Split pane divider positions of table panel and tournament panel are saved and restored now.

This commit is contained in:
LevelX2 2013-07-19 14:04:59 +02:00
parent f5f7b0d3ea
commit 41034ccdd8
8 changed files with 297 additions and 187 deletions

View file

@ -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

View file

@ -1,4 +1,4 @@
<?xml version="1.1" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
@ -16,8 +16,8 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="txtMessage" alignment="0" pref="183" max="32767" attributes="0"/>
<Component id="jSplitPane1" alignment="0" pref="183" max="32767" attributes="0"/>
<Component id="txtMessage" alignment="0" pref="203" max="32767" attributes="0"/>
<Component id="jSplitPane1" alignment="0" pref="0" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
@ -25,64 +25,61 @@
<Group type="102" alignment="1" attributes="0">
<Component id="jSplitPane1" pref="288" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="txtMessage" min="-2" pref="25" max="-2" attributes="0"/>
<Component id="txtMessage" min="-2" pref="30" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JTextField" name="txtMessage">
<Events>
<EventHandler event="keyTyped" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="txtMessageKeyTyped"/>
</Events>
</Component>
<Container class="javax.swing.JSplitPane" name="jSplitPane1">
<Properties>
<Property name="orientation" type="int" value="0"/>
<Property name="resizeWeight" type="double" value="0.8"/>
<Property name="resizeWeight" type="double" value="0.25"/>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Container class="javax.swing.JScrollPane" name="jScrollPaneTxt">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
<JSplitPaneConstraints position="left"/>
<JSplitPaneConstraints position="right"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTextArea" name="txtConversation">
<Component class="mage.client.components.ColorPane" name="txtConversation">
<Properties>
<Property name="columns" type="int" value="20"/>
<Property name="editable" type="boolean" value="false"/>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Arial" size="10" style="0"/>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
<EmptyBorder/>
</Border>
</Property>
<Property name="lineWrap" type="boolean" value="true"/>
<Property name="rows" type="int" value="5"/>
<Property name="wrapStyleWord" type="boolean" value="true"/>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Arial" size="14" style="0"/>
</Property>
<Property name="focusCycleRoot" type="boolean" value="false"/>
<Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
<Insets value="[2, 2, 2, 2]"/>
</Property>
<Property name="opaque" type="boolean" value="false"/>
</Properties>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JScrollPane" name="jScrollPane2">
<Container class="javax.swing.JScrollPane" name="jScrollPanePlayers">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
<JSplitPaneConstraints position="bottom"/>
<JSplitPaneConstraints position="top"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTable" name="jTable1">
<Component class="javax.swing.JTable" name="jTablePlayers">
<Properties>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="this.tableModel" type="code"/>
@ -100,5 +97,10 @@
</Container>
</SubComponents>
</Container>
<Component class="javax.swing.JTextField" name="txtMessage">
<Events>
<EventHandler event="keyTyped" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="txtMessageKeyTyped"/>
</Events>
</Component>
</SubComponents>
</Form>

View file

@ -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<String> players = new ArrayList<String>();
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 {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//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))
);
}// </editor-fold>//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

View file

@ -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);
}
}
}

View file

@ -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())) {

View file

@ -17,7 +17,7 @@
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jPanel1" alignment="1" max="32767" attributes="0"/>
<Component id="jSplitPane1" alignment="0" pref="848" max="32767" attributes="0"/>
<Component id="jSplitPane1" alignment="0" pref="908" max="32767" attributes="0"/>
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
<Component id="jPanel2" alignment="1" pref="908" max="32767" attributes="0"/>
</Group>
@ -28,7 +28,7 @@
<Group type="102" alignment="0" attributes="0">
<Component id="jPanel1" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
<Component id="jSplitPane1" max="32767" attributes="0"/>
<Component id="jSplitPane1" pref="505" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
<Component id="jPanel2" min="-2" pref="25" max="-2" attributes="0"/>
</Group>
@ -128,7 +128,7 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel2" pref="701" max="32767" attributes="0"/>
<Component id="jLabel2" pref="705" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
@ -218,7 +218,7 @@
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jSplitPane2" alignment="0" pref="499" max="32767" attributes="0"/>
<Component id="jSplitPane2" alignment="0" pref="503" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>

View file

@ -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<String, JComponent> getUIComponents() {
Map<String, JComponent> components = new HashMap<String, JComponent>();
@ -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<Void, Collection<String>> {
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];

View file

@ -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;