add restoring tournament table chat divider location

refactor getting current bounds into utility function
This commit is contained in:
GrayedFox 2018-05-22 20:36:05 +02:00
parent 5822a7d94d
commit ebc36c503e
No known key found for this signature in database
GPG key ID: 7FF4748DBF28C93F
4 changed files with 22 additions and 7 deletions

View file

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

View file

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

View file

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

View file

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