mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
restore focus to ok/cancel button when the Prompt panel is hidden and then reshown
This commit is contained in:
@@ -17,8 +17,14 @@
|
|||||||
*/
|
*/
|
||||||
package forge.gui.match.controllers;
|
package forge.gui.match.controllers;
|
||||||
|
|
||||||
|
import java.awt.Component;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.FocusAdapter;
|
||||||
|
import java.awt.event.FocusEvent;
|
||||||
|
import java.awt.event.FocusListener;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
|
||||||
import forge.Command;
|
import forge.Command;
|
||||||
import forge.game.MatchController;
|
import forge.game.MatchController;
|
||||||
@@ -37,13 +43,14 @@ public enum CMessage implements ICDoc {
|
|||||||
SINGLETON_INSTANCE;
|
SINGLETON_INSTANCE;
|
||||||
|
|
||||||
private GuiInput inputControl = new GuiInput();
|
private GuiInput inputControl = new GuiInput();
|
||||||
|
private Component lastFocusedButton = null;
|
||||||
|
|
||||||
private final ActionListener actCancel = new ActionListener() {
|
private final ActionListener actCancel = new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(final ActionEvent evt) {
|
public void actionPerformed(final ActionEvent evt) {
|
||||||
inputControl.selectButtonCancel();
|
inputControl.selectButtonCancel();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final ActionListener actOK = new ActionListener() {
|
private final ActionListener actOK = new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(final ActionEvent evt) {
|
public void actionPerformed(final ActionEvent evt) {
|
||||||
@@ -51,13 +58,28 @@ public enum CMessage implements ICDoc {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private final FocusListener onFocus = new FocusAdapter() {
|
||||||
|
@Override
|
||||||
|
public void focusGained(FocusEvent e) {
|
||||||
|
if (null != VMessage.SINGLETON_INSTANCE.getParentCell() && VMessage.SINGLETON_INSTANCE == VMessage.SINGLETON_INSTANCE.getParentCell().getSelected()) {
|
||||||
|
// only record focus changes when we're showing -- otherwise it is due to a tab visibility change
|
||||||
|
lastFocusedButton = e.getComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private void _initButton(JButton button, ActionListener onClick) {
|
||||||
|
// remove to ensure listeners don't accumulate over many initializations
|
||||||
|
button.removeActionListener(onClick);
|
||||||
|
button.addActionListener(onClick);
|
||||||
|
button.removeFocusListener(onFocus);
|
||||||
|
button.addFocusListener(onFocus);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
VMessage.SINGLETON_INSTANCE.getBtnCancel().removeActionListener(actCancel);
|
_initButton(VMessage.SINGLETON_INSTANCE.getBtnCancel(), actCancel);
|
||||||
VMessage.SINGLETON_INSTANCE.getBtnCancel().addActionListener(actCancel);
|
_initButton(VMessage.SINGLETON_INSTANCE.getBtnOK(), actOK);
|
||||||
|
|
||||||
VMessage.SINGLETON_INSTANCE.getBtnOK().removeActionListener(actOK);
|
|
||||||
VMessage.SINGLETON_INSTANCE.getBtnOK().addActionListener(actOK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -103,6 +125,9 @@ public enum CMessage implements ICDoc {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
|
// set focus back to button that last had it
|
||||||
|
if (null != lastFocusedButton) {
|
||||||
|
lastFocusedButton.requestFocusInWindow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user