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 |
|
|
|
private long lastNativeQueueAccess = 0; |
|
|
private long humanLatencyThreshold = 100; |
|
|
|
|
79 |
synchronized void setShutdown (boolean b) |
synchronized void setShutdown (boolean b) |
80 |
{ |
{ |
81 |
shutdown = b; |
shutdown = b; |
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 |
{ |
{ |
|
// Only the EventDispatchThread associated with the top of the stack is |
|
|
// allowed to get events from the native source; everyone else just |
|
|
// waits on the head of the queue. |
|
|
|
|
128 |
if (isDispatchThread()) |
if (isDispatchThread()) |
129 |
{ |
{ |
130 |
// We are not allowed to return null from this method, yet it |
// We are not allowed to return null from this method, yet it |
139 |
if (isShutdown()) |
if (isShutdown()) |
140 |
throw new InterruptedException(); |
throw new InterruptedException(); |
141 |
|
|
142 |
tk.iterateNativeQueue(this, true); |
wait(); |
143 |
lastNativeQueueAccess = System.currentTimeMillis(); |
} |
|
} |
|
|
else |
|
|
{ |
|
|
try |
|
|
{ |
|
|
wait(); |
|
|
} |
|
|
catch (InterruptedException ie) |
|
|
{ |
|
|
} |
|
|
} |
|
144 |
} |
} |
145 |
|
|
146 |
AWTEvent res = queue[next_out]; |
AWTEvent res = queue[next_out]; |
268 |
dispatchThread.start(); |
dispatchThread.start(); |
269 |
} |
} |
270 |
|
|
|
// 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(); |
|
|
|
|
271 |
notify(); |
notify(); |
272 |
} |
} |
273 |
|
|
439 |
next_in = 0; |
next_in = 0; |
440 |
next_out = 0; |
next_out = 0; |
441 |
|
|
|
((ClasspathToolkit) Toolkit.getDefaultToolkit()).wakeNativeQueue(); |
|
442 |
setShutdown(true); |
setShutdown(true); |
443 |
dispatchThread = null; |
dispatchThread = null; |
444 |
this.notifyAll(); |
this.notifyAll(); |