Skip to content

Commit d5b2ddf

Browse files
facchinmcmaglie
authored andcommitted
Use WindowListener instead than FocusListener to spawn watcher
This ensures that watcher is inactive when children views are focused Solves #6827
1 parent f278786 commit d5b2ddf

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

Diff for: app/src/processing/app/Editor.java

+9-21
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
* Main editor panel for the Processing Development Environment.
8787
*/
8888
@SuppressWarnings("serial")
89-
public class Editor extends JFrame implements RunnerListener, FocusListener {
89+
public class Editor extends JFrame implements RunnerListener {
9090

9191
public static final int MAX_TIME_AWAITING_FOR_RESUMING_SERIAL_MONITOR = 10000;
9292

@@ -237,12 +237,20 @@ public void windowClosing(WindowEvent e) {
237237
// When bringing a window to front, let the Base know
238238
addWindowListener(new WindowAdapter() {
239239
public void windowActivated(WindowEvent e) {
240+
if (watcher != null) {
241+
watcher.interrupt();
242+
watcher = null;
243+
}
240244
base.handleActivated(Editor.this);
241245
}
242246

243247
// added for 1.0.5
244248
// http://dev.processing.org/bugs/show_bug.cgi?id=1260
245249
public void windowDeactivated(WindowEvent e) {
250+
if (watcher == null) {
251+
watcher = new Thread(task);
252+
watcher.start();
253+
}
246254
fileMenu.remove(sketchbookMenu);
247255
fileMenu.remove(examplesMenu);
248256
List<Component> toolsMenuItemsToRemove = new LinkedList<>();
@@ -359,22 +367,6 @@ public void windowDeactivated(WindowEvent e) {
359367
EditorConsole.setCurrentEditorConsole(console);
360368
}
361369

362-
@Override
363-
public void focusGained(FocusEvent fe){
364-
if (watcher != null) {
365-
watcher.interrupt();
366-
watcher = null;
367-
}
368-
}
369-
370-
@Override
371-
public void focusLost(FocusEvent fe){
372-
if (watcher == null) {
373-
watcher = new Thread(task);
374-
watcher.start();
375-
}
376-
}
377-
378370
/**
379371
* Handles files dragged & dropped from the desktop and into the editor
380372
* window. Dragging files into the editor window is the same as using
@@ -2012,10 +2004,6 @@ public void run() {
20122004
}
20132005
};
20142006

2015-
addFocusListener(this);
2016-
getTabs().forEach(tab -> tab.getScrollPane().addFocusListener(this));
2017-
getTabs().forEach(tab -> tab.getTextArea().addFocusListener(this));
2018-
20192007
// opening was successful
20202008
return true;
20212009
}

0 commit comments

Comments
 (0)