mirror of
https://github.com/correl/mage.git
synced 2025-03-16 17:00:13 -09:00
Merge pull request #5626 from hitch17/more-forgiving-button-presses
Simulate JButton behavior while still preserving check for BUTTON1
This commit is contained in:
commit
1ad6dc9976
3 changed files with 93 additions and 89 deletions
|
@ -15,6 +15,8 @@ public class KeyboundButton extends JButton {
|
||||||
private final String text;
|
private final String text;
|
||||||
private static final Font keyFont = new Font(Font.SANS_SERIF, Font.BOLD, 13);
|
private static final Font keyFont = new Font(Font.SANS_SERIF, Font.BOLD, 13);
|
||||||
|
|
||||||
|
private boolean tinting = false;
|
||||||
|
|
||||||
public KeyboundButton(String key) {
|
public KeyboundButton(String key) {
|
||||||
text = PreferencesDialog.getCachedKeyText(key);
|
text = PreferencesDialog.getCachedKeyText(key);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +27,11 @@ public class KeyboundButton extends JButton {
|
||||||
Graphics sg = g.create();
|
Graphics sg = g.create();
|
||||||
try {
|
try {
|
||||||
ui.update(sg, this);
|
ui.update(sg, this);
|
||||||
sg.setColor(Color.white);
|
if (tinting) {
|
||||||
|
sg.setColor(new Color(0, 0, 0, 32));
|
||||||
|
sg.fillRoundRect(2, 2, getWidth() - 4 , getHeight() - 4, 6, 6);
|
||||||
|
}
|
||||||
|
sg.setColor(tinting ? Color.lightGray : Color.white);
|
||||||
sg.setFont(keyFont);
|
sg.setFont(keyFont);
|
||||||
|
|
||||||
int textWidth = sg.getFontMetrics(keyFont).stringWidth(text);
|
int textWidth = sg.getFontMetrics(keyFont).stringWidth(text);
|
||||||
|
@ -37,4 +43,10 @@ public class KeyboundButton extends JButton {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTint(boolean tinting) {
|
||||||
|
this.tinting = tinting;
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
package mage.client.game;
|
||||||
|
|
||||||
|
import mage.client.components.KeyboundButton;
|
||||||
|
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class FirstButtonMousePressedAction extends MouseAdapter {
|
||||||
|
|
||||||
|
private final Consumer<MouseEvent> callback;
|
||||||
|
private boolean pressed = false;
|
||||||
|
private boolean inside = false;
|
||||||
|
|
||||||
|
public FirstButtonMousePressedAction(Consumer<MouseEvent> callback) {
|
||||||
|
this.callback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
pressed = true;
|
||||||
|
if (e.getSource() instanceof KeyboundButton) {
|
||||||
|
KeyboundButton button = (KeyboundButton) e.getSource();
|
||||||
|
button.setTint(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent e) {
|
||||||
|
pressed = false;
|
||||||
|
if (e.getSource() instanceof KeyboundButton) {
|
||||||
|
KeyboundButton button = (KeyboundButton) e.getSource();
|
||||||
|
button.setTint(false);
|
||||||
|
}
|
||||||
|
if (e.getButton() == MouseEvent.BUTTON1 && inside) {
|
||||||
|
callback.accept(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent e) {
|
||||||
|
inside = true;
|
||||||
|
if (pressed && e.getSource() instanceof KeyboundButton) {
|
||||||
|
KeyboundButton button = (KeyboundButton) e.getSource();
|
||||||
|
button.setTint(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent e) {
|
||||||
|
inside = false;
|
||||||
|
if (e.getSource() instanceof KeyboundButton) {
|
||||||
|
KeyboundButton button = (KeyboundButton) e.getSource();
|
||||||
|
button.setTint(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1464,14 +1464,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
btnToggleMacro.setToolTipText("Toggle Record Macro ("
|
btnToggleMacro.setToolTipText("Toggle Record Macro ("
|
||||||
+ getCachedKeyText(KEY_CONTROL_TOGGLE_MACRO) + ").");
|
+ getCachedKeyText(KEY_CONTROL_TOGGLE_MACRO) + ").");
|
||||||
btnToggleMacro.setFocusable(false);
|
btnToggleMacro.setFocusable(false);
|
||||||
btnToggleMacro.addMouseListener(new MouseAdapter() {
|
btnToggleMacro.addMouseListener(new FirstButtonMousePressedAction(e ->
|
||||||
@Override
|
btnToggleMacroActionPerformed(null)));
|
||||||
public void mouseClicked(MouseEvent evt) {
|
|
||||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
|
||||||
btnToggleMacroActionPerformed(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
KeyStroke kst = getCachedKeystroke(KEY_CONTROL_TOGGLE_MACRO);
|
KeyStroke kst = getCachedKeystroke(KEY_CONTROL_TOGGLE_MACRO);
|
||||||
this.getInputMap(c).put(kst, "F8_PRESS");
|
this.getInputMap(c).put(kst, "F8_PRESS");
|
||||||
|
@ -1497,14 +1491,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
btnCancelSkip.setToolTipText("Cancel all skip actions ("
|
btnCancelSkip.setToolTipText("Cancel all skip actions ("
|
||||||
+ getCachedKeyText(KEY_CONTROL_CANCEL_SKIP) + ").");
|
+ getCachedKeyText(KEY_CONTROL_CANCEL_SKIP) + ").");
|
||||||
btnCancelSkip.setFocusable(false);
|
btnCancelSkip.setFocusable(false);
|
||||||
btnCancelSkip.addMouseListener(new MouseAdapter() {
|
btnCancelSkip.addMouseListener(new FirstButtonMousePressedAction(e ->
|
||||||
@Override
|
restorePriorityActionPerformed(null)));
|
||||||
public void mouseClicked(MouseEvent evt) {
|
|
||||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
|
||||||
restorePriorityActionPerformed(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
btnSkipToNextTurn.setContentAreaFilled(false);
|
btnSkipToNextTurn.setContentAreaFilled(false);
|
||||||
btnSkipToNextTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE));
|
btnSkipToNextTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE));
|
||||||
|
@ -1512,14 +1500,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
btnSkipToNextTurn.setToolTipText("Skip to next turn ("
|
btnSkipToNextTurn.setToolTipText("Skip to next turn ("
|
||||||
+ getCachedKeyText(KEY_CONTROL_NEXT_TURN) + ").");
|
+ getCachedKeyText(KEY_CONTROL_NEXT_TURN) + ").");
|
||||||
btnSkipToNextTurn.setFocusable(false);
|
btnSkipToNextTurn.setFocusable(false);
|
||||||
btnSkipToNextTurn.addMouseListener(new MouseAdapter() {
|
btnSkipToNextTurn.addMouseListener(new FirstButtonMousePressedAction(e ->
|
||||||
@Override
|
btnEndTurnActionPerformed(null)));
|
||||||
public void mouseClicked(MouseEvent evt) {
|
|
||||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
|
||||||
btnEndTurnActionPerformed(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
KeyStroke ks = getCachedKeystroke(KEY_CONTROL_NEXT_TURN);
|
KeyStroke ks = getCachedKeystroke(KEY_CONTROL_NEXT_TURN);
|
||||||
this.getInputMap(c).put(ks, "F4_PRESS");
|
this.getInputMap(c).put(ks, "F4_PRESS");
|
||||||
|
@ -1536,14 +1518,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
btnSkipToEndTurn.setToolTipText("Skip to (opponents/next) end of turn step ("
|
btnSkipToEndTurn.setToolTipText("Skip to (opponents/next) end of turn step ("
|
||||||
+ getCachedKeyText(KEY_CONTROL_END_STEP) + ") - adjust using preferences.");
|
+ getCachedKeyText(KEY_CONTROL_END_STEP) + ") - adjust using preferences.");
|
||||||
btnSkipToEndTurn.setFocusable(false);
|
btnSkipToEndTurn.setFocusable(false);
|
||||||
btnSkipToEndTurn.addMouseListener(new MouseAdapter() {
|
btnSkipToEndTurn.addMouseListener(new FirstButtonMousePressedAction(e ->
|
||||||
@Override
|
btnUntilEndOfTurnActionPerformed(null)));
|
||||||
public void mouseClicked(MouseEvent evt) {
|
|
||||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
|
||||||
btnUntilEndOfTurnActionPerformed(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ks = getCachedKeystroke(KEY_CONTROL_END_STEP);
|
ks = getCachedKeystroke(KEY_CONTROL_END_STEP);
|
||||||
this.getInputMap(c).put(ks, "F5_PRESS");
|
this.getInputMap(c).put(ks, "F5_PRESS");
|
||||||
|
@ -1569,14 +1545,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
btnSkipToNextMain.setToolTipText("Skip to (your) next main phase ("
|
btnSkipToNextMain.setToolTipText("Skip to (your) next main phase ("
|
||||||
+ getCachedKeyText(KEY_CONTROL_MAIN_STEP) + ") - adjust using preferences.");
|
+ getCachedKeyText(KEY_CONTROL_MAIN_STEP) + ") - adjust using preferences.");
|
||||||
btnSkipToNextMain.setFocusable(false);
|
btnSkipToNextMain.setFocusable(false);
|
||||||
btnSkipToNextMain.addMouseListener(new MouseAdapter() {
|
btnSkipToNextMain.addMouseListener(new FirstButtonMousePressedAction(e ->
|
||||||
@Override
|
btnUntilNextMainPhaseActionPerformed(null)));
|
||||||
public void mouseClicked(MouseEvent evt) {
|
|
||||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
|
||||||
btnUntilNextMainPhaseActionPerformed(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ks = getCachedKeystroke(KEY_CONTROL_MAIN_STEP);
|
ks = getCachedKeystroke(KEY_CONTROL_MAIN_STEP);
|
||||||
this.getInputMap(c).put(ks, "F7_PRESS");
|
this.getInputMap(c).put(ks, "F7_PRESS");
|
||||||
|
@ -1593,14 +1563,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
btnSkipToYourTurn.setToolTipText("Skip to your next turn ("
|
btnSkipToYourTurn.setToolTipText("Skip to your next turn ("
|
||||||
+ getCachedKeyText(KEY_CONTROL_YOUR_TURN) + ").");
|
+ getCachedKeyText(KEY_CONTROL_YOUR_TURN) + ").");
|
||||||
btnSkipToYourTurn.setFocusable(false);
|
btnSkipToYourTurn.setFocusable(false);
|
||||||
btnSkipToYourTurn.addMouseListener(new MouseAdapter() {
|
btnSkipToYourTurn.addMouseListener(new FirstButtonMousePressedAction(e ->
|
||||||
@Override
|
btnPassPriorityUntilNextYourTurnActionPerformed(null)));
|
||||||
public void mouseClicked(MouseEvent evt) {
|
|
||||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
|
||||||
btnPassPriorityUntilNextYourTurnActionPerformed(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
KeyStroke ks9 = getCachedKeystroke(KEY_CONTROL_YOUR_TURN);
|
KeyStroke ks9 = getCachedKeystroke(KEY_CONTROL_YOUR_TURN);
|
||||||
this.getInputMap(c).put(ks9, "F9_PRESS");
|
this.getInputMap(c).put(ks9, "F9_PRESS");
|
||||||
|
@ -1617,14 +1581,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
btnSkipToEndStepBeforeYourTurn.setToolTipText("Skip to the end step before your turn ("
|
btnSkipToEndStepBeforeYourTurn.setToolTipText("Skip to the end step before your turn ("
|
||||||
+ getCachedKeyText(KEY_CONTROL_PRIOR_END) + ") - adjust using preferences.");
|
+ getCachedKeyText(KEY_CONTROL_PRIOR_END) + ") - adjust using preferences.");
|
||||||
btnSkipToEndStepBeforeYourTurn.setFocusable(false);
|
btnSkipToEndStepBeforeYourTurn.setFocusable(false);
|
||||||
btnSkipToEndStepBeforeYourTurn.addMouseListener(new MouseAdapter() {
|
btnSkipToEndStepBeforeYourTurn.addMouseListener(new FirstButtonMousePressedAction(e ->
|
||||||
@Override
|
btnSkipToEndStepBeforeYourTurnActionPerformed(null)));
|
||||||
public void mouseClicked(MouseEvent evt) {
|
|
||||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
|
||||||
btnSkipToEndStepBeforeYourTurnActionPerformed(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
KeyStroke ks11 = getCachedKeystroke(KEY_CONTROL_PRIOR_END);
|
KeyStroke ks11 = getCachedKeystroke(KEY_CONTROL_PRIOR_END);
|
||||||
this.getInputMap(c).put(ks11, "F11_PRESS");
|
this.getInputMap(c).put(ks11, "F11_PRESS");
|
||||||
|
@ -1641,14 +1599,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
btnSkipStack.setToolTipText("Skip until stack is resolved ("
|
btnSkipStack.setToolTipText("Skip until stack is resolved ("
|
||||||
+ getCachedKeyText(KEY_CONTROL_SKIP_STACK) + ").");
|
+ getCachedKeyText(KEY_CONTROL_SKIP_STACK) + ").");
|
||||||
btnSkipStack.setFocusable(false);
|
btnSkipStack.setFocusable(false);
|
||||||
btnSkipStack.addMouseListener(new MouseAdapter() {
|
btnSkipStack.addMouseListener(new FirstButtonMousePressedAction(e ->
|
||||||
@Override
|
btnPassPriorityUntilStackResolvedActionPerformed(null)));
|
||||||
public void mouseClicked(MouseEvent evt) {
|
|
||||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
|
||||||
btnPassPriorityUntilStackResolvedActionPerformed(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ks = getCachedKeystroke(KEY_CONTROL_SKIP_STACK);
|
ks = getCachedKeystroke(KEY_CONTROL_SKIP_STACK);
|
||||||
this.getInputMap(c).put(ks, "F10_PRESS");
|
this.getInputMap(c).put(ks, "F10_PRESS");
|
||||||
|
@ -1664,14 +1616,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
btnConcede.setIcon(new ImageIcon(ImageManagerImpl.instance.getConcedeButtonImage()));
|
btnConcede.setIcon(new ImageIcon(ImageManagerImpl.instance.getConcedeButtonImage()));
|
||||||
btnConcede.setToolTipText("Concede the current game.");
|
btnConcede.setToolTipText("Concede the current game.");
|
||||||
btnConcede.setFocusable(false);
|
btnConcede.setFocusable(false);
|
||||||
btnConcede.addMouseListener(new MouseAdapter() {
|
btnConcede.addMouseListener(new FirstButtonMousePressedAction(e ->
|
||||||
@Override
|
btnConcedeActionPerformed(null)));
|
||||||
public void mouseClicked(MouseEvent evt) {
|
|
||||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
|
||||||
btnConcedeActionPerformed(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
KeyStroke ks2 = getCachedKeystroke(KEY_CONTROL_CONFIRM);
|
KeyStroke ks2 = getCachedKeystroke(KEY_CONTROL_CONFIRM);
|
||||||
this.getInputMap(c).put(ks2, "F2_PRESS");
|
this.getInputMap(c).put(ks2, "F2_PRESS");
|
||||||
|
@ -1772,28 +1718,16 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
btnSwitchHands.setIcon(new ImageIcon(ImageManagerImpl.instance.getSwitchHandsButtonImage()));
|
btnSwitchHands.setIcon(new ImageIcon(ImageManagerImpl.instance.getSwitchHandsButtonImage()));
|
||||||
btnSwitchHands.setFocusable(false);
|
btnSwitchHands.setFocusable(false);
|
||||||
btnSwitchHands.setToolTipText("Switch between your hand cards and hand cards of controlled players.");
|
btnSwitchHands.setToolTipText("Switch between your hand cards and hand cards of controlled players.");
|
||||||
btnSwitchHands.addMouseListener(new MouseAdapter() {
|
btnSwitchHands.addMouseListener(new FirstButtonMousePressedAction(e ->
|
||||||
@Override
|
btnSwitchHandActionPerformed(null)));
|
||||||
public void mouseClicked(MouseEvent evt) {
|
|
||||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
|
||||||
btnSwitchHandActionPerformed(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
btnStopWatching.setContentAreaFilled(false);
|
btnStopWatching.setContentAreaFilled(false);
|
||||||
btnStopWatching.setBorder(new EmptyBorder(0, 0, 0, 0));
|
btnStopWatching.setBorder(new EmptyBorder(0, 0, 0, 0));
|
||||||
btnStopWatching.setIcon(new ImageIcon(ImageManagerImpl.instance.getStopWatchButtonImage()));
|
btnStopWatching.setIcon(new ImageIcon(ImageManagerImpl.instance.getStopWatchButtonImage()));
|
||||||
btnStopWatching.setFocusable(false);
|
btnStopWatching.setFocusable(false);
|
||||||
btnStopWatching.setToolTipText("Stop watching this game.");
|
btnStopWatching.setToolTipText("Stop watching this game.");
|
||||||
btnStopWatching.addMouseListener(new MouseAdapter() {
|
btnStopWatching.addMouseListener(new FirstButtonMousePressedAction(e ->
|
||||||
@Override
|
btnStopWatchingActionPerformed(null)));
|
||||||
public void mouseClicked(MouseEvent evt) {
|
|
||||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
|
||||||
btnStopWatchingActionPerformed(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
stackObjects.setBackgroundColor(new Color(0, 0, 0, 40));
|
stackObjects.setBackgroundColor(new Color(0, 0, 0, 40));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue