mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
- Forge defocusing solution: part 2 [code contribution by nefigah]. Fixes defocusing on window pop-ups such as Goblin Guide.
This commit is contained in:
@@ -23,6 +23,10 @@ import java.awt.event.ActionListener;
|
|||||||
import java.awt.event.FocusAdapter;
|
import java.awt.event.FocusAdapter;
|
||||||
import java.awt.event.FocusEvent;
|
import java.awt.event.FocusEvent;
|
||||||
import java.awt.event.FocusListener;
|
import java.awt.event.FocusListener;
|
||||||
|
import java.awt.event.WindowAdapter;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.awt.Window;
|
||||||
|
import java.awt.Dialog;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
|
|
||||||
@@ -72,12 +76,30 @@ public class CPrompt implements ICDoc {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private final WindowAdapter focusOKButtonOnDialogClose = new WindowAdapter() {
|
||||||
|
@Override
|
||||||
|
public void windowClosed(WindowEvent evt) {
|
||||||
|
view.getBtnOK().requestFocusInWindow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private final PropertyChangeListener focusOnEnable = new PropertyChangeListener() {
|
private final PropertyChangeListener focusOnEnable = new PropertyChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void propertyChange(PropertyChangeEvent evt) {
|
public void propertyChange(PropertyChangeEvent evt) {
|
||||||
boolean isEnabled = (Boolean) evt.getNewValue();
|
if (lastFocusedButton == null || lastFocusedButton == view.getBtnOK()) {
|
||||||
if (isEnabled && (lastFocusedButton == null || lastFocusedButton == view.getBtnOK())) {
|
// Attempt to resolve sporadic button focus issues when dialogs are shown.
|
||||||
view.getBtnOK().requestFocusInWindow();
|
Dialog activeDialog = getActiveDialog(true);
|
||||||
|
if (activeDialog != null) {
|
||||||
|
// If this dialog already has our listener, remove it
|
||||||
|
activeDialog.removeWindowListener(focusOKButtonOnDialogClose);
|
||||||
|
activeDialog.addWindowListener(focusOKButtonOnDialogClose);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Focus the OK button when it becomes enabled
|
||||||
|
boolean isEnabled = (Boolean) evt.getNewValue();
|
||||||
|
if (isEnabled) {
|
||||||
|
view.getBtnOK().requestFocusInWindow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -110,6 +132,19 @@ public class CPrompt implements ICDoc {
|
|||||||
_initButton(view.getBtnOK(), actOK);
|
_initButton(view.getBtnOK(), actOK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Dialog getActiveDialog(boolean modalOnly)
|
||||||
|
{
|
||||||
|
Window[] windows = Window.getWindows();
|
||||||
|
if (windows != null) {
|
||||||
|
for (Window w : windows) {
|
||||||
|
if (w.isShowing() && w instanceof Dialog && (!modalOnly || ((Dialog)w).isModal())) {
|
||||||
|
return (Dialog)w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private void selectButtonOk() {
|
private void selectButtonOk() {
|
||||||
matchUI.getGameController().selectButtonOk();
|
matchUI.getGameController().selectButtonOk();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user