Skip to content

Commit 499e353

Browse files
committed
Use WindowListener instead than FocusListener to spawn watcher
This ensures that watcher is inactive when children views are focused Solves #6827
1 parent c96cdd7 commit 499e353

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<>();
@@ -363,22 +371,6 @@ public Base getBase() {
363371
return base;
364372
}
365373

366-
@Override
367-
public void focusGained(FocusEvent fe){
368-
if (watcher != null) {
369-
watcher.interrupt();
370-
watcher = null;
371-
}
372-
}
373-
374-
@Override
375-
public void focusLost(FocusEvent fe){
376-
if (watcher == null) {
377-
watcher = new Thread(task);
378-
watcher.start();
379-
}
380-
}
381-
382374
/**
383375
* Handles files dragged & dropped from the desktop and into the editor
384376
* window. Dragging files into the editor window is the same as using
@@ -2016,10 +2008,6 @@ public void run() {
20162008
}
20172009
};
20182010

2019-
addFocusListener(this);
2020-
getTabs().forEach(tab -> tab.getScrollPane().addFocusListener(this));
2021-
getTabs().forEach(tab -> tab.getTextArea().addFocusListener(this));
2022-
20232011
// opening was successful
20242012
return true;
20252013
}

0 commit comments

Comments
 (0)