Remembering toggle state for BigCard component between games

This commit is contained in:
magenoxx 2012-07-23 09:07:25 +04:00
parent 435798f7d5
commit 29e57830b4
2 changed files with 46 additions and 1 deletions

View file

@ -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_USE_DEFAULT = "cardImagesUseDefault";
public static final String KEY_CARD_IMAGES_PATH = "cardImagesPath"; public static final String KEY_CARD_IMAGES_PATH = "cardImagesPath";
public static final String KEY_CARD_IMAGES_CHECK = "cardImagesCheck"; 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_ADDRESS = "proxyAddress";
public static final String KEY_PROXY_PORT = "proxyPort"; public static final String KEY_PROXY_PORT = "proxyPort";
@ -967,7 +968,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
prefs.flush(); prefs.flush();
} catch (BackingStoreException ex) { } catch (BackingStoreException ex) {
ex.printStackTrace(); 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); dialog.setVisible(false);
@ -1246,6 +1247,18 @@ public class PreferencesDialog extends javax.swing.JDialog {
cache.put(key, value); 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() { private void addAvatars() {
try { try {
addAvatar(jPanel10, 51, true, false); addAvatar(jPanel10, 51, true, false);

View file

@ -57,6 +57,8 @@ import org.apache.log4j.Logger;
import javax.swing.*; import javax.swing.*;
import javax.swing.GroupLayout.Alignment; import javax.swing.GroupLayout.Alignment;
import javax.swing.border.LineBorder; import javax.swing.border.LineBorder;
import javax.swing.plaf.basic.BasicSplitPaneDivider;
import javax.swing.plaf.basic.BasicSplitPaneUI;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.io.Serializable; import java.io.Serializable;
@ -87,6 +89,7 @@ public class GamePanel extends javax.swing.JPanel {
private JLayeredPane jLayeredPane; private JLayeredPane jLayeredPane;
private String chosenHandKey = "You"; private String chosenHandKey = "You";
private boolean smallMode = false; private boolean smallMode = false;
private boolean initialized = false;
private HelperPanel helper; private HelperPanel helper;
@ -123,6 +126,17 @@ public class GamePanel extends javax.swing.JPanel {
j.setSize(width, height); j.setSize(width, height);
jSplitPane0.setSize(width, height); jSplitPane0.setSize(width, height);
sizeToScreen(); 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); KeyStroke ksAltShiftReleased = KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.ALT_MASK, true);
this.getInputMap(c).put(ksAltShiftReleased, "ENLARGE_RELEASE"); this.getInputMap(c).put(ksAltShiftReleased, "ENLARGE_RELEASE");
this.getActionMap().put("ENLARGE_RELEASE", new AbstractAction() { this.getActionMap().put("ENLARGE_RELEASE", new AbstractAction() {