Fixed an issue with new focus gaining, see #308

This commit is contained in:
hneemann 2019-08-20 17:01:19 +02:00
parent 626d85f5d0
commit a80906518c
2 changed files with 20 additions and 1 deletions

View File

@ -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() {

View File

@ -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();