From ebc36c503e93fb159484963291775c2f89818eba Mon Sep 17 00:00:00 2001 From: GrayedFox Date: Tue, 22 May 2018 20:36:05 +0200 Subject: [PATCH] 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 71b0668eef8..60620c13ab0 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 c3567f83a4a..33ff704220d 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 c8ee3e7f1ff..eacd35acd16 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 1ad148b0c2b..cd478e47e27 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)); }