diff --git a/Mage.Client/src/main/java/mage/client/MagePane.java b/Mage.Client/src/main/java/mage/client/MagePane.java index 8692beeb4c2..4da2411380d 100644 --- a/Mage.Client/src/main/java/mage/client/MagePane.java +++ b/Mage.Client/src/main/java/mage/client/MagePane.java @@ -52,8 +52,9 @@ public abstract class MagePane extends javax.swing.JInternalFrame { } private void hideTitle() { - if (ui instanceof BasicInternalFrameUI) + if (ui instanceof BasicInternalFrameUI) { ((BasicInternalFrameUI) ui).setNorthPane(null); + } } @Override diff --git a/Mage.Client/src/main/java/mage/client/chat/ChatPanel.form b/Mage.Client/src/main/java/mage/client/chat/ChatPanel.form index a10f24dbdfa..b45d41aa474 100644 --- a/Mage.Client/src/main/java/mage/client/chat/ChatPanel.form +++ b/Mage.Client/src/main/java/mage/client/chat/ChatPanel.form @@ -1,4 +1,4 @@ - +
@@ -16,8 +16,8 @@ - - + + @@ -25,64 +25,61 @@ - + - - - - - - + - - - - + - + - + - - - - + + + + - - - + + + + + + + + - + - + - + @@ -100,5 +97,10 @@ + + + + + diff --git a/Mage.Client/src/main/java/mage/client/chat/ChatPanel.java b/Mage.Client/src/main/java/mage/client/chat/ChatPanel.java index 08cd8f82fb8..3119849b9fa 100644 --- a/Mage.Client/src/main/java/mage/client/chat/ChatPanel.java +++ b/Mage.Client/src/main/java/mage/client/chat/ChatPanel.java @@ -34,19 +34,21 @@ package mage.client.chat; +import java.awt.Color; +import java.awt.event.KeyEvent; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.EnumMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import javax.swing.JTextField; +import javax.swing.table.AbstractTableModel; import mage.client.MageFrame; -import mage.client.components.ColorPane; import mage.remote.Session; import mage.view.ChatMessage.MessageColor; -import javax.swing.*; -import javax.swing.border.EmptyBorder; -import javax.swing.table.AbstractTableModel; -import java.awt.*; -import java.awt.event.KeyEvent; -import java.util.*; -import java.util.List; - /** * * @author BetaSteward_at_googlemail.com, nantuko @@ -57,7 +59,7 @@ public class ChatPanel extends javax.swing.JPanel { private Session session; private List players = new ArrayList(); - private TableModel tableModel; + private final TableModel tableModel; /** * Chat message color for opponents. @@ -125,16 +127,16 @@ public class ChatPanel extends javax.swing.JPanel { public ChatPanel(boolean addPlayersTab) { tableModel = new TableModel(); initComponents(); - jTable1.setBackground(new Color(0, 0, 0, 0)); - jTable1.setForeground(Color.white); + jTablePlayers.setBackground(new Color(0, 0, 0, 0)); + jTablePlayers.setForeground(Color.white); setBackground(new Color(0, 0, 0, 100)); - if (jScrollPane1 != null) { - jScrollPane1.setBackground(new Color(0, 0, 0, 100)); - jScrollPane1.getViewport().setBackground(new Color(0, 0, 0, 100)); + if (jScrollPaneTxt != null) { + jScrollPaneTxt.setBackground(new Color(0, 0, 0, 100)); + jScrollPaneTxt.getViewport().setBackground(new Color(0, 0, 0, 100)); } - if (jScrollPane2 != null) { - jScrollPane2.setBackground(new Color(0, 0, 0, 100)); - jScrollPane2.getViewport().setBackground(new Color(0, 0, 0, 100)); + if (jScrollPanePlayers != null) { + jScrollPanePlayers.setBackground(new Color(0, 0, 0, 100)); + jScrollPanePlayers.getViewport().setBackground(new Color(0, 0, 0, 100)); } if (!addPlayersTab) { simplifyComponents(); @@ -223,8 +225,21 @@ public class ChatPanel extends javax.swing.JPanel { this.txtConversation.setExtBackgroundColor(new Color(0,0,0,100)); this.txtConversation.setBackground(new Color(0,0,0,0)); this.txtConversation.setForeground(new Color(255,255,255)); - this.jScrollPane1.setOpaque(false); - this.jScrollPane1.getViewport().setOpaque(false); + this.jScrollPaneTxt.setOpaque(false); + this.jScrollPaneTxt.getViewport().setOpaque(false); + } + + public void setSplitDividerLocation(int location) { + if (jSplitPane1 != null) { + jSplitPane1.setDividerLocation(location); + } + } + + public int getSplitDividerLocation() { + if (jSplitPane1 == null) { + return 0; + } + return this.jSplitPane1.getDividerLocation(); } class TableModel extends AbstractTableModel { @@ -287,12 +302,31 @@ class TableModel extends AbstractTableModel { // //GEN-BEGIN:initComponents private void initComponents() { - txtMessage = new javax.swing.JTextField(); jSplitPane1 = new javax.swing.JSplitPane(); - jScrollPane1 = new javax.swing.JScrollPane(); - txtConversation = new ColorPane(); - jScrollPane2 = new javax.swing.JScrollPane(); - jTable1 = new javax.swing.JTable(); + jScrollPaneTxt = new javax.swing.JScrollPane(); + txtConversation = new mage.client.components.ColorPane(); + jScrollPanePlayers = new javax.swing.JScrollPane(); + jTablePlayers = new javax.swing.JTable(); + txtMessage = new javax.swing.JTextField(); + + jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); + jSplitPane1.setResizeWeight(0.25); + + txtConversation.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); + txtConversation.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N + txtConversation.setFocusCycleRoot(false); + txtConversation.setMargin(new java.awt.Insets(2, 2, 2, 2)); + txtConversation.setOpaque(false); + jScrollPaneTxt.setViewportView(txtConversation); + + jSplitPane1.setRightComponent(jScrollPaneTxt); + + jTablePlayers.setModel(this.tableModel); + jTablePlayers.setToolTipText("Connected players"); + jTablePlayers.setGridColor(new java.awt.Color(255, 255, 255)); + jScrollPanePlayers.setViewportView(jTablePlayers); + + jSplitPane1.setTopComponent(jScrollPanePlayers); txtMessage.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { @@ -300,42 +334,19 @@ class TableModel extends AbstractTableModel { } }); - jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); - jSplitPane1.setResizeWeight(0.25); - -// txtConversation.setColumns(20); - txtConversation.setOpaque(false); -// txtConversation.setEditable(false); - txtConversation.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N -// txtConversation.setLineWrap(true); -// txtConversation.setRows(5); -// txtConversation.setWrapStyleWord(true); - jScrollPane1.setViewportView(txtConversation); - jScrollPane1.setBorder(new EmptyBorder(0,0,0,0)); - - jSplitPane1.setLeftComponent(jScrollPane2); - - jTable1.setModel(this.tableModel); - jTable1.setToolTipText("Connected players"); - jTable1.setGridColor(new java.awt.Color(255, 255, 255)); - jScrollPane2.setViewportView(jTable1); - - jSplitPane1.setBottomComponent(jScrollPane1); - jSplitPane1.setDividerLocation(150 + jSplitPane1.getInsets().bottom); - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(txtMessage, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE) - .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE) + .addComponent(txtMessage, javax.swing.GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE) + .addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 288, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(txtMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(txtMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)) ); }// //GEN-END:initComponents @@ -345,18 +356,17 @@ class TableModel extends AbstractTableModel { layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(txtMessage, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE) - .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE) + .addComponent(jScrollPaneTxt, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 294, Short.MAX_VALUE) + .addComponent(jScrollPaneTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 294, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)) ); - - jTable1 = null; - jScrollPane2 = null; + jTablePlayers = null; + jScrollPanePlayers = null; } private void txtMessageKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtMessageKeyTyped @@ -401,11 +411,11 @@ class TableModel extends AbstractTableModel { } // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JScrollPane jScrollPanePlayers; + private javax.swing.JScrollPane jScrollPaneTxt; private javax.swing.JSplitPane jSplitPane1; - private javax.swing.JTable jTable1; - private ColorPane txtConversation; + private javax.swing.JTable jTablePlayers; + private mage.client.components.ColorPane txtConversation; private javax.swing.JTextField txtMessage; // End of variables declaration//GEN-END:variables diff --git a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java index a1d865f0352..8b03f62fe8b 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java @@ -95,11 +95,22 @@ public class PreferencesDialog extends javax.swing.JDialog { public static final String KEY_BIG_CARD_TOGGLED = "bigCardToggled"; - public static final String KEY_GAMEPANEL_LAST_SIZE = "gamepanelLastSize"; + + // Size of frame to check if divider locations should be used + public static final String KEY_MAGE_PANEL_LAST_SIZE = "gamepanelLastSize"; + + // positions of divider bars + public static final String KEY_TABLES_DIVIDER_LOCATION_1 = "tablePanelDividerLocation1"; + public static final String KEY_TABLES_DIVIDER_LOCATION_2 = "tablePanelDividerLocation2"; + public static final String KEY_TABLES_DIVIDER_LOCATION_3 = "tablePanelDividerLocation3"; + public static final String KEY_GAMEPANEL_DIVIDER_LOCATION_0 = "gamepanelDividerLocation0"; public static final String KEY_GAMEPANEL_DIVIDER_LOCATION_1 = "gamepanelDividerLocation1"; public static final String KEY_GAMEPANEL_DIVIDER_LOCATION_2 = "gamepanelDividerLocation2"; + public static final String KEY_TOURNAMENT_DIVIDER_LOCATION_1 = "tournamentPanelDividerLocation1"; + public static final String KEY_TOURNAMENT_DIVIDER_LOCATION_2 = "tournamentPanelDividerLocation2"; + // default setting for new table dialog public static final String KEY_NEW_TABLE_NAME = "newTableName"; public static final String KEY_NEW_TABLE_DECK_TYPE = "newTableDeckType"; @@ -1615,16 +1626,17 @@ public class PreferencesDialog extends javax.swing.JDialog { } prop = prefs.get(KEY_BATTLEFIELD_IMAGE_RANDOM, "true"); - if(dialog.cbUseRandomBattleImage.isEnabled()) - if(prop.equals("true")){ - dialog.cbUseRandomBattleImage.setSelected(true); - dialog.useRandomBattleField(); - }else{ - dialog.cbUseRandomBattleImage.setSelected(false); - dialog.useSelectedBattleField(); - String path = prefs.get(KEY_BATTLEFIELD_IMAGE, ""); - dialog.txtBattlefieldImagePath.setText(path); - updateCache(KEY_BATTLEFIELD_IMAGE, path); + if(dialog.cbUseRandomBattleImage.isEnabled()) { + if(prop.equals("true")){ + dialog.cbUseRandomBattleImage.setSelected(true); + dialog.useRandomBattleField(); + }else{ + dialog.cbUseRandomBattleImage.setSelected(false); + dialog.useSelectedBattleField(); + String path = prefs.get(KEY_BATTLEFIELD_IMAGE, ""); + dialog.txtBattlefieldImagePath.setText(path); + updateCache(KEY_BATTLEFIELD_IMAGE, path); + } } } diff --git a/Mage.Client/src/main/java/mage/client/game/GamePanel.java b/Mage.Client/src/main/java/mage/client/game/GamePanel.java index 854de36c8ff..3d3b3b49194 100644 --- a/Mage.Client/src/main/java/mage/client/game/GamePanel.java +++ b/Mage.Client/src/main/java/mage/client/game/GamePanel.java @@ -180,16 +180,16 @@ public final class GamePanel extends javax.swing.JPanel { // save panel sizes and divider locations. Rectangle rec = MageFrame.getDesktop().getBounds(); StringBuilder sb = new StringBuilder(Double.toString(rec.getWidth())).append("x").append(Double.toString(rec.getHeight())); - PreferencesDialog.saveValue(PreferencesDialog.KEY_GAMEPANEL_LAST_SIZE, sb.toString()); + PreferencesDialog.saveValue(PreferencesDialog.KEY_MAGE_PANEL_LAST_SIZE, sb.toString()); PreferencesDialog.saveValue(PreferencesDialog.KEY_GAMEPANEL_DIVIDER_LOCATION_0, Integer.toString(this.jSplitPane0.getDividerLocation())); PreferencesDialog.saveValue(PreferencesDialog.KEY_GAMEPANEL_DIVIDER_LOCATION_1, Integer.toString(this.jSplitPane1.getDividerLocation())); PreferencesDialog.saveValue(PreferencesDialog.KEY_GAMEPANEL_DIVIDER_LOCATION_2, Integer.toString(this.jSplitPane2.getDividerLocation())); } - public void restoreDividerLocations() { + private void restoreDividerLocations() { Rectangle rec = MageFrame.getDesktop().getBounds(); if (rec != null) { - String size = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAMEPANEL_LAST_SIZE, null); + String size = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_MAGE_PANEL_LAST_SIZE, null); StringBuilder sb = new StringBuilder(Double.toString(rec.getWidth())).append("x").append(Double.toString(rec.getHeight())); // use divider positions only if screen size is the same as it was the time the settings were saved if (size != null && size.equals(sb.toString())) { diff --git a/Mage.Client/src/main/java/mage/client/table/TablesPanel.form b/Mage.Client/src/main/java/mage/client/table/TablesPanel.form index 3a514255d88..15a2afcdc59 100644 --- a/Mage.Client/src/main/java/mage/client/table/TablesPanel.form +++ b/Mage.Client/src/main/java/mage/client/table/TablesPanel.form @@ -17,7 +17,7 @@ - + @@ -28,7 +28,7 @@ - + @@ -128,7 +128,7 @@ - + @@ -218,7 +218,7 @@ - + diff --git a/Mage.Client/src/main/java/mage/client/table/TablesPanel.java b/Mage.Client/src/main/java/mage/client/table/TablesPanel.java index c15ef06255a..dd832e554cf 100644 --- a/Mage.Client/src/main/java/mage/client/table/TablesPanel.java +++ b/Mage.Client/src/main/java/mage/client/table/TablesPanel.java @@ -34,20 +34,32 @@ package mage.client.table; -import java.awt.*; +import java.awt.Color; +import java.awt.Component; +import java.awt.Point; +import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.beans.PropertyVetoException; import java.io.File; import java.text.DateFormat; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.UUID; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; -import javax.swing.*; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.JComponent; +import javax.swing.JDesktopPane; +import javax.swing.JInternalFrame; +import javax.swing.JLayeredPane; +import javax.swing.JOptionPane; +import javax.swing.JPopupMenu; +import javax.swing.SwingWorker; import javax.swing.table.AbstractTableModel; -import mage.constants.MultiplayerAttackOption; -import mage.constants.RangeOfInfluence; import mage.cards.decks.importer.DeckImporterUtil; import mage.client.MageFrame; import mage.client.chat.ChatPanel; @@ -55,11 +67,13 @@ import mage.client.components.MageComponents; import mage.client.dialog.JoinTableDialog; import mage.client.dialog.NewTableDialog; import mage.client.dialog.NewTournamentDialog; +import mage.client.dialog.PreferencesDialog; import mage.client.dialog.TableWaitingDialog; import mage.client.util.ButtonColumn; import mage.client.util.gui.GuiDisplayUtil; import mage.constants.MatchTimeLimit; -import static mage.constants.TableState.DUELING; +import mage.constants.MultiplayerAttackOption; +import mage.constants.RangeOfInfluence; import mage.game.match.MatchOptions; import mage.remote.MageRemoteException; import mage.remote.Session; @@ -67,8 +81,6 @@ import mage.view.MatchView; import mage.view.TableView; import org.apache.log4j.Logger; - - /** * * @author BetaSteward_at_googlemail.com @@ -117,69 +129,69 @@ public class TablesPanel extends javax.swing.JPanel { Action joinTable; joinTable = new AbstractAction() - { - @Override - public void actionPerformed(ActionEvent e) - { - int modelRow = Integer.valueOf( e.getActionCommand() ); - UUID tableId = (UUID)tableModel.getValueAt(modelRow, TableTableModel.ACTION_COLUMN + 3); - UUID gameId = (UUID)tableModel.getValueAt(modelRow, TableTableModel.ACTION_COLUMN + 2); - String action = (String)tableModel.getValueAt(modelRow, TableTableModel.ACTION_COLUMN); - boolean isTournament = (Boolean)tableModel.getValueAt(modelRow, TableTableModel.ACTION_COLUMN + 1); - String owner = (String)tableModel.getValueAt(modelRow, 1); + { + @Override + public void actionPerformed(ActionEvent e) + { + int modelRow = Integer.valueOf( e.getActionCommand() ); + UUID tableId = (UUID)tableModel.getValueAt(modelRow, TableTableModel.ACTION_COLUMN + 3); + UUID gameId = (UUID)tableModel.getValueAt(modelRow, TableTableModel.ACTION_COLUMN + 2); + String action = (String)tableModel.getValueAt(modelRow, TableTableModel.ACTION_COLUMN); + boolean isTournament = (Boolean)tableModel.getValueAt(modelRow, TableTableModel.ACTION_COLUMN + 1); + String owner = (String)tableModel.getValueAt(modelRow, 1); + + if (action.equals("Join")) { + if (owner.equals(session.getUserName())) { + try { + JDesktopPane desktopPane = (JDesktopPane)MageFrame.getUI().getComponent(MageComponents.DESKTOP_PANE); + JInternalFrame[] windows = desktopPane.getAllFramesInLayer(javax.swing.JLayeredPane.DEFAULT_LAYER); + for (JInternalFrame frame : windows) { + if (frame.getTitle().equals("Waiting for players")) { + frame.toFront(); + frame.setVisible(true); + try { + frame.setSelected(true); + } catch (PropertyVetoException ve) { + ve.printStackTrace(); + logger.error(ve); + } + } - if (action.equals("Join")) { - if (owner.equals(session.getUserName())) { - try { - JDesktopPane desktopPane = (JDesktopPane)MageFrame.getUI().getComponent(MageComponents.DESKTOP_PANE); - JInternalFrame[] windows = desktopPane.getAllFramesInLayer(javax.swing.JLayeredPane.DEFAULT_LAYER); - for (JInternalFrame frame : windows) { - if (frame.getTitle().equals("Waiting for players")) { - frame.toFront(); - frame.setVisible(true); - try { - frame.setSelected(true); - } catch (PropertyVetoException ve) { - ve.printStackTrace(); - logger.error(ve); } + } catch (Exception ex) { + logger.error(ex); } - + return; } - } catch (Exception ex) { - logger.error(ex); + if (isTournament) { + logger.info("Joining tournament " + tableId); + session.joinTournamentTable(roomId, tableId, session.getUserName(), "Human", 1); + } + else { + logger.info("Joining table " + tableId); + joinTableDialog.showDialog(roomId, tableId); + } + } else if (action.equals("Remove")) { + if (JOptionPane.showConfirmDialog(null, "Are you sure you want to remove table?", "Removing table", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { + session.removeTable(roomId, tableId); + } + } else if (action.equals("Show")) { + if (isTournament) { + logger.info("Showing tournament table " + tableId); + session.watchTable(roomId, tableId); + } + } else if (action.equals("Watch")) { + if (!isTournament) { + logger.info("Watching table " + tableId); + session.watchTable(roomId, tableId); + } + } else if (action.equals("Replay")) { + logger.info("Replaying game " + gameId); + // no replay because of memory leaks + // session.replayGame(gameId); } - return; } - if (isTournament) { - logger.info("Joining tournament " + tableId); - session.joinTournamentTable(roomId, tableId, session.getUserName(), "Human", 1); - } - else { - logger.info("Joining table " + tableId); - joinTableDialog.showDialog(roomId, tableId); - } - } else if (action.equals("Remove")) { - if (JOptionPane.showConfirmDialog(null, "Are you sure you want to remove table?", "Removing table", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { - session.removeTable(roomId, tableId); - } - } else if (action.equals("Show")) { - if (isTournament) { - logger.info("Showing tournament table " + tableId); - session.watchTable(roomId, tableId); - } - } else if (action.equals("Watch")) { - if (!isTournament) { - logger.info("Watching table " + tableId); - session.watchTable(roomId, tableId); - } - } else if (action.equals("Replay")) { - logger.info("Replaying game " + gameId); - // no replay because of memory leaks - // session.replayGame(gameId); - } - } - }; + }; Action replayMatch = new AbstractAction() { @@ -207,6 +219,39 @@ public class TablesPanel extends javax.swing.JPanel { new ButtonColumn(tableCompleted, replayMatch, MatchesTableModel.ACTION_COLUMN); } + + private void saveDividerLocations() { + // save panel sizes and divider locations. + Rectangle rec = MageFrame.getDesktop().getBounds(); + StringBuilder sb = new StringBuilder(Double.toString(rec.getWidth())).append("x").append(Double.toString(rec.getHeight())); + PreferencesDialog.saveValue(PreferencesDialog.KEY_MAGE_PANEL_LAST_SIZE, sb.toString()); + PreferencesDialog.saveValue(PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_1, Integer.toString(this.jSplitPane1.getDividerLocation())); + PreferencesDialog.saveValue(PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_2, Integer.toString(this.jSplitPane2.getDividerLocation())); + PreferencesDialog.saveValue(PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_3, Integer.toString(chatPanel.getSplitDividerLocation())); + } + + private void restoreDividerLocations() { + Rectangle rec = MageFrame.getDesktop().getBounds(); + if (rec != null) { + String size = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_MAGE_PANEL_LAST_SIZE, null); + StringBuilder sb = new StringBuilder(Double.toString(rec.getWidth())).append("x").append(Double.toString(rec.getHeight())); + // use divider positions only if screen size is the same as it was the time the settings were saved + if (size != null && size.equals(sb.toString())) { + String location = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_1, null); + if (location != null && jSplitPane1 != null) { + jSplitPane1.setDividerLocation(Integer.parseInt(location)); + } + location = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_2, null); + if (location != null && jSplitPane2 != null) { + jSplitPane2.setDividerLocation(Integer.parseInt(location)); + } + location = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_3, null); + if (location != null && chatPanel != null) { + chatPanel.setSplitDividerLocation(Integer.parseInt(location)); + } + } + } + } public Map getUIComponents() { Map components = new HashMap(); @@ -306,6 +351,7 @@ public class TablesPanel extends javax.swing.JPanel { reloadMessages(); MageFrame.getUI().addButton(MageComponents.NEW_GAME_BUTTON, btnNewTable); + this.restoreDividerLocations(); } protected void reloadMessages() { @@ -325,6 +371,7 @@ public class TablesPanel extends javax.swing.JPanel { } public void hideTables() { + this.saveDividerLocations(); for (Component component : MageFrame.getDesktop().getComponents()) { if (component instanceof TableWaitingDialog) { ((TableWaitingDialog)component).closeDialog(); @@ -615,7 +662,7 @@ private void chkShowCompletedActionPerformed(java.awt.event.ActionEvent evt) {// class TableTableModel extends AbstractTableModel { - public static int ACTION_COLUMN = 9; // column the action is located (starting with 0) + public static final int ACTION_COLUMN = 9; // column the action is located (starting with 0) private String[] columnNames = new String[]{"Match Name", "Owner / Players", "Game Type", "Wins", "Free Mulligans", "Deck Type", "Info", "Status", "Created", "Action"}; private TableView[] tables = new TableView[0]; @@ -822,7 +869,7 @@ class UpdatePlayersTask extends SwingWorker> { class MatchesTableModel extends AbstractTableModel { - public static int ACTION_COLUMN = 7; // column the action is located (starting with 0) + public static final int ACTION_COLUMN = 7; // column the action is located (starting with 0) private String[] columnNames = new String[]{"Match Name", "Game Type", "Deck Type", "Players", "Result", "Start Time", "End Time","Action"}; private MatchView[] matches = new MatchView[0]; diff --git a/Mage.Client/src/main/java/mage/client/tournament/TournamentPanel.java b/Mage.Client/src/main/java/mage/client/tournament/TournamentPanel.java index eb52213bb5a..d9a4c554a9e 100644 --- a/Mage.Client/src/main/java/mage/client/tournament/TournamentPanel.java +++ b/Mage.Client/src/main/java/mage/client/tournament/TournamentPanel.java @@ -46,6 +46,7 @@ import javax.swing.*; import javax.swing.table.AbstractTableModel; import mage.client.MageFrame; import mage.client.chat.ChatPanel; +import mage.client.dialog.PreferencesDialog; import mage.client.util.ButtonColumn; import mage.remote.Session; import mage.view.RoundView; @@ -76,6 +77,7 @@ public class TournamentPanel extends javax.swing.JPanel { matchesModel = new TournamentMatchesTableModel(); initComponents(); + this.restoreDividerLocations(); btnQuitTournament.setVisible(false); df = DateFormat.getDateTimeInstance(); @@ -91,10 +93,13 @@ public class TournamentPanel extends javax.swing.JPanel { public void actionPerformed(ActionEvent e) { int modelRow = Integer.valueOf( e.getActionCommand() ); - UUID gameId = UUID.fromString((String)tableMatches.getValueAt(modelRow, 3)); - String state = (String)tableMatches.getValueAt(modelRow, 4); - String actionText = (String)tableMatches.getValueAt(modelRow, 6); - UUID tableId = UUID.fromString((String)matchesModel.getValueAt(modelRow, 7)); + + String state = (String)tableMatches.getValueAt(modelRow, 2); + String actionText = (String)tableMatches.getValueAt(modelRow, TournamentMatchesTableModel.ACTION_COLUMN); + UUID tableId = UUID.fromString((String)matchesModel.getValueAt(modelRow, TournamentMatchesTableModel.ACTION_COLUMN +1)); + UUID gameId = UUID.fromString((String)matchesModel.getValueAt(modelRow, TournamentMatchesTableModel.ACTION_COLUMN +3)); + + // if (state.equals("Finished") && action.equals("Replay")) { // logger.info("Replaying game " + gameId); // session.replayGame(gameId); @@ -106,11 +111,39 @@ public class TournamentPanel extends javax.swing.JPanel { } }; - // replay button, don't delete this - ButtonColumn buttonColumn = new ButtonColumn(tableMatches, action, 6); + // action button, don't delete this + ButtonColumn buttonColumn = new ButtonColumn(tableMatches, action, TournamentMatchesTableModel.ACTION_COLUMN); } + private void saveDividerLocations() { + // save panel sizes and divider locations. + Rectangle rec = MageFrame.getDesktop().getBounds(); + StringBuilder sb = new StringBuilder(Double.toString(rec.getWidth())).append("x").append(Double.toString(rec.getHeight())); + PreferencesDialog.saveValue(PreferencesDialog.KEY_MAGE_PANEL_LAST_SIZE, sb.toString()); + PreferencesDialog.saveValue(PreferencesDialog.KEY_TOURNAMENT_DIVIDER_LOCATION_1, Integer.toString(this.jSplitPane1.getDividerLocation())); + PreferencesDialog.saveValue(PreferencesDialog.KEY_TOURNAMENT_DIVIDER_LOCATION_2, Integer.toString(this.jSplitPane2.getDividerLocation())); + } + + private void restoreDividerLocations() { + Rectangle rec = MageFrame.getDesktop().getBounds(); + if (rec != null) { + String size = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_MAGE_PANEL_LAST_SIZE, null); + StringBuilder sb = new StringBuilder(Double.toString(rec.getWidth())).append("x").append(Double.toString(rec.getHeight())); + // use divider positions only if screen size is the same as it was the time the settings were saved + if (size != null && size.equals(sb.toString())) { + String location = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TOURNAMENT_DIVIDER_LOCATION_1, null); + if (location != null && jSplitPane1 != null) { + jSplitPane1.setDividerLocation(Integer.parseInt(location)); + } + location = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TOURNAMENT_DIVIDER_LOCATION_2, null); + if (location != null && jSplitPane2 != null) { + jSplitPane2.setDividerLocation(Integer.parseInt(location)); + } + } + } + } + public synchronized void showTournament(UUID tournamentId) { this.tournamentId = tournamentId; session = MageFrame.getSession(); @@ -135,6 +168,7 @@ public class TournamentPanel extends javax.swing.JPanel { public void hideTournament() { stopTasks(); this.chatPanel1.disconnect(); + this.saveDividerLocations(); Component c = this.getParent(); while (c != null && !(c instanceof TournamentPane)) { c = c.getParent(); @@ -463,7 +497,10 @@ class TournamentPlayersTableModel extends AbstractTableModel { } class TournamentMatchesTableModel extends AbstractTableModel { - private String[] columnNames = new String[]{"Round Number", "Players", "Match Id", "Game Id", "State", "Result", "Action"}; + + public static final int ACTION_COLUMN = 4; // column the action is located + + private String[] columnNames = new String[]{"Round Number", "Players", "State", "Result", "Action"}; private TournamentGameView[] games = new TournamentGameView[0]; private boolean watchingAllowed; @@ -497,14 +534,10 @@ class TournamentMatchesTableModel extends AbstractTableModel { case 1: return games[arg0].getPlayers(); case 2: - return games[arg0].getMatchId().toString(); - case 3: - return games[arg0].getGameId().toString(); - case 4: return games[arg0].getState(); - case 5: + case 3: return games[arg0].getResult(); - case 6: + case 4: // if (games[arg0].getState().equals("Finished")) { // return "Replay"; // } @@ -512,8 +545,13 @@ class TournamentMatchesTableModel extends AbstractTableModel { return "Watch"; } return ""; - case 7: + case 5: return games[arg0].getTableId().toString(); + case 6: + return games[arg0].getMatchId().toString(); + case 7: + return games[arg0].getGameId().toString(); + } return ""; } @@ -536,7 +574,7 @@ class TournamentMatchesTableModel extends AbstractTableModel { @Override public boolean isCellEditable(int rowIndex, int columnIndex) { - if (columnIndex != 6) { + if (columnIndex != ACTION_COLUMN) { return false; } return true;