From 5822a7d94d0f845805ea9f50b2e5763a24d66abb Mon Sep 17 00:00:00 2001 From: GrayedFox Date: Tue, 22 May 2018 20:11:07 +0200 Subject: [PATCH 1/7] refactor divider setting and saving into utility functions refactor setting and saving filters into utility functions --- .../java/mage/client/table/TablesPanel.java | 87 +++++++------------ .../mage/client/util/gui/GuiDisplayUtil.java | 26 ++++++ .../java/mage/client/util/gui/TableUtil.java | 33 +++++-- 3 files changed, 84 insertions(+), 62 deletions(-) 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 36f1e52002..c8ee3e7f1f 100644 --- a/Mage.Client/src/main/java/mage/client/table/TablesPanel.java +++ b/Mage.Client/src/main/java/mage/client/table/TablesPanel.java @@ -56,6 +56,11 @@ import mage.client.components.MageComponents; import mage.client.dialog.*; import static mage.client.dialog.PreferencesDialog.KEY_TABLES_COLUMNS_ORDER; import static mage.client.dialog.PreferencesDialog.KEY_TABLES_COLUMNS_WIDTH; +import static mage.client.dialog.PreferencesDialog.KEY_TABLES_FILTER_SETTINGS; +import static mage.client.dialog.PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_1; +import static mage.client.dialog.PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_2; +import static mage.client.dialog.PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_3; +import static mage.client.dialog.PreferencesDialog.KEY_MAGE_PANEL_LAST_SIZE; import mage.client.util.ButtonColumn; import mage.client.util.GUISizeHelper; import mage.client.util.IgnoreList; @@ -227,8 +232,7 @@ public class TablesPanel extends javax.swing.JPanel { jScrollPaneTablesActive.getViewport().setBackground(new Color(255, 255, 255, 50)); jScrollPaneTablesFinished.getViewport().setBackground(new Color(255, 255, 255, 50)); - restoreSettings(); - + saveActiveFiltersToPrefs(); setGUISize(); Action openTableAction; @@ -343,7 +347,7 @@ public class TablesPanel extends javax.swing.JPanel { } public void cleanUp() { - saveSettings(); + saveGuiSettings(); chatPanelMain.cleanUp(); } @@ -406,66 +410,35 @@ public class TablesPanel extends javax.swing.JPanel { } private void saveDividerLocations() { - // save panel sizes and divider locations. + // save desktop bounds and divider locations Rectangle rec = MageFrame.getDesktop().getBounds(); - String sb = Double.toString(rec.getWidth()) + 'x' + Double.toString(rec.getHeight()); - PreferencesDialog.saveValue(PreferencesDialog.KEY_MAGE_PANEL_LAST_SIZE, sb); - PreferencesDialog.saveValue(PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_1, Integer.toString(this.jSplitPane1.getDividerLocation())); - PreferencesDialog.saveValue(PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_2, Integer.toString(this.jSplitPaneTables.getDividerLocation())); - PreferencesDialog.saveValue(PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_3, Integer.toString(chatPanelMain.getSplitDividerLocation())); + String currentBounds = Double.toString(rec.getWidth()) + 'x' + Double.toString(rec.getHeight()); + PreferencesDialog.saveValue(KEY_MAGE_PANEL_LAST_SIZE, currentBounds); + GuiDisplayUtil.setDividerLocation(KEY_TABLES_DIVIDER_LOCATION_1, this.jSplitPane1.getDividerLocation()); + GuiDisplayUtil.setDividerLocation(KEY_TABLES_DIVIDER_LOCATION_2, this.jSplitPaneTables.getDividerLocation()); + GuiDisplayUtil.setDividerLocation(KEY_TABLES_DIVIDER_LOCATION_3, chatPanelMain.getSplitDividerLocation()); } - private void restoreSettings() { - // filter settings - String formatSettings = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLES_FILTER_SETTINGS, ""); - int i = 0; - for (JToggleButton component : filterButtons) { - if (formatSettings.length() > i) { - component.setSelected(formatSettings.substring(i, i + 1).equals("x")); - } else { - component.setSelected(true); - } - i++; - } + private void saveActiveFiltersToPrefs() { + TableUtil.setActiveFilters(KEY_TABLES_FILTER_SETTINGS, filterButtons); setTableFilter(); } - private void saveSettings() { - // Filters - StringBuilder formatSettings = new StringBuilder(); - for (JToggleButton component : filterButtons) { - formatSettings.append(component.isSelected() ? "x" : "-"); - } - PreferencesDialog.saveValue(PreferencesDialog.KEY_TABLES_FILTER_SETTINGS, formatSettings.toString()); - + private void saveGuiSettings() { + TableUtil.saveActiveFiltersToPrefs(KEY_TABLES_FILTER_SETTINGS, filterButtons); TableUtil.saveColumnWidthAndOrderToPrefs(tableTables, KEY_TABLES_COLUMNS_WIDTH, KEY_TABLES_COLUMNS_ORDER); } - private void restoreDividerLocations() { - Rectangle rec = MageFrame.getDesktop().getBounds(); - if (rec != null) { - String size = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_MAGE_PANEL_LAST_SIZE, null); - String sb = Double.toString(rec.getWidth()) + 'x' + 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)) { - String location = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_1, null); - if (location != null && jSplitPane1 != null) { - jSplitPane1.setDividerLocation(Integer.parseInt(location)); - } - if (this.btnStateFinished.isSelected()) { - this.jSplitPaneTables.setDividerLocation(-1); - } else { - location = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_2, null); - if (location != null && jSplitPaneTables != null) { - jSplitPaneTables.setDividerLocation(Integer.parseInt(location)); - } - } - location = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_3, null); - if (location != null && chatPanelMain != null) { - chatPanelMain.setSplitDividerLocation(Integer.parseInt(location)); - } - } - } + private void restoreDividers() { + Rectangle currentBounds = MageFrame.getDesktop().getBounds(); + if (currentBounds != null) { + String firstDivider = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_1, null); + String tableDivider = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_2, null); + String chatDivider = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_3, null); + GuiDisplayUtil.restoreDividerLocations(currentBounds, firstDivider, jSplitPane1); + GuiDisplayUtil.restoreDividerLocations(currentBounds, tableDivider, jSplitPaneTables); + GuiDisplayUtil.restoreDividerLocations(currentBounds, chatDivider, chatPanelMain); + } } public Map getUIComponents() { @@ -565,7 +538,7 @@ public class TablesPanel extends javax.swing.JPanel { MageFrame.getUI().addButton(MageComponents.NEW_GAME_BUTTON, btnNewTable); // divider locations have to be set with delay else values set are overwritten with system defaults - Executors.newSingleThreadScheduledExecutor().schedule(() -> restoreDividerLocations(), 300, TimeUnit.MILLISECONDS); + Executors.newSingleThreadScheduledExecutor().schedule(() -> restoreDividers(), 300, TimeUnit.MILLISECONDS); } @@ -1284,7 +1257,7 @@ public class TablesPanel extends javax.swing.JPanel { if (currentMessage >= messages.size()) { currentMessage = 0; } - + URLHandler.RemoveMouseAdapter(jLabelFooterText); URLHandler.handleMessage(messages.get(currentMessage), this.jLabelFooterText); } @@ -1447,7 +1420,7 @@ class TableTableModel extends AbstractTableModel { if (tables[arg0].isTournament()) { return "Show"; } else { - owner = tables[arg0].getControllerName(); + owner = tables[arg0].getControllerName(); if (SessionHandler.getSession() != null && owner.equals(SessionHandler.getUserName())) { return ""; } diff --git a/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java b/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java index 2702815006..1ad148b0c2 100644 --- a/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java +++ b/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java @@ -4,8 +4,11 @@ import java.awt.*; import java.util.ArrayList; import java.util.Locale; import javax.swing.*; +import mage.client.dialog.PreferencesDialog; +import static mage.client.dialog.PreferencesDialog.KEY_MAGE_PANEL_LAST_SIZE; import mage.client.MageFrame; import mage.client.util.GUISizeHelper; +import mage.client.table.*; import mage.constants.*; import mage.view.CardView; import mage.view.CounterView; @@ -26,6 +29,29 @@ public final class GuiDisplayUtil { public ArrayList lines; } + public static void restoreDividerLocations(Rectangle bounds, String lastDividerLocation, JComponent component) { + String currentBounds = Double.toString(bounds.getWidth()) + 'x' + Double.toString(bounds.getHeight()); + String savedBounds = PreferencesDialog.getCachedValue(KEY_MAGE_PANEL_LAST_SIZE, null); + // use divider positions only if screen size is the same as it was the time the settings were saved + if (savedBounds != null && savedBounds.equals(currentBounds)) { + if (lastDividerLocation != null && component != null) { + if (component instanceof JSplitPane) { + JSplitPane jSplitPane = (JSplitPane) component; + jSplitPane.setDividerLocation(Integer.parseInt(lastDividerLocation)); + } + + if (component instanceof PlayersChatPanel) { + PlayersChatPanel playerChatPanel = (PlayersChatPanel) component; + playerChatPanel.setSplitDividerLocation(Integer.parseInt(lastDividerLocation)); + } + } + } + } + + public static void setDividerLocation(String dividerPrefKey, int position) { + PreferencesDialog.saveValue(dividerPrefKey, Integer.toString(position)); + } + public static JXPanel getDescription(CardView card, int width, int height) { JXPanel descriptionPanel = new JXPanel(); diff --git a/Mage.Client/src/main/java/mage/client/util/gui/TableUtil.java b/Mage.Client/src/main/java/mage/client/util/gui/TableUtil.java index 61f502f18a..fbd66783b8 100644 --- a/Mage.Client/src/main/java/mage/client/util/gui/TableUtil.java +++ b/Mage.Client/src/main/java/mage/client/util/gui/TableUtil.java @@ -7,6 +7,7 @@ package mage.client.util.gui; import java.util.Arrays; import javax.swing.JTable; +import javax.swing.JToggleButton; import javax.swing.table.TableColumn; import org.apache.log4j.Logger; import mage.client.dialog.PreferencesDialog; @@ -27,7 +28,29 @@ public final class TableUtil { private static final Logger LOGGER = Logger.getLogger(TableUtil.class); - static public void setColumnWidthAndOrder(JTable table, int[] defaultColumnsWidth, String widthPrefKey, String orderPrefKey) { + public static void saveActiveFiltersToPrefs(String filterPrefKey, JToggleButton[] buttons) { + StringBuilder currentFilters = new StringBuilder(); + for (JToggleButton component : buttons) { + currentFilters.append(component.isSelected() ? "x" : "-"); + } + + PreferencesDialog.saveValue(filterPrefKey, currentFilters.toString()); + } + + public static void setActiveFilters(String filterPrefKey, JToggleButton[] buttons) { + String formatSettings = PreferencesDialog.getCachedValue(filterPrefKey, ""); + int i = 0; + for (JToggleButton component : buttons) { + if (formatSettings.length() > i) { + component.setSelected(formatSettings.substring(i, i + 1).equals("x")); + } else { + component.setSelected(true); + } + i++; + } + } + + public static 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 @@ -58,11 +81,11 @@ public final class TableUtil { } - static public void saveColumnWidthAndOrderToPrefs(JTable table, String widthPrefKey, String orderPrefKey) { - // Column width + public static void saveColumnWidthAndOrderToPrefs(JTable table, String widthPrefKey, String orderPrefKey) { StringBuilder columnWidthSettings = new StringBuilder(); StringBuilder columnOrderSettings = new StringBuilder(); boolean firstValue = true; + for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) { TableColumn column = table.getColumnModel().getColumn(table.convertColumnIndexToView(i)); if (!firstValue) { @@ -74,14 +97,14 @@ public final class TableUtil { columnWidthSettings.append(column.getWidth()); columnOrderSettings.append(table.convertColumnIndexToModel(i)); } + 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) { + private static int[] getIntArrayFromString(String stringData) { int[] intArray = null; if (stringData != null && !stringData.isEmpty()) { String[] items = stringData.split(","); From ebc36c503e93fb159484963291775c2f89818eba Mon Sep 17 00:00:00 2001 From: GrayedFox Date: Tue, 22 May 2018 20:36:05 +0200 Subject: [PATCH 2/7] add restoring tournament table chat divider location refactor getting current bounds into utility function --- .../java/mage/client/dialog/PreferencesDialog.java | 1 + .../java/mage/client/dialog/TableWaitingDialog.java | 10 ++++++++++ .../src/main/java/mage/client/table/TablesPanel.java | 12 +++++------- .../java/mage/client/util/gui/GuiDisplayUtil.java | 6 ++++++ 4 files changed, 22 insertions(+), 7 deletions(-) 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 71b0668eef..60620c13ab 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java @@ -203,6 +203,7 @@ public class PreferencesDialog extends javax.swing.JDialog { 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_TABLES_DIVIDER_LOCATION_4 = "tablePanelDividerLocation4"; // Positions of deck editor divider bars public static final String KEY_EDITOR_HORIZONTAL_DIVIDER_LOCATION = "editorHorizontalDividerLocation"; diff --git a/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java b/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java index c3567f83a4..33ff704220 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java @@ -34,6 +34,7 @@ package mage.client.dialog; import java.awt.Dimension; +import java.awt.Rectangle; import java.util.List; import java.util.Optional; import java.util.UUID; @@ -54,6 +55,7 @@ import mage.client.util.GUISizeHelper; import mage.client.util.audio.AudioManager; import mage.client.util.gui.TableUtil; import mage.client.util.gui.countryBox.CountryCellRenderer; +import mage.client.util.gui.GuiDisplayUtil; import mage.players.PlayerType; import mage.remote.Session; import mage.view.SeatView; @@ -61,6 +63,7 @@ import mage.view.TableView; import static mage.client.dialog.PreferencesDialog.KEY_TABLE_WAITING_COLUMNS_ORDER; import static mage.client.dialog.PreferencesDialog.KEY_TABLE_WAITING_COLUMNS_WIDTH; +import static mage.client.dialog.PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_4; /** * @author BetaSteward_at_googlemail.com @@ -154,6 +157,9 @@ public class TableWaitingDialog extends MageDialog { this.roomId = roomId; this.tableId = tableId; this.isTournament = isTournament; + + Rectangle currentBounds = MageFrame.getDesktop().getBounds(); + updateTask = new UpdateSeatsTask(SessionHandler.getSession(), roomId, tableId, this); if (SessionHandler.isTableOwner(roomId, tableId)) { this.btnStart.setVisible(true); @@ -171,6 +177,8 @@ public class TableWaitingDialog extends MageDialog { this.setModal(false); this.setLocation(100, 100); this.setVisible(true); + String tournamentChatDivider = PreferencesDialog.getCachedValue(KEY_TABLES_DIVIDER_LOCATION_4, null); + GuiDisplayUtil.restoreDividerLocations(currentBounds, tournamentChatDivider, jSplitPane1); } else { closeDialog(); } @@ -185,6 +193,8 @@ public class TableWaitingDialog extends MageDialog { MageFrame.getUI().removeButton(MageComponents.TABLE_WAITING_START_BUTTON); this.removeDialog(); TableUtil.saveColumnWidthAndOrderToPrefs(jTableSeats, KEY_TABLE_WAITING_COLUMNS_WIDTH, KEY_TABLE_WAITING_COLUMNS_ORDER); + GuiDisplayUtil.saveCurrentBoundsToPrefs(); + GuiDisplayUtil.setDividerLocation(KEY_TABLES_DIVIDER_LOCATION_4, this.jSplitPane1.getDividerLocation()); } /** 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 c8ee3e7f1f..eacd35acd1 100644 --- a/Mage.Client/src/main/java/mage/client/table/TablesPanel.java +++ b/Mage.Client/src/main/java/mage/client/table/TablesPanel.java @@ -410,10 +410,8 @@ public class TablesPanel extends javax.swing.JPanel { } private void saveDividerLocations() { - // save desktop bounds and divider locations - Rectangle rec = MageFrame.getDesktop().getBounds(); - String currentBounds = Double.toString(rec.getWidth()) + 'x' + Double.toString(rec.getHeight()); - PreferencesDialog.saveValue(KEY_MAGE_PANEL_LAST_SIZE, currentBounds); + // save divider locations and divider saveDividerLocations + GuiDisplayUtil.saveCurrentBoundsToPrefs(); GuiDisplayUtil.setDividerLocation(KEY_TABLES_DIVIDER_LOCATION_1, this.jSplitPane1.getDividerLocation()); GuiDisplayUtil.setDividerLocation(KEY_TABLES_DIVIDER_LOCATION_2, this.jSplitPaneTables.getDividerLocation()); GuiDisplayUtil.setDividerLocation(KEY_TABLES_DIVIDER_LOCATION_3, chatPanelMain.getSplitDividerLocation()); @@ -432,9 +430,9 @@ public class TablesPanel extends javax.swing.JPanel { private void restoreDividers() { Rectangle currentBounds = MageFrame.getDesktop().getBounds(); if (currentBounds != null) { - String firstDivider = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_1, null); - String tableDivider = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_2, null); - String chatDivider = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_3, null); + String firstDivider = PreferencesDialog.getCachedValue(KEY_TABLES_DIVIDER_LOCATION_1, null); + String tableDivider = PreferencesDialog.getCachedValue(KEY_TABLES_DIVIDER_LOCATION_2, null); + String chatDivider = PreferencesDialog.getCachedValue(KEY_TABLES_DIVIDER_LOCATION_3, null); GuiDisplayUtil.restoreDividerLocations(currentBounds, firstDivider, jSplitPane1); GuiDisplayUtil.restoreDividerLocations(currentBounds, tableDivider, jSplitPaneTables); GuiDisplayUtil.restoreDividerLocations(currentBounds, chatDivider, chatPanelMain); diff --git a/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java b/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java index 1ad148b0c2..cd478e47e2 100644 --- a/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java +++ b/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java @@ -48,6 +48,12 @@ public final class GuiDisplayUtil { } } + public static void saveCurrentBoundsToPrefs() { + Rectangle rec = MageFrame.getDesktop().getBounds(); + String currentBounds = Double.toString(rec.getWidth()) + 'x' + Double.toString(rec.getHeight()); + PreferencesDialog.saveValue(KEY_MAGE_PANEL_LAST_SIZE, currentBounds); + } + public static void setDividerLocation(String dividerPrefKey, int position) { PreferencesDialog.saveValue(dividerPrefKey, Integer.toString(position)); } From 32cb438e7cb3a17d643c3a4078b427ccc19fe7f2 Mon Sep 17 00:00:00 2001 From: GrayedFox Date: Tue, 22 May 2018 21:26:17 +0200 Subject: [PATCH 3/7] minor refactor - code ordering and variable reference --- .../mage/client/dialog/TableWaitingDialog.java | 15 +++++++-------- .../main/java/mage/client/table/TablesPanel.java | 3 +-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java b/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java index 33ff704220..238d203d79 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java @@ -95,12 +95,10 @@ public class TableWaitingDialog extends MageDialog { } 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()); - + TableUtil.setColumnWidthAndOrder(jTableSeats, DEFAULT_COLUMNS_WIDTH, KEY_TABLE_WAITING_COLUMNS_WIDTH, KEY_TABLE_WAITING_COLUMNS_ORDER); + chatPanel.useExtendedView(ChatPanelBasic.VIEW_MODE.NONE); MageFrame.getUI().addButton(MageComponents.TABLE_WAITING_START_BUTTON, btnStart); } @@ -154,13 +152,14 @@ public class TableWaitingDialog extends MageDialog { } public void showDialog(UUID roomId, UUID tableId, boolean isTournament) { + Rectangle currentBounds = MageFrame.getDesktop().getBounds(); + Optional chatId = SessionHandler.getTableChatId(tableId); + updateTask = new UpdateSeatsTask(SessionHandler.getSession(), roomId, tableId, this); + this.roomId = roomId; this.tableId = tableId; this.isTournament = isTournament; - Rectangle currentBounds = MageFrame.getDesktop().getBounds(); - - updateTask = new UpdateSeatsTask(SessionHandler.getSession(), roomId, tableId, this); if (SessionHandler.isTableOwner(roomId, tableId)) { this.btnStart.setVisible(true); this.btnMoveDown.setVisible(true); @@ -170,7 +169,7 @@ public class TableWaitingDialog extends MageDialog { this.btnMoveDown.setVisible(false); this.btnMoveUp.setVisible(false); } - Optional chatId = SessionHandler.getTableChatId(tableId); + if (chatId.isPresent()) { this.chatPanel.connect(chatId.get()); updateTask.execute(); 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 eacd35acd1..d9610492a8 100644 --- a/Mage.Client/src/main/java/mage/client/table/TablesPanel.java +++ b/Mage.Client/src/main/java/mage/client/table/TablesPanel.java @@ -196,8 +196,7 @@ public class TablesPanel extends javax.swing.JPanel { list.add(new RowSorter.SortKey(TableTableModel.COLUMN_CREATED, SortOrder.DESCENDING)); activeTablesSorter.setSortKeys(list); - TableUtil.setColumnWidthAndOrder(tableTables, DEFAULT_COLUMNS_WIDTH, - PreferencesDialog.KEY_TABLES_COLUMNS_WIDTH, PreferencesDialog.KEY_TABLES_COLUMNS_ORDER); + TableUtil.setColumnWidthAndOrder(tableTables, DEFAULT_COLUMNS_WIDTH, KEY_TABLES_COLUMNS_WIDTH, KEY_TABLES_COLUMNS_ORDER); // 2. TABLE COMPLETED completedTablesSorter = new MageTableRowSorter(matchesModel); From 42b539c41f351612255119741005ac354814a108 Mon Sep 17 00:00:00 2001 From: GrayedFox Date: Wed, 23 May 2018 16:49:48 +0200 Subject: [PATCH 4/7] renamed utility functions for clarity --- .../java/mage/client/dialog/TableWaitingDialog.java | 5 +++-- .../src/main/java/mage/client/table/TablesPanel.java | 10 +++++----- .../main/java/mage/client/util/gui/GuiDisplayUtil.java | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java b/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java index 238d203d79..cc9e0e5fe8 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java @@ -154,6 +154,7 @@ public class TableWaitingDialog extends MageDialog { public void showDialog(UUID roomId, UUID tableId, boolean isTournament) { Rectangle currentBounds = MageFrame.getDesktop().getBounds(); Optional chatId = SessionHandler.getTableChatId(tableId); + String tournamentChatDivider = PreferencesDialog.getCachedValue(KEY_TABLES_DIVIDER_LOCATION_4, null); updateTask = new UpdateSeatsTask(SessionHandler.getSession(), roomId, tableId, this); this.roomId = roomId; @@ -176,7 +177,7 @@ public class TableWaitingDialog extends MageDialog { this.setModal(false); this.setLocation(100, 100); this.setVisible(true); - String tournamentChatDivider = PreferencesDialog.getCachedValue(KEY_TABLES_DIVIDER_LOCATION_4, null); + GuiDisplayUtil.restoreDividerLocations(currentBounds, tournamentChatDivider, jSplitPane1); } else { closeDialog(); @@ -193,7 +194,7 @@ public class TableWaitingDialog extends MageDialog { this.removeDialog(); TableUtil.saveColumnWidthAndOrderToPrefs(jTableSeats, KEY_TABLE_WAITING_COLUMNS_WIDTH, KEY_TABLE_WAITING_COLUMNS_ORDER); GuiDisplayUtil.saveCurrentBoundsToPrefs(); - GuiDisplayUtil.setDividerLocation(KEY_TABLES_DIVIDER_LOCATION_4, this.jSplitPane1.getDividerLocation()); + GuiDisplayUtil.saveDividerLocationToPrefs(KEY_TABLES_DIVIDER_LOCATION_4, this.jSplitPane1.getDividerLocation()); } /** 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 d9610492a8..31b1868657 100644 --- a/Mage.Client/src/main/java/mage/client/table/TablesPanel.java +++ b/Mage.Client/src/main/java/mage/client/table/TablesPanel.java @@ -231,7 +231,7 @@ public class TablesPanel extends javax.swing.JPanel { jScrollPaneTablesActive.getViewport().setBackground(new Color(255, 255, 255, 50)); jScrollPaneTablesFinished.getViewport().setBackground(new Color(255, 255, 255, 50)); - saveActiveFiltersToPrefs(); + restoreFilters(); setGUISize(); Action openTableAction; @@ -411,12 +411,12 @@ public class TablesPanel extends javax.swing.JPanel { private void saveDividerLocations() { // save divider locations and divider saveDividerLocations GuiDisplayUtil.saveCurrentBoundsToPrefs(); - GuiDisplayUtil.setDividerLocation(KEY_TABLES_DIVIDER_LOCATION_1, this.jSplitPane1.getDividerLocation()); - GuiDisplayUtil.setDividerLocation(KEY_TABLES_DIVIDER_LOCATION_2, this.jSplitPaneTables.getDividerLocation()); - GuiDisplayUtil.setDividerLocation(KEY_TABLES_DIVIDER_LOCATION_3, chatPanelMain.getSplitDividerLocation()); + GuiDisplayUtil.saveDividerLocationToPrefs(KEY_TABLES_DIVIDER_LOCATION_1, this.jSplitPane1.getDividerLocation()); + GuiDisplayUtil.saveDividerLocationToPrefs(KEY_TABLES_DIVIDER_LOCATION_2, this.jSplitPaneTables.getDividerLocation()); + GuiDisplayUtil.saveDividerLocationToPrefs(KEY_TABLES_DIVIDER_LOCATION_3, chatPanelMain.getSplitDividerLocation()); } - private void saveActiveFiltersToPrefs() { + private void restoreFilters() { TableUtil.setActiveFilters(KEY_TABLES_FILTER_SETTINGS, filterButtons); setTableFilter(); } diff --git a/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java b/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java index cd478e47e2..2261c9e2a7 100644 --- a/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java +++ b/Mage.Client/src/main/java/mage/client/util/gui/GuiDisplayUtil.java @@ -54,7 +54,7 @@ public final class GuiDisplayUtil { PreferencesDialog.saveValue(KEY_MAGE_PANEL_LAST_SIZE, currentBounds); } - public static void setDividerLocation(String dividerPrefKey, int position) { + public static void saveDividerLocationToPrefs(String dividerPrefKey, int position) { PreferencesDialog.saveValue(dividerPrefKey, Integer.toString(position)); } From 49fd99a45bffbc13d9948d4c40d282d8f28a872d Mon Sep 17 00:00:00 2001 From: GrayedFox Date: Wed, 23 May 2018 18:00:25 +0200 Subject: [PATCH 5/7] fix columns being resized due to auto creation flag --- .../src/main/java/mage/client/dialog/TableWaitingDialog.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java b/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java index cc9e0e5fe8..7a1d1b1fa5 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java @@ -96,6 +96,7 @@ public class TableWaitingDialog extends MageDialog { setGUISize(); jTableSeats.createDefaultColumnsFromModel(); + jTableSeats.setAutoCreateColumnsFromModel(false); jTableSeats.setDefaultRenderer(Icon.class, new CountryCellRenderer()); TableUtil.setColumnWidthAndOrder(jTableSeats, DEFAULT_COLUMNS_WIDTH, KEY_TABLE_WAITING_COLUMNS_WIDTH, KEY_TABLE_WAITING_COLUMNS_ORDER); chatPanel.useExtendedView(ChatPanelBasic.VIEW_MODE.NONE); From 9da01a1270105839bd892c028caa38a0246ed7f6 Mon Sep 17 00:00:00 2001 From: GrayedFox Date: Wed, 23 May 2018 18:50:12 +0200 Subject: [PATCH 6/7] remove logging --- Mage.Client/src/main/java/mage/client/util/gui/TableUtil.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/util/gui/TableUtil.java b/Mage.Client/src/main/java/mage/client/util/gui/TableUtil.java index fbd66783b8..f762afb2f4 100644 --- a/Mage.Client/src/main/java/mage/client/util/gui/TableUtil.java +++ b/Mage.Client/src/main/java/mage/client/util/gui/TableUtil.java @@ -55,7 +55,6 @@ public final class TableUtil { // 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) { @@ -72,7 +71,6 @@ 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); @@ -100,8 +98,6 @@ 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()); } private static int[] getIntArrayFromString(String stringData) { From f3cdad97e7ef9f8147f29edb18a2ab47ea98b6c2 Mon Sep 17 00:00:00 2001 From: GrayedFox Date: Wed, 23 May 2018 19:06:01 +0200 Subject: [PATCH 7/7] add default width for History (also fixes stored width not being used) --- .../src/main/java/mage/client/dialog/TableWaitingDialog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java b/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java index 7a1d1b1fa5..db61cf981d 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java @@ -71,7 +71,7 @@ import static mage.client.dialog.PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_4 public class TableWaitingDialog extends MageDialog { private static final Logger LOGGER = Logger.getLogger(TableWaitingDialog.class); - private static final int[] DEFAULT_COLUMNS_WIDTH = {20, 50, 100, 100, 100}; + private static final int[] DEFAULT_COLUMNS_WIDTH = {20, 50, 100, 100, 100, 100}; private UUID tableId; private UUID roomId;