summaryrefslogtreecommitdiff
path: root/devel/charva/files/patch-java_src_charva_awt_Window.java
blob: 41f18aa85c091733362d9f56cc7fe0052cc40492 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
--- java/src/charva/awt/Window.java.orig	Mon Aug 14 17:38:56 2006
+++ java/src/charva/awt/Window.java	Mon Jan 29 09:39:30 2007
@@ -156,13 +156,21 @@ public class Window
          */
         SyncQueue.getInstance().postEvent(new SyncEvent(this));
 
-        if (_dispatchThreadRunning)
-            run();
-        else {
-            _dispatchThreadRunning = true;
-            Thread dispatchThread = new Thread(this);
-            dispatchThread.setName("event dispatcher");
-            dispatchThread.start();
+        if (_dispatchThread != null) {
+            if (Thread.currentThread() == _dispatchThread) {
+        	// we are in the EDT, we must manage events
+        	run();
+            } else {
+        	// we are not the EDT, let's wait for him to ask us to close
+                synchronized (this) {
+                    while (!_windowClosed)
+                        try { wait(); } catch (InterruptedException e) { }
+                }
+            }
+        } else {
+            _dispatchThread = new Thread(this);
+            _dispatchThread.setName("event dispatcher");
+            _dispatchThread.start();
 
             /* If "charva.script.playback" is defined, we start up
              * a thread for playing back the script. Keys from both the
@@ -270,7 +278,10 @@ public class Window
              */
             if (we.getID() == AWTEvent.WINDOW_CLOSING) {
 
-                we.getWindow()._windowClosed = true;
+        	synchronized (we.getWindow()) {
+        	    we.getWindow()._windowClosed = true;
+        	    we.getWindow().notify();
+        	}
 
                 /* Remove this window from the list of those displayed,
                  * and blank out the screen area where the window was
@@ -407,10 +418,10 @@ public class Window
 
     private Window _owner;
     protected Toolkit _term;
-    private boolean _windowClosed = false;
+    private volatile boolean _windowClosed = false;
 
     private Vector _windowListeners = null;
 
-    private static boolean _dispatchThreadRunning = false;
+    private static Thread _dispatchThread = null;
 
 }