38 |
|
|
39 |
package java.awt; |
package java.awt; |
40 |
|
|
|
import gnu.java.awt.ClasspathToolkit; |
|
|
|
|
41 |
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
42 |
import java.awt.event.InputEvent; |
import java.awt.event.InputEvent; |
43 |
import java.awt.event.InputMethodEvent; |
import java.awt.event.InputMethodEvent; |
76 |
private EventDispatchThread dispatchThread = new EventDispatchThread(this); |
private EventDispatchThread dispatchThread = new EventDispatchThread(this); |
77 |
private boolean shutdown = false; |
private boolean shutdown = false; |
78 |
|
|
79 |
private long lastNativeQueueAccess = 0; |
synchronized private void setShutdown (boolean b) |
|
private long humanLatencyThreshold = 100; |
|
|
|
|
|
synchronized void setShutdown (boolean b) |
|
80 |
{ |
{ |
81 |
shutdown = b; |
shutdown = b; |
82 |
} |
} |
89 |
// This is the exact self-shutdown condition specified in J2SE: |
// This is the exact self-shutdown condition specified in J2SE: |
90 |
// http://java.sun.com/j2se/1.4.2/docs/api/java/awt/doc-files/AWTThreadIssues.html |
// http://java.sun.com/j2se/1.4.2/docs/api/java/awt/doc-files/AWTThreadIssues.html |
91 |
|
|
92 |
if (peekEvent() == null |
// FIXME: check somewhere that the native queue is empty |
93 |
&& ((ClasspathToolkit) Toolkit.getDefaultToolkit()).nativeQueueEmpty()) |
if (peekEvent() == null) |
94 |
{ |
{ |
95 |
Frame[] frames = Frame.getFrames(); |
Frame[] frames = Frame.getFrames(); |
96 |
for (int i = 0; i < frames.length; ++i) |
for (int i = 0; i < frames.length; ++i) |
122 |
{ |
{ |
123 |
if (next != null) |
if (next != null) |
124 |
return next.getNextEvent(); |
return next.getNextEvent(); |
|
|
|
|
ClasspathToolkit tk = ((ClasspathToolkit) Toolkit.getDefaultToolkit()); |
|
|
long curr = System.currentTimeMillis(); |
|
|
|
|
|
if (! tk.nativeQueueEmpty() && |
|
|
(curr - lastNativeQueueAccess > humanLatencyThreshold)) |
|
|
{ |
|
|
tk.iterateNativeQueue(this, false); |
|
|
lastNativeQueueAccess = curr; |
|
|
} |
|
125 |
|
|
126 |
while (next_in == next_out) |
while (next_in == next_out) |
127 |
{ |
{ |
128 |
// Only the EventDispatchThread associated with the top of the stack is |
// We are not allowed to return null from this method, yet it |
129 |
// allowed to get events from the native source; everyone else just |
// is possible that we actually have run out of native events |
130 |
// waits on the head of the queue. |
// in the enclosing while() loop, and none of the native events |
131 |
|
// happened to cause AWT events. We therefore ought to check |
132 |
if (isDispatchThread()) |
// the isShutdown() condition here, before risking a "native |
133 |
{ |
// wait". If we check it before entering this function we may |
134 |
// We are not allowed to return null from this method, yet it |
// wait forever for events after the shutdown condition has |
135 |
// is possible that we actually have run out of native events |
// arisen. |
|
// in the enclosing while() loop, and none of the native events |
|
|
// happened to cause AWT events. We therefore ought to check |
|
|
// the isShutdown() condition here, before risking a "native |
|
|
// wait". If we check it before entering this function we may |
|
|
// wait forever for events after the shutdown condition has |
|
|
// arisen. |
|
136 |
|
|
137 |
if (isShutdown()) |
if (isShutdown()) |
138 |
throw new InterruptedException(); |
throw new InterruptedException(); |
139 |
|
|
140 |
tk.iterateNativeQueue(this, true); |
wait(); |
|
lastNativeQueueAccess = System.currentTimeMillis(); |
|
|
} |
|
|
else |
|
|
{ |
|
|
try |
|
|
{ |
|
|
wait(); |
|
|
} |
|
|
catch (InterruptedException ie) |
|
|
{ |
|
|
} |
|
|
} |
|
141 |
} |
} |
142 |
|
|
143 |
AWTEvent res = queue[next_out]; |
AWTEvent res = queue[next_out]; |
265 |
dispatchThread.start(); |
dispatchThread.start(); |
266 |
} |
} |
267 |
|
|
|
// Window events might represent the closing of a window, which |
|
|
// might cause the end of the dispatch thread's life, so we'll wake |
|
|
// it up here to give it a chance to check for shutdown. |
|
|
|
|
|
if (!isDispatchThread() |
|
|
|| (evt.getID() == WindowEvent.WINDOW_CLOSED) |
|
|
|| (evt.getID() == WindowEvent.WINDOW_CLOSING)) |
|
|
((ClasspathToolkit) Toolkit.getDefaultToolkit()).wakeNativeQueue(); |
|
|
|
|
268 |
notify(); |
notify(); |
269 |
} |
} |
270 |
|
|
436 |
next_in = 0; |
next_in = 0; |
437 |
next_out = 0; |
next_out = 0; |
438 |
|
|
|
((ClasspathToolkit) Toolkit.getDefaultToolkit()).wakeNativeQueue(); |
|
439 |
setShutdown(true); |
setShutdown(true); |
440 |
dispatchThread = null; |
dispatchThread = null; |
441 |
this.notifyAll(); |
this.notifyAll(); |