From 29e57830b48889e661ea798ffb268703f622343e Mon Sep 17 00:00:00 2001 From: magenoxx Date: Mon, 23 Jul 2012 09:07:25 +0400 Subject: [PATCH] Remembering toggle state for BigCard component between games --- .../mage/client/dialog/PreferencesDialog.java | 15 ++++++++- .../main/java/mage/client/game/GamePanel.java | 32 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) 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 705aba1f8d..98c4322c67 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java @@ -69,6 +69,7 @@ public class PreferencesDialog extends javax.swing.JDialog { public static final String KEY_CARD_IMAGES_USE_DEFAULT = "cardImagesUseDefault"; public static final String KEY_CARD_IMAGES_PATH = "cardImagesPath"; public static final String KEY_CARD_IMAGES_CHECK = "cardImagesCheck"; + public static final String KEY_BIG_CARD_TOGGLED = "bigCardToggled"; public static final String KEY_PROXY_ADDRESS = "proxyAddress"; public static final String KEY_PROXY_PORT = "proxyPort"; @@ -967,7 +968,7 @@ public class PreferencesDialog extends javax.swing.JDialog { prefs.flush(); } catch (BackingStoreException ex) { ex.printStackTrace(); - JOptionPane.showMessageDialog(null, "Error: couldn't save phase stops. Please try again."); + JOptionPane.showMessageDialog(null, "Error: couldn't save preferences. Please try once again."); } dialog.setVisible(false); @@ -1246,6 +1247,18 @@ public class PreferencesDialog extends javax.swing.JDialog { cache.put(key, value); } + public static void saveValue(String key, String value) { + Preferences prefs = MageFrame.getPreferences(); + prefs.put(key, value); + try { + prefs.flush(); + } catch (BackingStoreException ex) { + ex.printStackTrace(); + JOptionPane.showMessageDialog(null, "Error: couldn't save preferences. Please try once again."); + } + updateCache(key, value); + } + private void addAvatars() { try { addAvatar(jPanel10, 51, true, false); diff --git a/Mage.Client/src/main/java/mage/client/game/GamePanel.java b/Mage.Client/src/main/java/mage/client/game/GamePanel.java index 90c2d15b88..0c85bccc63 100644 --- a/Mage.Client/src/main/java/mage/client/game/GamePanel.java +++ b/Mage.Client/src/main/java/mage/client/game/GamePanel.java @@ -57,6 +57,8 @@ import org.apache.log4j.Logger; import javax.swing.*; import javax.swing.GroupLayout.Alignment; import javax.swing.border.LineBorder; +import javax.swing.plaf.basic.BasicSplitPaneDivider; +import javax.swing.plaf.basic.BasicSplitPaneUI; import java.awt.*; import java.awt.event.*; import java.io.Serializable; @@ -87,6 +89,7 @@ public class GamePanel extends javax.swing.JPanel { private JLayeredPane jLayeredPane; private String chosenHandKey = "You"; private boolean smallMode = false; + private boolean initialized = false; private HelperPanel helper; @@ -123,6 +126,17 @@ public class GamePanel extends javax.swing.JPanel { j.setSize(width, height); jSplitPane0.setSize(width, height); sizeToScreen(); + + if (!initialized) { + String state = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BIG_CARD_TOGGLED, null); + if (state != null) { + if (state.equals("down")) { + jSplitPane0.setDividerLocation(1.0); + } + } + } + + initialized = true; } }); @@ -791,6 +805,24 @@ public class GamePanel extends javax.swing.JPanel { } }); + final BasicSplitPaneUI ui = (BasicSplitPaneUI) jSplitPane0.getUI(); + final BasicSplitPaneDivider divider = ui.getDivider(); + final JButton upArrowButton = (JButton) divider.getComponent(0); + upArrowButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + PreferencesDialog.saveValue(PreferencesDialog.KEY_BIG_CARD_TOGGLED, "up"); + } + }); + + final JButton downArrowButton = (JButton) divider.getComponent(1); + downArrowButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + PreferencesDialog.saveValue(PreferencesDialog.KEY_BIG_CARD_TOGGLED, "down"); + } + }); + KeyStroke ksAltShiftReleased = KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.ALT_MASK, true); this.getInputMap(c).put(ksAltShiftReleased, "ENLARGE_RELEASE"); this.getActionMap().put("ENLARGE_RELEASE", new AbstractAction() {