mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-17 08:55:05 -04:00
Fixed an issue with new focus gaining, see #308
This commit is contained in:
parent
626d85f5d0
commit
a80906518c
@ -1276,6 +1276,25 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
stateManager.setActualState(stoppedState);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return returns true if one of the children has the focus.
|
||||
*/
|
||||
public boolean hasMouseFocus() {
|
||||
return checkFocus(getContentPane());
|
||||
}
|
||||
|
||||
private static boolean checkFocus(Container contentPane) {
|
||||
for (int i = 0; i < contentPane.getComponentCount(); i++) {
|
||||
Component c = contentPane.getComponent(i);
|
||||
if (c.hasFocus())
|
||||
return true;
|
||||
if (c instanceof Container)
|
||||
if (checkFocus((Container) c))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private class RunModelState extends State {
|
||||
@Override
|
||||
public void enter() {
|
||||
|
@ -1335,7 +1335,7 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
hadFocusAtClick = SwingUtilities.getWindowAncestor(CircuitComponent.this).isFocused();
|
||||
hadFocusAtClick = hasFocus() || parent.hasMouseFocus();
|
||||
pos = new Vector(e.getX(), e.getY());
|
||||
isMoved = false;
|
||||
requestFocusInWindow();
|
||||
|
Loading…
x
Reference in New Issue
Block a user