mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-22 11:55:15 -04:00
removes focus moving, see #756
This commit is contained in:
parent
467064ffa1
commit
674ba18adb
@ -35,7 +35,7 @@ public class GraphicDialog extends JDialog {
|
||||
setLocationRelativeTo(null);
|
||||
setVisible(true);
|
||||
|
||||
addWindowFocusListener(new MoveFocusTo(parent));
|
||||
MoveFocusTo.addListener(this, parent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,7 +37,7 @@ public class LedMatrixDialog extends JDialog {
|
||||
setLocationRelativeTo(null);
|
||||
setVisible(true);
|
||||
|
||||
addWindowFocusListener(new MoveFocusTo(parent));
|
||||
MoveFocusTo.addListener(this, parent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,21 +19,33 @@ import java.awt.event.WindowFocusListener;
|
||||
* no longer be used.
|
||||
*/
|
||||
public class MoveFocusTo implements WindowFocusListener {
|
||||
private final Window parent;
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
* Adds the listener to the given child dialog and moves the focus to the given parent
|
||||
*
|
||||
* @param parent the window which should keep the focus
|
||||
* @param child the child dialog
|
||||
* @param parent the parent window
|
||||
*/
|
||||
public MoveFocusTo(Window parent) {
|
||||
public static void addListener(Dialog child, Window parent) {
|
||||
child.setAlwaysOnTop(true);
|
||||
child.addWindowFocusListener(new MoveFocusTo(child, parent));
|
||||
}
|
||||
|
||||
private final Window child;
|
||||
private final Window parent;
|
||||
|
||||
private MoveFocusTo(Window child, Window parent) {
|
||||
this.child = child;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowGainedFocus(WindowEvent windowEvent) {
|
||||
if (parent != null)
|
||||
SwingUtilities.invokeLater(parent::requestFocus);
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
child.removeWindowFocusListener(this);
|
||||
parent.requestFocus();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -33,7 +33,7 @@ public class VGADialog extends JDialog {
|
||||
setLocationRelativeTo(null);
|
||||
setVisible(true);
|
||||
|
||||
addWindowFocusListener(new MoveFocusTo(parent));
|
||||
MoveFocusTo.addListener(this, parent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user