Make tooltips work properly

This commit is contained in:
Campbell Suter 2016-10-19 09:15:37 +13:00
parent e910778e54
commit d9ebceec20
No known key found for this signature in database
GPG key ID: 754A66CCF3F73C0F
2 changed files with 67 additions and 44 deletions

View file

@ -3318,15 +3318,15 @@ public class PreferencesDialog extends javax.swing.JDialog {
}
private static void loadControlSettings(Preferences prefs) {
load(prefs, dialog.keyConfirm, KEY_CONTROL_CONFIRM, KeyEvent.VK_F2);
load(prefs, dialog.keyCancelSkip, KEY_CONTROL_CANCEL_SKIP, KeyEvent.VK_F3);
load(prefs, dialog.keyNextTurn, KEY_CONTROL_NEXT_TURN, KeyEvent.VK_F4);
load(prefs, dialog.keyEndStep, KEY_CONTROL_END_STEP, KeyEvent.VK_F5);
load(prefs, dialog.keySkipStep, KEY_CONTROL_SKIP_STEP, KeyEvent.VK_F6);
load(prefs, dialog.keyMainStep, KEY_CONTROL_MAIN_STEP, KeyEvent.VK_F7);
load(prefs, dialog.keyYourTurn, KEY_CONTROL_YOUR_TURN, KeyEvent.VK_F9);
load(prefs, dialog.keySkipStack, KEY_CONTROL_SKIP_STACK, KeyEvent.VK_F10);
load(prefs, dialog.keyPriorEnd, KEY_CONTROL_PRIOR_END, KeyEvent.VK_F11);
load(prefs, dialog.keyConfirm, KEY_CONTROL_CONFIRM);
load(prefs, dialog.keyCancelSkip, KEY_CONTROL_CANCEL_SKIP);
load(prefs, dialog.keyNextTurn, KEY_CONTROL_NEXT_TURN);
load(prefs, dialog.keyEndStep, KEY_CONTROL_END_STEP);
load(prefs, dialog.keySkipStep, KEY_CONTROL_SKIP_STEP);
load(prefs, dialog.keyMainStep, KEY_CONTROL_MAIN_STEP);
load(prefs, dialog.keyYourTurn, KEY_CONTROL_YOUR_TURN);
load(prefs, dialog.keySkipStack, KEY_CONTROL_SKIP_STACK);
load(prefs, dialog.keyPriorEnd, KEY_CONTROL_PRIOR_END);
}
private static void loadSelectedAvatar(Preferences prefs) {
@ -3453,8 +3453,8 @@ public class PreferencesDialog extends javax.swing.JDialog {
load(prefs, checkBox, propName, PHASE_ON);
}
private static void load(Preferences prefs, KeyBindButton button, String propName, int defaultValue) {
int prop = prefs.getInt(propName, defaultValue);
private static void load(Preferences prefs, KeyBindButton button, String propName) {
int prop = prefs.getInt(propName, getDefaultControlKey(propName));
button.setKeyCode(prop);
}
@ -3531,11 +3531,41 @@ public class PreferencesDialog extends javax.swing.JDialog {
}
}
public static KeyStroke getCachedKeystroke(String key, int def) {
int code = getCachedValue(key, def);
private static int getDefaultControlKey(String key) {
switch (key) {
case KEY_CONTROL_CONFIRM:
return KeyEvent.VK_F2;
case KEY_CONTROL_CANCEL_SKIP:
return KeyEvent.VK_F3;
case KEY_CONTROL_NEXT_TURN:
return KeyEvent.VK_F4;
case KEY_CONTROL_END_STEP:
return KeyEvent.VK_F5;
case KEY_CONTROL_SKIP_STEP:
return KeyEvent.VK_F6;
case KEY_CONTROL_MAIN_STEP:
return KeyEvent.VK_F7;
case KEY_CONTROL_YOUR_TURN:
return KeyEvent.VK_F9;
case KEY_CONTROL_SKIP_STACK:
return KeyEvent.VK_F10;
case KEY_CONTROL_PRIOR_END:
return KeyEvent.VK_F11;
default:
return 0;
}
}
public static KeyStroke getCachedKeystroke(String key) {
int code = getCachedValue(key, getDefaultControlKey(key));
return KeyStroke.getKeyStroke(code, 0);
}
public static String getCachedKeyText(String key) {
int code = getCachedValue(key, getDefaultControlKey(key));
return KeyEvent.getKeyText(code);
}
private static void updateCache(String key, String value) {
CACHE.put(key, value);
}

View file

@ -99,12 +99,7 @@ import mage.client.dialog.PickChoiceDialog;
import mage.client.dialog.PickNumberDialog;
import mage.client.dialog.PickPileDialog;
import mage.client.dialog.PreferencesDialog;
import static mage.client.dialog.PreferencesDialog.KEY_CONTROL_NEXT_TURN;
import static mage.client.dialog.PreferencesDialog.KEY_CONTROL_PRIOR_END;
import static mage.client.dialog.PreferencesDialog.KEY_CONTROL_YOUR_TURN;
import static mage.client.dialog.PreferencesDialog.KEY_GAME_MANA_AUTOPAYMENT;
import static mage.client.dialog.PreferencesDialog.KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE;
import static mage.client.dialog.PreferencesDialog.KEY_USE_FIRST_MANA_ABILITY;
import static mage.client.dialog.PreferencesDialog.*;
import mage.client.dialog.ShowCardsDialog;
import mage.client.game.FeedbackPanel.FeedbackMode;
import mage.client.plugins.adapters.MageActionCallback;
@ -1449,8 +1444,7 @@ public final class GamePanel extends javax.swing.JPanel {
int c = JComponent.WHEN_IN_FOCUSED_WINDOW;
KeyStroke ks3 = PreferencesDialog.getCachedKeystroke(
PreferencesDialog.KEY_CONTROL_CANCEL_SKIP, KeyEvent.VK_F3);
KeyStroke ks3 = getCachedKeystroke(KEY_CONTROL_CANCEL_SKIP);
this.getInputMap(c).put(ks3, "F3_PRESS");
this.getActionMap().put("F3_PRESS", new AbstractAction() {
@Override
@ -1462,7 +1456,8 @@ public final class GamePanel extends javax.swing.JPanel {
btnCancelSkip.setContentAreaFilled(false);
btnCancelSkip.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE));
btnCancelSkip.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getCancelSkipButtonImage()));
btnCancelSkip.setToolTipText("Cancel all skip actions (F3).");
btnCancelSkip.setToolTipText("Cancel all skip actions ("
+ getCachedKeyText(KEY_CONTROL_CANCEL_SKIP) + ").");
btnCancelSkip.setFocusable(false);
btnCancelSkip.addMouseListener(new MouseAdapter() {
@Override
@ -1476,7 +1471,8 @@ public final class GamePanel extends javax.swing.JPanel {
btnSkipToNextTurn.setContentAreaFilled(false);
btnSkipToNextTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE));
btnSkipToNextTurn.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipNextTurnButtonImage()));
btnSkipToNextTurn.setToolTipText("Skip to next turn (F4).");
btnSkipToNextTurn.setToolTipText("Skip to next turn ("
+ getCachedKeyText(KEY_CONTROL_NEXT_TURN) + ").");
btnSkipToNextTurn.setFocusable(false);
btnSkipToNextTurn.addMouseListener(new MouseAdapter() {
@Override
@ -1487,8 +1483,7 @@ public final class GamePanel extends javax.swing.JPanel {
}
});
KeyStroke ks = PreferencesDialog.getCachedKeystroke(
PreferencesDialog.KEY_CONTROL_NEXT_TURN, KeyEvent.VK_F4);
KeyStroke ks = getCachedKeystroke(KEY_CONTROL_NEXT_TURN);
this.getInputMap(c).put(ks, "F4_PRESS");
this.getActionMap().put("F4_PRESS", new AbstractAction() {
@Override
@ -1500,7 +1495,8 @@ public final class GamePanel extends javax.swing.JPanel {
btnSkipToEndTurn.setContentAreaFilled(false);
btnSkipToEndTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE));
btnSkipToEndTurn.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipEndTurnButtonImage()));
btnSkipToEndTurn.setToolTipText("Skip to (opponents/next) end of turn step (F5) - adjust using preferences.");
btnSkipToEndTurn.setToolTipText("Skip to (opponents/next) end of turn step ("
+ getCachedKeyText(KEY_CONTROL_END_STEP) + ") - adjust using preferences.");
btnSkipToEndTurn.setFocusable(false);
btnSkipToEndTurn.addMouseListener(new MouseAdapter() {
@Override
@ -1511,8 +1507,7 @@ public final class GamePanel extends javax.swing.JPanel {
}
});
ks = PreferencesDialog.getCachedKeystroke(
PreferencesDialog.KEY_CONTROL_END_STEP, KeyEvent.VK_F5);
ks = getCachedKeystroke(KEY_CONTROL_END_STEP);
this.getInputMap(c).put(ks, "F5_PRESS");
this.getActionMap().put("F5_PRESS", new AbstractAction() {
@Override
@ -1521,8 +1516,7 @@ public final class GamePanel extends javax.swing.JPanel {
}
});
ks = PreferencesDialog.getCachedKeystroke(
PreferencesDialog.KEY_CONTROL_SKIP_STEP, KeyEvent.VK_F6);
ks = getCachedKeystroke(KEY_CONTROL_SKIP_STEP);
this.getInputMap(c).put(ks, "F6_PRESS");
this.getActionMap().put("F6_PRESS", new AbstractAction() {
@Override
@ -1534,7 +1528,8 @@ public final class GamePanel extends javax.swing.JPanel {
btnSkipToNextMain.setContentAreaFilled(false);
btnSkipToNextMain.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE));
btnSkipToNextMain.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipMainButtonImage()));
btnSkipToNextMain.setToolTipText("Skip to (your) next main phase (F7) - adjust using preferences.");
btnSkipToNextMain.setToolTipText("Skip to (your) next main phase ("
+ getCachedKeyText(KEY_CONTROL_MAIN_STEP) + ") - adjust using preferences.");
btnSkipToNextMain.setFocusable(false);
btnSkipToNextMain.addMouseListener(new MouseAdapter() {
@Override
@ -1545,8 +1540,7 @@ public final class GamePanel extends javax.swing.JPanel {
}
});
ks = PreferencesDialog.getCachedKeystroke(
PreferencesDialog.KEY_CONTROL_MAIN_STEP, KeyEvent.VK_F7);
ks = getCachedKeystroke(KEY_CONTROL_MAIN_STEP);
this.getInputMap(c).put(ks, "F7_PRESS");
this.getActionMap().put("F7_PRESS", new AbstractAction() {
@Override
@ -1558,7 +1552,8 @@ public final class GamePanel extends javax.swing.JPanel {
btnSkipToYourTurn.setContentAreaFilled(false);
btnSkipToYourTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE));
btnSkipToYourTurn.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipYourNextTurnButtonImage()));
btnSkipToYourTurn.setToolTipText("Skip to your next turn (F9).");
btnSkipToYourTurn.setToolTipText("Skip to your next turn ("
+ getCachedKeyText(KEY_CONTROL_YOUR_TURN) + ").");
btnSkipToYourTurn.setFocusable(false);
btnSkipToYourTurn.addMouseListener(new MouseAdapter() {
@Override
@ -1569,8 +1564,7 @@ public final class GamePanel extends javax.swing.JPanel {
}
});
KeyStroke ks9 = PreferencesDialog.getCachedKeystroke(
PreferencesDialog.KEY_CONTROL_YOUR_TURN, KeyEvent.VK_F9);
KeyStroke ks9 = getCachedKeystroke(KEY_CONTROL_YOUR_TURN);
this.getInputMap(c).put(ks9, "F9_PRESS");
this.getActionMap().put("F9_PRESS", new AbstractAction() {
@Override
@ -1582,7 +1576,8 @@ public final class GamePanel extends javax.swing.JPanel {
btnSkipToEndStepBeforeYourTurn.setContentAreaFilled(false);
btnSkipToEndStepBeforeYourTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE));
btnSkipToEndStepBeforeYourTurn.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipEndStepBeforeYourTurnButtonImage()));
btnSkipToEndStepBeforeYourTurn.setToolTipText("Skip to the end step before your turn (F11) - adjust using preferences.");
btnSkipToEndStepBeforeYourTurn.setToolTipText("Skip to the end step before your turn ("
+ getCachedKeyText(KEY_CONTROL_PRIOR_END) + ") - adjust using preferences.");
btnSkipToEndStepBeforeYourTurn.setFocusable(false);
btnSkipToEndStepBeforeYourTurn.addMouseListener(new MouseAdapter() {
@Override
@ -1593,8 +1588,7 @@ public final class GamePanel extends javax.swing.JPanel {
}
});
KeyStroke ks11 = PreferencesDialog.getCachedKeystroke(
PreferencesDialog.KEY_CONTROL_PRIOR_END, KeyEvent.VK_F11);
KeyStroke ks11 = getCachedKeystroke(KEY_CONTROL_PRIOR_END);
this.getInputMap(c).put(ks11, "F11_PRESS");
this.getActionMap().put("F11_PRESS", new AbstractAction() {
@Override
@ -1606,7 +1600,8 @@ public final class GamePanel extends javax.swing.JPanel {
btnSkipStack.setContentAreaFilled(false);
btnSkipStack.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE));
btnSkipStack.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipStackButtonImage()));
btnSkipStack.setToolTipText("Skip until stack is resolved (F10).");
btnSkipStack.setToolTipText("Skip until stack is resolved ("
+ getCachedKeyText(KEY_CONTROL_SKIP_STACK) + ").");
btnSkipStack.setFocusable(false);
btnSkipStack.addMouseListener(new MouseAdapter() {
@Override
@ -1617,8 +1612,7 @@ public final class GamePanel extends javax.swing.JPanel {
}
});
ks = PreferencesDialog.getCachedKeystroke(
PreferencesDialog.KEY_CONTROL_SKIP_STACK, KeyEvent.VK_F10);
ks = getCachedKeystroke(KEY_CONTROL_SKIP_STACK);
this.getInputMap(c).put(ks, "F10_PRESS");
this.getActionMap().put("F10_PRESS", new AbstractAction() {
@Override
@ -1641,8 +1635,7 @@ public final class GamePanel extends javax.swing.JPanel {
}
});
KeyStroke ks2 = PreferencesDialog.getCachedKeystroke(
PreferencesDialog.KEY_CONTROL_CONFIRM, KeyEvent.VK_F2);
KeyStroke ks2 = getCachedKeystroke(KEY_CONTROL_CONFIRM);
this.getInputMap(c).put(ks2, "F2_PRESS");
this.getActionMap().put("F2_PRESS", new AbstractAction() {
@Override