mirror of
https://github.com/correl/mage.git
synced 2024-11-21 19:18:40 +00:00
Merge pull request #4953 from GrayedFox/issue-4952-fix-touranment-lobby-prefs
Issue 4952 fix touranment lobby prefs (WIP)
This commit is contained in:
commit
f89c3cc65b
5 changed files with 44 additions and 29 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -142,3 +142,7 @@ client_secrets.json
|
|||
dependency-reduced-pom.xml
|
||||
mage-bundle
|
||||
/Mage.Client/game-*.json
|
||||
|
||||
# build-tools config and log files when building client/server with Atom
|
||||
.build-tools.cson
|
||||
build-output.log
|
||||
|
|
|
@ -111,7 +111,7 @@
|
|||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JTable" name="tableSeats">
|
||||
<Component class="javax.swing.JTable" name="jTableSeats">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="tableWaitModel" type="code"/>
|
||||
|
|
|
@ -43,13 +43,13 @@ import java.util.concurrent.TimeUnit;
|
|||
import javax.swing.Icon;
|
||||
import javax.swing.SwingWorker;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.SessionHandler;
|
||||
import mage.client.chat.ChatPanelBasic;
|
||||
import mage.client.components.MageComponents;
|
||||
import mage.client.components.tray.MageTray;
|
||||
import static mage.client.dialog.PreferencesDialog.KEY_TABLE_WAITING_COLUMNS_ORDER;
|
||||
import static mage.client.dialog.PreferencesDialog.KEY_TABLE_WAITING_COLUMNS_WIDTH;
|
||||
import mage.client.util.GUISizeHelper;
|
||||
import mage.client.util.audio.AudioManager;
|
||||
import mage.client.util.gui.TableUtil;
|
||||
|
@ -58,7 +58,9 @@ import mage.players.PlayerType;
|
|||
import mage.remote.Session;
|
||||
import mage.view.SeatView;
|
||||
import mage.view.TableView;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import static mage.client.dialog.PreferencesDialog.KEY_TABLE_WAITING_COLUMNS_ORDER;
|
||||
import static mage.client.dialog.PreferencesDialog.KEY_TABLE_WAITING_COLUMNS_WIDTH;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
@ -66,7 +68,7 @@ import org.apache.log4j.Logger;
|
|||
public class TableWaitingDialog extends MageDialog {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(TableWaitingDialog.class);
|
||||
private static final int[] DEFAULT_COLUMS_WIDTH = {20, 50, 100, 100, 100};
|
||||
private static final int[] DEFAULT_COLUMNS_WIDTH = {20, 50, 100, 100, 100};
|
||||
|
||||
private UUID tableId;
|
||||
private UUID roomId;
|
||||
|
@ -89,12 +91,13 @@ public class TableWaitingDialog extends MageDialog {
|
|||
this.setSize(prefWidth, prefHeight);
|
||||
}
|
||||
|
||||
chatPanel.useExtendedView(ChatPanelBasic.VIEW_MODE.NONE);
|
||||
tableSeats.createDefaultColumnsFromModel();
|
||||
TableUtil.setColumnWidthAndOrder(tableSeats, DEFAULT_COLUMS_WIDTH, KEY_TABLE_WAITING_COLUMNS_WIDTH, KEY_TABLE_WAITING_COLUMNS_ORDER);
|
||||
tableSeats.setDefaultRenderer(Icon.class, new CountryCellRenderer());
|
||||
setGUISize();
|
||||
|
||||
chatPanel.useExtendedView(ChatPanelBasic.VIEW_MODE.NONE);
|
||||
jTableSeats.createDefaultColumnsFromModel();
|
||||
TableUtil.setColumnWidthAndOrder(jTableSeats, DEFAULT_COLUMNS_WIDTH, KEY_TABLE_WAITING_COLUMNS_WIDTH, KEY_TABLE_WAITING_COLUMNS_ORDER);
|
||||
jTableSeats.setDefaultRenderer(Icon.class, new CountryCellRenderer());
|
||||
|
||||
MageFrame.getUI().addButton(MageComponents.TABLE_WAITING_START_BUTTON, btnStart);
|
||||
}
|
||||
|
||||
|
@ -104,9 +107,9 @@ public class TableWaitingDialog extends MageDialog {
|
|||
}
|
||||
|
||||
private void setGUISize() {
|
||||
tableSeats.getTableHeader().setFont(GUISizeHelper.tableFont);
|
||||
tableSeats.setFont(GUISizeHelper.tableFont);
|
||||
tableSeats.setRowHeight(GUISizeHelper.getTableRowHeight());
|
||||
jTableSeats.getTableHeader().setFont(GUISizeHelper.tableFont);
|
||||
jTableSeats.setFont(GUISizeHelper.tableFont);
|
||||
jTableSeats.setRowHeight(GUISizeHelper.getTableRowHeight());
|
||||
|
||||
jSplitPane1.setDividerSize(GUISizeHelper.dividerBarSize);
|
||||
jScrollPane1.getVerticalScrollBar().setPreferredSize(new Dimension(GUISizeHelper.scrollBarSize, 0));
|
||||
|
@ -131,14 +134,14 @@ public class TableWaitingDialog extends MageDialog {
|
|||
closeDialog();
|
||||
return;
|
||||
}
|
||||
int row = this.tableSeats.getSelectedRow();
|
||||
int row = this.jTableSeats.getSelectedRow();
|
||||
if (getTitle().equals("Waiting for players")) {
|
||||
this.title = getTitle() + " - " + table.getDeckType() + " / " + table.getGameType();
|
||||
this.repaint();
|
||||
}
|
||||
tableWaitModel.loadData(table);
|
||||
this.tableSeats.repaint();
|
||||
this.tableSeats.getSelectionModel().setSelectionInterval(row, row);
|
||||
this.jTableSeats.repaint();
|
||||
this.jTableSeats.getSelectionModel().setSelectionInterval(row, row);
|
||||
} else {
|
||||
closeDialog();
|
||||
}
|
||||
|
@ -177,12 +180,11 @@ public class TableWaitingDialog extends MageDialog {
|
|||
if (updateTask != null) {
|
||||
updateTask.cancel(true);
|
||||
}
|
||||
|
||||
this.chatPanel.disconnect();
|
||||
MageFrame.getUI().removeButton(MageComponents.TABLE_WAITING_START_BUTTON);
|
||||
this.removeDialog();
|
||||
TableUtil.saveColumnWidthAndOrderToPrefs(tableSeats, KEY_TABLE_WAITING_COLUMNS_WIDTH, KEY_TABLE_WAITING_COLUMNS_ORDER);
|
||||
PreferencesDialog.saveValue(PreferencesDialog.KEY_TABLE_WAITING_WIDTH, Integer.toString(getWidth()));
|
||||
PreferencesDialog.saveValue(PreferencesDialog.KEY_TABLE_WAITING_HEIGHT, Integer.toString(getHeight()));
|
||||
TableUtil.saveColumnWidthAndOrderToPrefs(jTableSeats, KEY_TABLE_WAITING_COLUMNS_WIDTH, KEY_TABLE_WAITING_COLUMNS_ORDER);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -200,7 +202,7 @@ public class TableWaitingDialog extends MageDialog {
|
|||
btnStart = new javax.swing.JButton();
|
||||
jSplitPane1 = new javax.swing.JSplitPane();
|
||||
jScrollPane1 = new javax.swing.JScrollPane();
|
||||
tableSeats = new javax.swing.JTable();
|
||||
jTableSeats = new javax.swing.JTable();
|
||||
chatPanel = new mage.client.chat.ChatPanelBasic();
|
||||
|
||||
setResizable(true);
|
||||
|
@ -226,9 +228,9 @@ public class TableWaitingDialog extends MageDialog {
|
|||
jSplitPane1.setResizeWeight(1.0);
|
||||
jSplitPane1.setToolTipText("");
|
||||
|
||||
tableSeats.setModel(tableWaitModel);
|
||||
tableSeats.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
|
||||
jScrollPane1.setViewportView(tableSeats);
|
||||
jTableSeats.setModel(tableWaitModel);
|
||||
jTableSeats.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
|
||||
jScrollPane1.setViewportView(jTableSeats);
|
||||
|
||||
jSplitPane1.setLeftComponent(jScrollPane1);
|
||||
jSplitPane1.setRightComponent(chatPanel);
|
||||
|
@ -288,19 +290,19 @@ public class TableWaitingDialog extends MageDialog {
|
|||
}//GEN-LAST:event_btnCancelActionPerformed
|
||||
|
||||
private void btnMoveDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMoveDownActionPerformed
|
||||
int row = this.tableSeats.getSelectedRow();
|
||||
if (row < this.tableSeats.getRowCount() - 1) {
|
||||
int row = this.jTableSeats.getSelectedRow();
|
||||
if (row < this.jTableSeats.getRowCount() - 1) {
|
||||
SessionHandler.swapSeats(roomId, tableId, row, row + 1);
|
||||
this.tableSeats.getSelectionModel().setSelectionInterval(row + 1, row + 1);
|
||||
this.jTableSeats.getSelectionModel().setSelectionInterval(row + 1, row + 1);
|
||||
}
|
||||
|
||||
}//GEN-LAST:event_btnMoveDownActionPerformed
|
||||
|
||||
private void btnMoveUpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMoveUpActionPerformed
|
||||
int row = this.tableSeats.getSelectedRow();
|
||||
int row = this.jTableSeats.getSelectedRow();
|
||||
if (row > 0) {
|
||||
SessionHandler.swapSeats(roomId, tableId, row, row - 1);
|
||||
this.tableSeats.getSelectionModel().setSelectionInterval(row - 1, row - 1);
|
||||
this.jTableSeats.getSelectionModel().setSelectionInterval(row - 1, row - 1);
|
||||
}
|
||||
}//GEN-LAST:event_btnMoveUpActionPerformed
|
||||
|
||||
|
@ -312,7 +314,7 @@ public class TableWaitingDialog extends MageDialog {
|
|||
private mage.client.chat.ChatPanelBasic chatPanel;
|
||||
private javax.swing.JScrollPane jScrollPane1;
|
||||
private javax.swing.JSplitPane jSplitPane1;
|
||||
private javax.swing.JTable tableSeats;
|
||||
private javax.swing.JTable jTableSeats;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
}
|
||||
|
|
|
@ -192,7 +192,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
activeTablesSorter.setSortKeys(list);
|
||||
|
||||
TableUtil.setColumnWidthAndOrder(tableTables, DEFAULT_COLUMNS_WIDTH,
|
||||
PreferencesDialog.KEY_TABLES_COLUMNS_WIDTH, PreferencesDialog.KEY_TABLES_COLUMNS_ORDER); // TODO: is sort order save and restore after app restart/window open?
|
||||
PreferencesDialog.KEY_TABLES_COLUMNS_WIDTH, PreferencesDialog.KEY_TABLES_COLUMNS_ORDER);
|
||||
|
||||
// 2. TABLE COMPLETED
|
||||
completedTablesSorter = new MageTableRowSorter(matchesModel);
|
||||
|
|
|
@ -5,8 +5,10 @@
|
|||
*/
|
||||
package mage.client.util.gui;
|
||||
|
||||
import java.util.Arrays;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.TableColumn;
|
||||
import org.apache.log4j.Logger;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
|
||||
/**
|
||||
|
@ -22,11 +24,15 @@ public final class TableUtil {
|
|||
* @param widthPrefKey
|
||||
* @param orderPrefKey
|
||||
*/
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(TableUtil.class);
|
||||
|
||||
static public void setColumnWidthAndOrder(JTable table, int[] defaultColumnsWidth, String widthPrefKey, String orderPrefKey) {
|
||||
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
||||
|
||||
// set the column width from saved value or defaults
|
||||
int[] widths = getIntArrayFromString(PreferencesDialog.getCachedValue(widthPrefKey, null));
|
||||
LOGGER.info("loading stored widths: " + Arrays.toString(widths));
|
||||
int i = 0;
|
||||
for (int width : defaultColumnsWidth) {
|
||||
if (widths != null && widths.length > i) {
|
||||
|
@ -43,6 +49,7 @@ public final class TableUtil {
|
|||
|
||||
// set the column order
|
||||
int[] order = getIntArrayFromString(PreferencesDialog.getCachedValue(orderPrefKey, null));
|
||||
LOGGER.info("loading column order: " + Arrays.toString(order));
|
||||
if (order != null && order.length == table.getColumnCount()) {
|
||||
for (int j = 0; j < table.getColumnCount(); j++) {
|
||||
table.moveColumn(table.convertColumnIndexToView(order[j]), j);
|
||||
|
@ -70,6 +77,8 @@ public final class TableUtil {
|
|||
PreferencesDialog.saveValue(widthPrefKey, columnWidthSettings.toString());
|
||||
PreferencesDialog.saveValue(orderPrefKey, columnOrderSettings.toString());
|
||||
|
||||
LOGGER.info("saving column widths: " + columnWidthSettings.toString());
|
||||
LOGGER.info("saving column order: " + columnOrderSettings.toString());
|
||||
}
|
||||
|
||||
public static int[] getIntArrayFromString(String stringData) {
|
||||
|
|
Loading…
Reference in a new issue