author | dav |
Mon, 07 Jul 2008 16:09:39 +0400 | |
changeset 1181 | c5971dbeaaaa |
parent 2 | 90ce3da70b43 |
child 1247 | b4c26443dee5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package java.awt; |
|
27 |
||
28 |
import java.awt.event.*; |
|
29 |
||
30 |
import java.awt.peer.ComponentPeer; |
|
31 |
||
32 |
import java.lang.ref.WeakReference; |
|
33 |
import java.lang.reflect.InvocationTargetException; |
|
34 |
||
35 |
import java.security.AccessController; |
|
36 |
import java.security.PrivilegedAction; |
|
37 |
||
38 |
import java.util.EmptyStackException; |
|
39 |
import java.util.logging.*; |
|
40 |
||
41 |
import sun.awt.AppContext; |
|
42 |
import sun.awt.AWTAutoShutdown; |
|
43 |
import sun.awt.PeerEvent; |
|
44 |
import sun.awt.SunToolkit; |
|
1181
c5971dbeaaaa
6693974: Unify EventQueue$EventQueueItem and SunToolkit.$EventQueueItem classes
dav
parents:
2
diff
changeset
|
45 |
import sun.awt.EventQueueItem; |
2 | 46 |
|
47 |
/** |
|
48 |
* <code>EventQueue</code> is a platform-independent class |
|
49 |
* that queues events, both from the underlying peer classes |
|
50 |
* and from trusted application classes. |
|
51 |
* <p> |
|
52 |
* It encapsulates asynchronous event dispatch machinery which |
|
53 |
* extracts events from the queue and dispatches them by calling |
|
54 |
* {@link #dispatchEvent(AWTEvent) dispatchEvent(AWTEvent)} method |
|
55 |
* on this <code>EventQueue</code> with the event to be dispatched |
|
56 |
* as an argument. The particular behavior of this machinery is |
|
57 |
* implementation-dependent. The only requirements are that events |
|
58 |
* which were actually enqueued to this queue (note that events |
|
59 |
* being posted to the <code>EventQueue</code> can be coalesced) |
|
60 |
* are dispatched: |
|
61 |
* <dl> |
|
62 |
* <dt> Sequentially. |
|
63 |
* <dd> That is, it is not permitted that several events from |
|
64 |
* this queue are dispatched simultaneously. |
|
65 |
* <dt> In the same order as they are enqueued. |
|
66 |
* <dd> That is, if <code>AWTEvent</code> A is enqueued |
|
67 |
* to the <code>EventQueue</code> before |
|
68 |
* <code>AWTEvent</code> B then event B will not be |
|
69 |
* dispatched before event A. |
|
70 |
* </dl> |
|
71 |
* <p> |
|
72 |
* Some browsers partition applets in different code bases into |
|
73 |
* separate contexts, and establish walls between these contexts. |
|
74 |
* In such a scenario, there will be one <code>EventQueue</code> |
|
75 |
* per context. Other browsers place all applets into the same |
|
76 |
* context, implying that there will be only a single, global |
|
77 |
* <code>EventQueue</code> for all applets. This behavior is |
|
78 |
* implementation-dependent. Consult your browser's documentation |
|
79 |
* for more information. |
|
80 |
* <p> |
|
81 |
* For information on the threading issues of the event dispatch |
|
82 |
* machinery, see <a href="doc-files/AWTThreadIssues.html#Autoshutdown" |
|
83 |
* >AWT Threading Issues</a>. |
|
84 |
* |
|
85 |
* @author Thomas Ball |
|
86 |
* @author Fred Ecks |
|
87 |
* @author David Mendenhall |
|
88 |
* |
|
89 |
* @since 1.1 |
|
90 |
*/ |
|
91 |
public class EventQueue { |
|
92 |
||
93 |
// From Thread.java |
|
94 |
private static int threadInitNumber; |
|
95 |
private static synchronized int nextThreadNum() { |
|
96 |
return threadInitNumber++; |
|
97 |
} |
|
98 |
||
99 |
private static final int LOW_PRIORITY = 0; |
|
100 |
private static final int NORM_PRIORITY = 1; |
|
101 |
private static final int HIGH_PRIORITY = 2; |
|
102 |
private static final int ULTIMATE_PRIORITY = 3; |
|
103 |
||
104 |
private static final int NUM_PRIORITIES = ULTIMATE_PRIORITY + 1; |
|
105 |
||
106 |
/* |
|
107 |
* We maintain one Queue for each priority that the EventQueue supports. |
|
108 |
* That is, the EventQueue object is actually implemented as |
|
109 |
* NUM_PRIORITIES queues and all Events on a particular internal Queue |
|
110 |
* have identical priority. Events are pulled off the EventQueue starting |
|
111 |
* with the Queue of highest priority. We progress in decreasing order |
|
112 |
* across all Queues. |
|
113 |
*/ |
|
114 |
private Queue[] queues = new Queue[NUM_PRIORITIES]; |
|
115 |
||
116 |
/* |
|
117 |
* The next EventQueue on the stack, or null if this EventQueue is |
|
118 |
* on the top of the stack. If nextQueue is non-null, requests to post |
|
119 |
* an event are forwarded to nextQueue. |
|
120 |
*/ |
|
121 |
private EventQueue nextQueue; |
|
122 |
||
123 |
/* |
|
124 |
* The previous EventQueue on the stack, or null if this is the |
|
125 |
* "base" EventQueue. |
|
126 |
*/ |
|
127 |
private EventQueue previousQueue; |
|
128 |
||
129 |
private EventDispatchThread dispatchThread; |
|
130 |
||
131 |
private final ThreadGroup threadGroup = |
|
132 |
Thread.currentThread().getThreadGroup(); |
|
133 |
private final ClassLoader classLoader = |
|
134 |
Thread.currentThread().getContextClassLoader(); |
|
135 |
||
136 |
/* |
|
137 |
* The time stamp of the last dispatched InputEvent or ActionEvent. |
|
138 |
*/ |
|
139 |
private long mostRecentEventTime = System.currentTimeMillis(); |
|
140 |
||
141 |
/** |
|
142 |
* The modifiers field of the current event, if the current event is an |
|
143 |
* InputEvent or ActionEvent. |
|
144 |
*/ |
|
145 |
private WeakReference currentEvent; |
|
146 |
||
147 |
/* |
|
148 |
* Non-zero if a thread is waiting in getNextEvent(int) for an event of |
|
149 |
* a particular ID to be posted to the queue. |
|
150 |
*/ |
|
151 |
private int waitForID; |
|
152 |
||
153 |
private final String name = "AWT-EventQueue-" + nextThreadNum(); |
|
154 |
||
155 |
private static final Logger eventLog = Logger.getLogger("java.awt.event.EventQueue"); |
|
156 |
||
157 |
public EventQueue() { |
|
158 |
for (int i = 0; i < NUM_PRIORITIES; i++) { |
|
159 |
queues[i] = new Queue(); |
|
160 |
} |
|
161 |
/* |
|
162 |
* NOTE: if you ever have to start the associated event dispatch |
|
163 |
* thread at this point, be aware of the following problem: |
|
164 |
* If this EventQueue instance is created in |
|
165 |
* SunToolkit.createNewAppContext() the started dispatch thread |
|
166 |
* may call AppContext.getAppContext() before createNewAppContext() |
|
167 |
* completes thus causing mess in thread group to appcontext mapping. |
|
168 |
*/ |
|
169 |
} |
|
170 |
||
171 |
/** |
|
172 |
* Posts a 1.1-style event to the <code>EventQueue</code>. |
|
173 |
* If there is an existing event on the queue with the same ID |
|
174 |
* and event source, the source <code>Component</code>'s |
|
175 |
* <code>coalesceEvents</code> method will be called. |
|
176 |
* |
|
177 |
* @param theEvent an instance of <code>java.awt.AWTEvent</code>, |
|
178 |
* or a subclass of it |
|
179 |
* @throws NullPointerException if <code>theEvent</code> is <code>null</code> |
|
180 |
*/ |
|
181 |
public void postEvent(AWTEvent theEvent) { |
|
182 |
SunToolkit.flushPendingEvents(); |
|
183 |
postEventPrivate(theEvent); |
|
184 |
} |
|
185 |
||
186 |
/** |
|
187 |
* Posts a 1.1-style event to the <code>EventQueue</code>. |
|
188 |
* If there is an existing event on the queue with the same ID |
|
189 |
* and event source, the source <code>Component</code>'s |
|
190 |
* <code>coalesceEvents</code> method will be called. |
|
191 |
* |
|
192 |
* @param theEvent an instance of <code>java.awt.AWTEvent</code>, |
|
193 |
* or a subclass of it |
|
194 |
*/ |
|
195 |
final void postEventPrivate(AWTEvent theEvent) { |
|
196 |
theEvent.isPosted = true; |
|
197 |
synchronized(this) { |
|
198 |
if (dispatchThread == null && nextQueue == null) { |
|
199 |
if (theEvent.getSource() == AWTAutoShutdown.getInstance()) { |
|
200 |
return; |
|
201 |
} else { |
|
202 |
initDispatchThread(); |
|
203 |
} |
|
204 |
} |
|
205 |
if (nextQueue != null) { |
|
206 |
// Forward event to top of EventQueue stack. |
|
207 |
nextQueue.postEventPrivate(theEvent); |
|
208 |
return; |
|
209 |
} |
|
210 |
postEvent(theEvent, getPriority(theEvent)); |
|
211 |
} |
|
212 |
} |
|
213 |
||
214 |
private static int getPriority(AWTEvent theEvent) { |
|
215 |
if (theEvent instanceof PeerEvent && |
|
216 |
(((PeerEvent)theEvent).getFlags() & |
|
217 |
PeerEvent.ULTIMATE_PRIORITY_EVENT) != 0) |
|
218 |
{ |
|
219 |
return ULTIMATE_PRIORITY; |
|
220 |
} |
|
221 |
||
222 |
if (theEvent instanceof PeerEvent && |
|
223 |
(((PeerEvent)theEvent).getFlags() & |
|
224 |
PeerEvent.PRIORITY_EVENT) != 0) |
|
225 |
{ |
|
226 |
return HIGH_PRIORITY; |
|
227 |
} |
|
228 |
||
229 |
if (theEvent instanceof PeerEvent && |
|
230 |
(((PeerEvent)theEvent).getFlags() & |
|
231 |
PeerEvent.LOW_PRIORITY_EVENT) != 0) |
|
232 |
{ |
|
233 |
return LOW_PRIORITY; |
|
234 |
} |
|
235 |
||
236 |
int id = theEvent.getID(); |
|
237 |
if (id == PaintEvent.PAINT || id == PaintEvent.UPDATE) { |
|
238 |
return LOW_PRIORITY; |
|
239 |
} |
|
240 |
return NORM_PRIORITY; |
|
241 |
} |
|
242 |
||
243 |
/** |
|
244 |
* Posts the event to the internal Queue of specified priority, |
|
245 |
* coalescing as appropriate. |
|
246 |
* |
|
247 |
* @param theEvent an instance of <code>java.awt.AWTEvent</code>, |
|
248 |
* or a subclass of it |
|
249 |
* @param priority the desired priority of the event |
|
250 |
*/ |
|
251 |
private void postEvent(AWTEvent theEvent, int priority) { |
|
252 |
if (coalesceEvent(theEvent, priority)) { |
|
253 |
return; |
|
254 |
} |
|
255 |
||
256 |
EventQueueItem newItem = new EventQueueItem(theEvent); |
|
257 |
||
258 |
cacheEQItem(newItem); |
|
259 |
||
260 |
boolean notifyID = (theEvent.getID() == this.waitForID); |
|
261 |
||
262 |
if (queues[priority].head == null) { |
|
263 |
boolean shouldNotify = noEvents(); |
|
264 |
queues[priority].head = queues[priority].tail = newItem; |
|
265 |
||
266 |
if (shouldNotify) { |
|
267 |
if (theEvent.getSource() != AWTAutoShutdown.getInstance()) { |
|
268 |
AWTAutoShutdown.getInstance().notifyThreadBusy(dispatchThread); |
|
269 |
} |
|
270 |
notifyAll(); |
|
271 |
} else if (notifyID) { |
|
272 |
notifyAll(); |
|
273 |
} |
|
274 |
} else { |
|
275 |
// The event was not coalesced or has non-Component source. |
|
276 |
// Insert it at the end of the appropriate Queue. |
|
277 |
queues[priority].tail.next = newItem; |
|
278 |
queues[priority].tail = newItem; |
|
279 |
if (notifyID) { |
|
280 |
notifyAll(); |
|
281 |
} |
|
282 |
} |
|
283 |
} |
|
284 |
||
285 |
private boolean coalescePaintEvent(PaintEvent e) { |
|
286 |
ComponentPeer sourcePeer = ((Component)e.getSource()).peer; |
|
287 |
if (sourcePeer != null) { |
|
288 |
sourcePeer.coalescePaintEvent(e); |
|
289 |
} |
|
290 |
EventQueueItem[] cache = ((Component)e.getSource()).eventCache; |
|
291 |
if (cache == null) { |
|
292 |
return false; |
|
293 |
} |
|
294 |
int index = eventToCacheIndex(e); |
|
295 |
||
296 |
if (index != -1 && cache[index] != null) { |
|
297 |
PaintEvent merged = mergePaintEvents(e, (PaintEvent)cache[index].event); |
|
298 |
if (merged != null) { |
|
299 |
cache[index].event = merged; |
|
300 |
return true; |
|
301 |
} |
|
302 |
} |
|
303 |
return false; |
|
304 |
} |
|
305 |
||
306 |
private PaintEvent mergePaintEvents(PaintEvent a, PaintEvent b) { |
|
307 |
Rectangle aRect = a.getUpdateRect(); |
|
308 |
Rectangle bRect = b.getUpdateRect(); |
|
309 |
if (bRect.contains(aRect)) { |
|
310 |
return b; |
|
311 |
} |
|
312 |
if (aRect.contains(bRect)) { |
|
313 |
return a; |
|
314 |
} |
|
315 |
return null; |
|
316 |
} |
|
317 |
||
318 |
private boolean coalesceMouseEvent(MouseEvent e) { |
|
319 |
EventQueueItem[] cache = ((Component)e.getSource()).eventCache; |
|
320 |
if (cache == null) { |
|
321 |
return false; |
|
322 |
} |
|
323 |
int index = eventToCacheIndex(e); |
|
324 |
if (index != -1 && cache[index] != null) { |
|
325 |
cache[index].event = e; |
|
326 |
return true; |
|
327 |
} |
|
328 |
return false; |
|
329 |
} |
|
330 |
||
331 |
private boolean coalescePeerEvent(PeerEvent e) { |
|
332 |
EventQueueItem[] cache = ((Component)e.getSource()).eventCache; |
|
333 |
if (cache == null) { |
|
334 |
return false; |
|
335 |
} |
|
336 |
int index = eventToCacheIndex(e); |
|
337 |
if (index != -1 && cache[index] != null) { |
|
338 |
e = e.coalesceEvents((PeerEvent)cache[index].event); |
|
339 |
if (e != null) { |
|
340 |
cache[index].event = e; |
|
341 |
return true; |
|
342 |
} else { |
|
343 |
cache[index] = null; |
|
344 |
} |
|
345 |
} |
|
346 |
return false; |
|
347 |
} |
|
348 |
||
349 |
/* |
|
350 |
* Should avoid of calling this method by any means |
|
351 |
* as it's working time is dependant on EQ length. |
|
352 |
* In the wors case this method alone can slow down the entire application |
|
353 |
* 10 times by stalling the Event processing. |
|
354 |
* Only here by backward compatibility reasons. |
|
355 |
*/ |
|
356 |
private boolean coalesceOtherEvent(AWTEvent e, int priority) { |
|
357 |
int id = e.getID(); |
|
358 |
Component source = (Component)e.getSource(); |
|
359 |
for (EventQueueItem entry = queues[priority].head; |
|
360 |
entry != null; entry = entry.next) |
|
361 |
{ |
|
362 |
// Give Component.coalesceEvents a chance |
|
1181
c5971dbeaaaa
6693974: Unify EventQueue$EventQueueItem and SunToolkit.$EventQueueItem classes
dav
parents:
2
diff
changeset
|
363 |
if (entry.event.getSource() == source && entry.event.getID() == id) { |
2 | 364 |
AWTEvent coalescedEvent = source.coalesceEvents( |
365 |
entry.event, e); |
|
366 |
if (coalescedEvent != null) { |
|
367 |
entry.event = coalescedEvent; |
|
368 |
return true; |
|
369 |
} |
|
370 |
} |
|
371 |
} |
|
372 |
return false; |
|
373 |
} |
|
374 |
||
375 |
private boolean coalesceEvent(AWTEvent e, int priority) { |
|
376 |
if (!(e.getSource() instanceof Component)) { |
|
377 |
return false; |
|
378 |
} |
|
379 |
if (e instanceof PeerEvent) { |
|
380 |
return coalescePeerEvent((PeerEvent)e); |
|
381 |
} |
|
382 |
// The worst case |
|
383 |
if (((Component)e.getSource()).isCoalescingEnabled() |
|
384 |
&& coalesceOtherEvent(e, priority)) |
|
385 |
{ |
|
386 |
return true; |
|
387 |
} |
|
388 |
if (e instanceof PaintEvent) { |
|
389 |
return coalescePaintEvent((PaintEvent)e); |
|
390 |
} |
|
391 |
if (e instanceof MouseEvent) { |
|
392 |
return coalesceMouseEvent((MouseEvent)e); |
|
393 |
} |
|
394 |
return false; |
|
395 |
} |
|
396 |
||
397 |
private void cacheEQItem(EventQueueItem entry) { |
|
398 |
int index = eventToCacheIndex(entry.event); |
|
399 |
if (index != -1 && entry.event.getSource() instanceof Component) { |
|
400 |
Component source = (Component)entry.event.getSource(); |
|
401 |
if (source.eventCache == null) { |
|
402 |
source.eventCache = new EventQueueItem[CACHE_LENGTH]; |
|
403 |
} |
|
404 |
source.eventCache[index] = entry; |
|
405 |
} |
|
406 |
} |
|
407 |
||
408 |
private void uncacheEQItem(EventQueueItem entry) { |
|
409 |
int index = eventToCacheIndex(entry.event); |
|
410 |
if (index != -1 && entry.event.getSource() instanceof Component) { |
|
411 |
Component source = (Component)entry.event.getSource(); |
|
412 |
if (source.eventCache == null) { |
|
413 |
return; |
|
414 |
} |
|
415 |
source.eventCache[index] = null; |
|
416 |
} |
|
417 |
} |
|
418 |
||
419 |
private static final int PAINT = 0; |
|
420 |
private static final int UPDATE = 1; |
|
421 |
private static final int MOVE = 2; |
|
422 |
private static final int DRAG = 3; |
|
423 |
private static final int PEER = 4; |
|
424 |
private static final int CACHE_LENGTH = 5; |
|
425 |
||
426 |
private static int eventToCacheIndex(AWTEvent e) { |
|
427 |
switch(e.getID()) { |
|
428 |
case PaintEvent.PAINT: |
|
429 |
return PAINT; |
|
430 |
case PaintEvent.UPDATE: |
|
431 |
return UPDATE; |
|
432 |
case MouseEvent.MOUSE_MOVED: |
|
433 |
return MOVE; |
|
434 |
case MouseEvent.MOUSE_DRAGGED: |
|
435 |
return DRAG; |
|
436 |
default: |
|
437 |
return e instanceof PeerEvent ? PEER : -1; |
|
438 |
} |
|
439 |
} |
|
440 |
||
441 |
/** |
|
442 |
* Returns whether an event is pending on any of the separate |
|
443 |
* Queues. |
|
444 |
* @return whether an event is pending on any of the separate Queues |
|
445 |
*/ |
|
446 |
private boolean noEvents() { |
|
447 |
for (int i = 0; i < NUM_PRIORITIES; i++) { |
|
448 |
if (queues[i].head != null) { |
|
449 |
return false; |
|
450 |
} |
|
451 |
} |
|
452 |
||
453 |
return true; |
|
454 |
} |
|
455 |
||
456 |
/** |
|
457 |
* Removes an event from the <code>EventQueue</code> and |
|
458 |
* returns it. This method will block until an event has |
|
459 |
* been posted by another thread. |
|
460 |
* @return the next <code>AWTEvent</code> |
|
461 |
* @exception InterruptedException |
|
462 |
* if any thread has interrupted this thread |
|
463 |
*/ |
|
464 |
public AWTEvent getNextEvent() throws InterruptedException { |
|
465 |
do { |
|
466 |
/* |
|
467 |
* SunToolkit.flushPendingEvents must be called outside |
|
468 |
* of the synchronized block to avoid deadlock when |
|
469 |
* event queues are nested with push()/pop(). |
|
470 |
*/ |
|
471 |
SunToolkit.flushPendingEvents(); |
|
472 |
synchronized (this) { |
|
473 |
for (int i = NUM_PRIORITIES - 1; i >= 0; i--) { |
|
474 |
if (queues[i].head != null) { |
|
475 |
EventQueueItem entry = queues[i].head; |
|
476 |
queues[i].head = entry.next; |
|
477 |
if (entry.next == null) { |
|
478 |
queues[i].tail = null; |
|
479 |
} |
|
480 |
uncacheEQItem(entry); |
|
481 |
return entry.event; |
|
482 |
} |
|
483 |
} |
|
484 |
AWTAutoShutdown.getInstance().notifyThreadFree(dispatchThread); |
|
485 |
wait(); |
|
486 |
} |
|
487 |
} while(true); |
|
488 |
} |
|
489 |
||
490 |
AWTEvent getNextEvent(int id) throws InterruptedException { |
|
491 |
do { |
|
492 |
/* |
|
493 |
* SunToolkit.flushPendingEvents must be called outside |
|
494 |
* of the synchronized block to avoid deadlock when |
|
495 |
* event queues are nested with push()/pop(). |
|
496 |
*/ |
|
497 |
SunToolkit.flushPendingEvents(); |
|
498 |
synchronized (this) { |
|
499 |
for (int i = 0; i < NUM_PRIORITIES; i++) { |
|
500 |
for (EventQueueItem entry = queues[i].head, prev = null; |
|
501 |
entry != null; prev = entry, entry = entry.next) |
|
502 |
{ |
|
1181
c5971dbeaaaa
6693974: Unify EventQueue$EventQueueItem and SunToolkit.$EventQueueItem classes
dav
parents:
2
diff
changeset
|
503 |
if (entry.event.getID() == id) { |
2 | 504 |
if (prev == null) { |
505 |
queues[i].head = entry.next; |
|
506 |
} else { |
|
507 |
prev.next = entry.next; |
|
508 |
} |
|
509 |
if (queues[i].tail == entry) { |
|
510 |
queues[i].tail = prev; |
|
511 |
} |
|
512 |
uncacheEQItem(entry); |
|
513 |
return entry.event; |
|
514 |
} |
|
515 |
} |
|
516 |
} |
|
517 |
this.waitForID = id; |
|
518 |
wait(); |
|
519 |
this.waitForID = 0; |
|
520 |
} |
|
521 |
} while(true); |
|
522 |
} |
|
523 |
||
524 |
/** |
|
525 |
* Returns the first event on the <code>EventQueue</code> |
|
526 |
* without removing it. |
|
527 |
* @return the first event |
|
528 |
*/ |
|
529 |
public synchronized AWTEvent peekEvent() { |
|
530 |
for (int i = NUM_PRIORITIES - 1; i >= 0; i--) { |
|
531 |
if (queues[i].head != null) { |
|
532 |
return queues[i].head.event; |
|
533 |
} |
|
534 |
} |
|
535 |
||
536 |
return null; |
|
537 |
} |
|
538 |
||
539 |
/** |
|
540 |
* Returns the first event with the specified id, if any. |
|
541 |
* @param id the id of the type of event desired |
|
542 |
* @return the first event of the specified id or <code>null</code> |
|
543 |
* if there is no such event |
|
544 |
*/ |
|
545 |
public synchronized AWTEvent peekEvent(int id) { |
|
546 |
for (int i = NUM_PRIORITIES - 1; i >= 0; i--) { |
|
547 |
EventQueueItem q = queues[i].head; |
|
548 |
for (; q != null; q = q.next) { |
|
1181
c5971dbeaaaa
6693974: Unify EventQueue$EventQueueItem and SunToolkit.$EventQueueItem classes
dav
parents:
2
diff
changeset
|
549 |
if (q.event.getID() == id) { |
2 | 550 |
return q.event; |
551 |
} |
|
552 |
} |
|
553 |
} |
|
554 |
||
555 |
return null; |
|
556 |
} |
|
557 |
||
558 |
/** |
|
559 |
* Dispatches an event. The manner in which the event is |
|
560 |
* dispatched depends upon the type of the event and the |
|
561 |
* type of the event's source object: |
|
562 |
* <p> </p> |
|
563 |
* <table border=1 summary="Event types, source types, and dispatch methods"> |
|
564 |
* <tr> |
|
565 |
* <th>Event Type</th> |
|
566 |
* <th>Source Type</th> |
|
567 |
* <th>Dispatched To</th> |
|
568 |
* </tr> |
|
569 |
* <tr> |
|
570 |
* <td>ActiveEvent</td> |
|
571 |
* <td>Any</td> |
|
572 |
* <td>event.dispatch()</td> |
|
573 |
* </tr> |
|
574 |
* <tr> |
|
575 |
* <td>Other</td> |
|
576 |
* <td>Component</td> |
|
577 |
* <td>source.dispatchEvent(AWTEvent)</td> |
|
578 |
* </tr> |
|
579 |
* <tr> |
|
580 |
* <td>Other</td> |
|
581 |
* <td>MenuComponent</td> |
|
582 |
* <td>source.dispatchEvent(AWTEvent)</td> |
|
583 |
* </tr> |
|
584 |
* <tr> |
|
585 |
* <td>Other</td> |
|
586 |
* <td>Other</td> |
|
587 |
* <td>No action (ignored)</td> |
|
588 |
* </tr> |
|
589 |
* </table> |
|
590 |
* <p> </p> |
|
591 |
* @param event an instance of <code>java.awt.AWTEvent</code>, |
|
592 |
* or a subclass of it |
|
593 |
* @throws NullPointerException if <code>event</code> is <code>null</code> |
|
594 |
* @since 1.2 |
|
595 |
*/ |
|
596 |
protected void dispatchEvent(AWTEvent event) { |
|
597 |
event.isPosted = true; |
|
598 |
Object src = event.getSource(); |
|
599 |
if (event instanceof ActiveEvent) { |
|
600 |
// This could become the sole method of dispatching in time. |
|
601 |
setCurrentEventAndMostRecentTimeImpl(event); |
|
602 |
||
603 |
((ActiveEvent)event).dispatch(); |
|
604 |
} else if (src instanceof Component) { |
|
605 |
((Component)src).dispatchEvent(event); |
|
606 |
event.dispatched(); |
|
607 |
} else if (src instanceof MenuComponent) { |
|
608 |
((MenuComponent)src).dispatchEvent(event); |
|
609 |
} else if (src instanceof TrayIcon) { |
|
610 |
((TrayIcon)src).dispatchEvent(event); |
|
611 |
} else if (src instanceof AWTAutoShutdown) { |
|
612 |
if (noEvents()) { |
|
613 |
dispatchThread.stopDispatching(); |
|
614 |
} |
|
615 |
} else { |
|
616 |
System.err.println("unable to dispatch event: " + event); |
|
617 |
} |
|
618 |
} |
|
619 |
||
620 |
/** |
|
621 |
* Returns the timestamp of the most recent event that had a timestamp, and |
|
622 |
* that was dispatched from the <code>EventQueue</code> associated with the |
|
623 |
* calling thread. If an event with a timestamp is currently being |
|
624 |
* dispatched, its timestamp will be returned. If no events have yet |
|
625 |
* been dispatched, the EventQueue's initialization time will be |
|
626 |
* returned instead.In the current version of |
|
627 |
* the JDK, only <code>InputEvent</code>s, |
|
628 |
* <code>ActionEvent</code>s, and <code>InvocationEvent</code>s have |
|
629 |
* timestamps; however, future versions of the JDK may add timestamps to |
|
630 |
* additional event types. Note that this method should only be invoked |
|
631 |
* from an application's {@link #isDispatchThread event dispatching thread}. |
|
632 |
* If this method is |
|
633 |
* invoked from another thread, the current system time (as reported by |
|
634 |
* <code>System.currentTimeMillis()</code>) will be returned instead. |
|
635 |
* |
|
636 |
* @return the timestamp of the last <code>InputEvent</code>, |
|
637 |
* <code>ActionEvent</code>, or <code>InvocationEvent</code> to be |
|
638 |
* dispatched, or <code>System.currentTimeMillis()</code> if this |
|
639 |
* method is invoked on a thread other than an event dispatching |
|
640 |
* thread |
|
641 |
* @see java.awt.event.InputEvent#getWhen |
|
642 |
* @see java.awt.event.ActionEvent#getWhen |
|
643 |
* @see java.awt.event.InvocationEvent#getWhen |
|
644 |
* @see #isDispatchThread |
|
645 |
* |
|
646 |
* @since 1.4 |
|
647 |
*/ |
|
648 |
public static long getMostRecentEventTime() { |
|
649 |
return Toolkit.getEventQueue().getMostRecentEventTimeImpl(); |
|
650 |
} |
|
651 |
private synchronized long getMostRecentEventTimeImpl() { |
|
652 |
return (Thread.currentThread() == dispatchThread) |
|
653 |
? mostRecentEventTime |
|
654 |
: System.currentTimeMillis(); |
|
655 |
} |
|
656 |
||
657 |
/** |
|
658 |
* @return most recent event time on all threads. |
|
659 |
*/ |
|
660 |
synchronized long getMostRecentEventTimeEx() { |
|
661 |
return mostRecentEventTime; |
|
662 |
} |
|
663 |
||
664 |
/** |
|
665 |
* Returns the the event currently being dispatched by the |
|
666 |
* <code>EventQueue</code> associated with the calling thread. This is |
|
667 |
* useful if a method needs access to the event, but was not designed to |
|
668 |
* receive a reference to it as an argument. Note that this method should |
|
669 |
* only be invoked from an application's event dispatching thread. If this |
|
670 |
* method is invoked from another thread, null will be returned. |
|
671 |
* |
|
672 |
* @return the event currently being dispatched, or null if this method is |
|
673 |
* invoked on a thread other than an event dispatching thread |
|
674 |
* @since 1.4 |
|
675 |
*/ |
|
676 |
public static AWTEvent getCurrentEvent() { |
|
677 |
return Toolkit.getEventQueue().getCurrentEventImpl(); |
|
678 |
} |
|
679 |
private synchronized AWTEvent getCurrentEventImpl() { |
|
680 |
return (Thread.currentThread() == dispatchThread) |
|
681 |
? ((AWTEvent)currentEvent.get()) |
|
682 |
: null; |
|
683 |
} |
|
684 |
||
685 |
/** |
|
686 |
* Replaces the existing <code>EventQueue</code> with the specified one. |
|
687 |
* Any pending events are transferred to the new <code>EventQueue</code> |
|
688 |
* for processing by it. |
|
689 |
* |
|
690 |
* @param newEventQueue an <code>EventQueue</code> |
|
691 |
* (or subclass thereof) instance to be use |
|
692 |
* @see java.awt.EventQueue#pop |
|
693 |
* @throws NullPointerException if <code>newEventQueue</code> is <code>null</code> |
|
694 |
* @since 1.2 |
|
695 |
*/ |
|
696 |
public synchronized void push(EventQueue newEventQueue) { |
|
697 |
if (eventLog.isLoggable(Level.FINE)) { |
|
698 |
eventLog.log(Level.FINE, "EventQueue.push(" + newEventQueue + ")"); |
|
699 |
} |
|
700 |
||
701 |
if (nextQueue != null) { |
|
702 |
nextQueue.push(newEventQueue); |
|
703 |
return; |
|
704 |
} |
|
705 |
||
706 |
synchronized (newEventQueue) { |
|
707 |
// Transfer all events forward to new EventQueue. |
|
708 |
while (peekEvent() != null) { |
|
709 |
try { |
|
710 |
newEventQueue.postEventPrivate(getNextEvent()); |
|
711 |
} catch (InterruptedException ie) { |
|
712 |
if (eventLog.isLoggable(Level.FINE)) { |
|
713 |
eventLog.log(Level.FINE, "Interrupted push", ie); |
|
714 |
} |
|
715 |
} |
|
716 |
} |
|
717 |
||
718 |
newEventQueue.previousQueue = this; |
|
719 |
} |
|
720 |
/* |
|
721 |
* Stop the event dispatch thread associated with the currently |
|
722 |
* active event queue, so that after the new queue is pushed |
|
723 |
* on the top this event dispatch thread won't prevent AWT from |
|
724 |
* being automatically shut down. |
|
725 |
* Use stopDispatchingLater() to avoid deadlock: stopDispatching() |
|
726 |
* waits for the dispatch thread to exit, so if the dispatch |
|
727 |
* thread attempts to synchronize on this EventQueue object |
|
728 |
* it will never exit since we already hold this lock. |
|
729 |
*/ |
|
730 |
if (dispatchThread != null) { |
|
731 |
dispatchThread.stopDispatchingLater(); |
|
732 |
} |
|
733 |
||
734 |
nextQueue = newEventQueue; |
|
735 |
||
736 |
AppContext appContext = AppContext.getAppContext(); |
|
737 |
if (appContext.get(AppContext.EVENT_QUEUE_KEY) == this) { |
|
738 |
appContext.put(AppContext.EVENT_QUEUE_KEY, newEventQueue); |
|
739 |
} |
|
740 |
} |
|
741 |
||
742 |
/** |
|
743 |
* Stops dispatching events using this <code>EventQueue</code>. |
|
744 |
* Any pending events are transferred to the previous |
|
745 |
* <code>EventQueue</code> for processing. |
|
746 |
* <p> |
|
747 |
* Warning: To avoid deadlock, do not declare this method |
|
748 |
* synchronized in a subclass. |
|
749 |
* |
|
750 |
* @exception EmptyStackException if no previous push was made |
|
751 |
* on this <code>EventQueue</code> |
|
752 |
* @see java.awt.EventQueue#push |
|
753 |
* @since 1.2 |
|
754 |
*/ |
|
755 |
protected void pop() throws EmptyStackException { |
|
756 |
if (eventLog.isLoggable(Level.FINE)) { |
|
757 |
eventLog.log(Level.FINE, "EventQueue.pop(" + this + ")"); |
|
758 |
} |
|
759 |
||
760 |
// To prevent deadlock, we lock on the previous EventQueue before |
|
761 |
// this one. This uses the same locking order as everything else |
|
762 |
// in EventQueue.java, so deadlock isn't possible. |
|
763 |
EventQueue prev = previousQueue; |
|
764 |
synchronized ((prev != null) ? prev : this) { |
|
765 |
synchronized(this) { |
|
766 |
if (nextQueue != null) { |
|
767 |
nextQueue.pop(); |
|
768 |
return; |
|
769 |
} |
|
770 |
if (previousQueue == null) { |
|
771 |
throw new EmptyStackException(); |
|
772 |
} |
|
773 |
||
774 |
// Transfer all events back to previous EventQueue. |
|
775 |
previousQueue.nextQueue = null; |
|
776 |
while (peekEvent() != null) { |
|
777 |
try { |
|
778 |
previousQueue.postEventPrivate(getNextEvent()); |
|
779 |
} catch (InterruptedException ie) { |
|
780 |
if (eventLog.isLoggable(Level.FINE)) { |
|
781 |
eventLog.log(Level.FINE, "Interrupted pop", ie); |
|
782 |
} |
|
783 |
} |
|
784 |
} |
|
785 |
AppContext appContext = AppContext.getAppContext(); |
|
786 |
if (appContext.get(AppContext.EVENT_QUEUE_KEY) == this) { |
|
787 |
appContext.put(AppContext.EVENT_QUEUE_KEY, previousQueue); |
|
788 |
} |
|
789 |
||
790 |
previousQueue = null; |
|
791 |
} |
|
792 |
} |
|
793 |
||
794 |
EventDispatchThread dt = this.dispatchThread; |
|
795 |
if (dt != null) { |
|
796 |
dt.stopDispatching(); // Must be done outside synchronized |
|
797 |
// block to avoid possible deadlock |
|
798 |
} |
|
799 |
} |
|
800 |
||
801 |
/** |
|
802 |
* Returns true if the calling thread is |
|
803 |
* {@link Toolkit#getSystemEventQueue the current AWT EventQueue}'s |
|
804 |
* dispatch thread. Use this method to ensure that a particular |
|
805 |
* task is being executed (or not being) there. |
|
806 |
* <p> |
|
807 |
* Note: use the {@link #invokeLater} or {@link #invokeAndWait} |
|
808 |
* methods to execute a task in |
|
809 |
* {@link Toolkit#getSystemEventQueue the current AWT EventQueue}'s |
|
810 |
* dispatch thread. |
|
811 |
* <p> |
|
812 |
* |
|
813 |
* @return true if running in |
|
814 |
* {@link Toolkit#getSystemEventQueue the current AWT EventQueue}'s |
|
815 |
* dispatch thread |
|
816 |
* @see #invokeLater |
|
817 |
* @see #invokeAndWait |
|
818 |
* @see Toolkit#getSystemEventQueue |
|
819 |
* @since 1.2 |
|
820 |
*/ |
|
821 |
public static boolean isDispatchThread() { |
|
822 |
EventQueue eq = Toolkit.getEventQueue(); |
|
823 |
EventQueue next = eq.nextQueue; |
|
824 |
while (next != null) { |
|
825 |
eq = next; |
|
826 |
next = eq.nextQueue; |
|
827 |
} |
|
828 |
return (Thread.currentThread() == eq.dispatchThread); |
|
829 |
} |
|
830 |
||
831 |
final void initDispatchThread() { |
|
832 |
synchronized (this) { |
|
833 |
if (dispatchThread == null && !threadGroup.isDestroyed()) { |
|
834 |
dispatchThread = (EventDispatchThread) |
|
835 |
AccessController.doPrivileged(new PrivilegedAction() { |
|
836 |
public Object run() { |
|
837 |
EventDispatchThread t = |
|
838 |
new EventDispatchThread(threadGroup, |
|
839 |
name, |
|
840 |
EventQueue.this); |
|
841 |
t.setContextClassLoader(classLoader); |
|
842 |
t.setPriority(Thread.NORM_PRIORITY + 1); |
|
843 |
t.setDaemon(false); |
|
844 |
return t; |
|
845 |
} |
|
846 |
}); |
|
847 |
AWTAutoShutdown.getInstance().notifyThreadBusy(dispatchThread); |
|
848 |
dispatchThread.start(); |
|
849 |
} |
|
850 |
} |
|
851 |
} |
|
852 |
||
853 |
final void detachDispatchThread() { |
|
854 |
dispatchThread = null; |
|
855 |
} |
|
856 |
||
857 |
/* |
|
858 |
* Gets the <code>EventDispatchThread</code> for this |
|
859 |
* <code>EventQueue</code>. |
|
860 |
* @return the event dispatch thread associated with this event queue |
|
861 |
* or <code>null</code> if this event queue doesn't have a |
|
862 |
* working thread associated with it |
|
863 |
* @see java.awt.EventQueue#initDispatchThread |
|
864 |
* @see java.awt.EventQueue#detachDispatchThread |
|
865 |
*/ |
|
866 |
final EventDispatchThread getDispatchThread() { |
|
867 |
return dispatchThread; |
|
868 |
} |
|
869 |
||
870 |
/* |
|
871 |
* Removes any pending events for the specified source object. |
|
872 |
* If removeAllEvents parameter is <code>true</code> then all |
|
873 |
* events for the specified source object are removed, if it |
|
874 |
* is <code>false</code> then <code>SequencedEvent</code>, <code>SentEvent</code>, |
|
875 |
* <code>FocusEvent</code>, <code>WindowEvent</code>, <code>KeyEvent</code>, |
|
876 |
* and <code>InputMethodEvent</code> are kept in the queue, but all other |
|
877 |
* events are removed. |
|
878 |
* |
|
879 |
* This method is normally called by the source's |
|
880 |
* <code>removeNotify</code> method. |
|
881 |
*/ |
|
882 |
final void removeSourceEvents(Object source, boolean removeAllEvents) { |
|
883 |
SunToolkit.flushPendingEvents(); |
|
884 |
synchronized (this) { |
|
885 |
for (int i = 0; i < NUM_PRIORITIES; i++) { |
|
886 |
EventQueueItem entry = queues[i].head; |
|
887 |
EventQueueItem prev = null; |
|
888 |
while (entry != null) { |
|
889 |
if ((entry.event.getSource() == source) |
|
890 |
&& (removeAllEvents |
|
891 |
|| ! (entry.event instanceof SequencedEvent |
|
892 |
|| entry.event instanceof SentEvent |
|
893 |
|| entry.event instanceof FocusEvent |
|
894 |
|| entry.event instanceof WindowEvent |
|
895 |
|| entry.event instanceof KeyEvent |
|
896 |
|| entry.event instanceof InputMethodEvent))) |
|
897 |
{ |
|
898 |
if (entry.event instanceof SequencedEvent) { |
|
899 |
((SequencedEvent)entry.event).dispose(); |
|
900 |
} |
|
901 |
if (entry.event instanceof SentEvent) { |
|
902 |
((SentEvent)entry.event).dispose(); |
|
903 |
} |
|
904 |
if (prev == null) { |
|
905 |
queues[i].head = entry.next; |
|
906 |
} else { |
|
907 |
prev.next = entry.next; |
|
908 |
} |
|
909 |
uncacheEQItem(entry); |
|
910 |
} else { |
|
911 |
prev = entry; |
|
912 |
} |
|
913 |
entry = entry.next; |
|
914 |
} |
|
915 |
queues[i].tail = prev; |
|
916 |
} |
|
917 |
} |
|
918 |
} |
|
919 |
||
920 |
static void setCurrentEventAndMostRecentTime(AWTEvent e) { |
|
921 |
Toolkit.getEventQueue().setCurrentEventAndMostRecentTimeImpl(e); |
|
922 |
} |
|
923 |
private synchronized void setCurrentEventAndMostRecentTimeImpl(AWTEvent e) |
|
924 |
{ |
|
925 |
if (Thread.currentThread() != dispatchThread) { |
|
926 |
return; |
|
927 |
} |
|
928 |
||
929 |
currentEvent = new WeakReference(e); |
|
930 |
||
931 |
// This series of 'instanceof' checks should be replaced with a |
|
932 |
// polymorphic type (for example, an interface which declares a |
|
933 |
// getWhen() method). However, this would require us to make such |
|
934 |
// a type public, or to place it in sun.awt. Both of these approaches |
|
935 |
// have been frowned upon. So for now, we hack. |
|
936 |
// |
|
937 |
// In tiger, we will probably give timestamps to all events, so this |
|
938 |
// will no longer be an issue. |
|
939 |
long mostRecentEventTime2 = Long.MIN_VALUE; |
|
940 |
if (e instanceof InputEvent) { |
|
941 |
InputEvent ie = (InputEvent)e; |
|
942 |
mostRecentEventTime2 = ie.getWhen(); |
|
943 |
} else if (e instanceof InputMethodEvent) { |
|
944 |
InputMethodEvent ime = (InputMethodEvent)e; |
|
945 |
mostRecentEventTime2 = ime.getWhen(); |
|
946 |
} else if (e instanceof ActionEvent) { |
|
947 |
ActionEvent ae = (ActionEvent)e; |
|
948 |
mostRecentEventTime2 = ae.getWhen(); |
|
949 |
} else if (e instanceof InvocationEvent) { |
|
950 |
InvocationEvent ie = (InvocationEvent)e; |
|
951 |
mostRecentEventTime2 = ie.getWhen(); |
|
952 |
} |
|
953 |
mostRecentEventTime = Math.max(mostRecentEventTime, mostRecentEventTime2); |
|
954 |
} |
|
955 |
||
956 |
/** |
|
957 |
* Causes <code>runnable</code> to have its <code>run</code> |
|
958 |
* method called in the {@link #isDispatchThread dispatch thread} of |
|
959 |
* {@link Toolkit#getSystemEventQueue the system EventQueue}. |
|
960 |
* This will happen after all pending events are processed. |
|
961 |
* |
|
962 |
* @param runnable the <code>Runnable</code> whose <code>run</code> |
|
963 |
* method should be executed |
|
964 |
* asynchronously in the |
|
965 |
* {@link #isDispatchThread event dispatch thread} |
|
966 |
* of {@link Toolkit#getSystemEventQueue the system EventQueue} |
|
967 |
* @see #invokeAndWait |
|
968 |
* @see Toolkit#getSystemEventQueue |
|
969 |
* @see #isDispatchThread |
|
970 |
* @since 1.2 |
|
971 |
*/ |
|
972 |
public static void invokeLater(Runnable runnable) { |
|
973 |
Toolkit.getEventQueue().postEvent( |
|
974 |
new InvocationEvent(Toolkit.getDefaultToolkit(), runnable)); |
|
975 |
} |
|
976 |
||
977 |
/** |
|
978 |
* Causes <code>runnable</code> to have its <code>run</code> |
|
979 |
* method called in the {@link #isDispatchThread dispatch thread} of |
|
980 |
* {@link Toolkit#getSystemEventQueue the system EventQueue}. |
|
981 |
* This will happen after all pending events are processed. |
|
982 |
* The call blocks until this has happened. This method |
|
983 |
* will throw an Error if called from the |
|
984 |
* {@link #isDispatchThread event dispatcher thread}. |
|
985 |
* |
|
986 |
* @param runnable the <code>Runnable</code> whose <code>run</code> |
|
987 |
* method should be executed |
|
988 |
* synchronously in the |
|
989 |
* {@link #isDispatchThread event dispatch thread} |
|
990 |
* of {@link Toolkit#getSystemEventQueue the system EventQueue} |
|
991 |
* @exception InterruptedException if any thread has |
|
992 |
* interrupted this thread |
|
993 |
* @exception InvocationTargetException if an throwable is thrown |
|
994 |
* when running <code>runnable</code> |
|
995 |
* @see #invokeLater |
|
996 |
* @see Toolkit#getSystemEventQueue |
|
997 |
* @see #isDispatchThread |
|
998 |
* @since 1.2 |
|
999 |
*/ |
|
1000 |
public static void invokeAndWait(Runnable runnable) |
|
1001 |
throws InterruptedException, InvocationTargetException { |
|
1002 |
||
1003 |
if (EventQueue.isDispatchThread()) { |
|
1004 |
throw new Error("Cannot call invokeAndWait from the event dispatcher thread"); |
|
1005 |
} |
|
1006 |
||
1007 |
class AWTInvocationLock {} |
|
1008 |
Object lock = new AWTInvocationLock(); |
|
1009 |
||
1010 |
InvocationEvent event = |
|
1011 |
new InvocationEvent(Toolkit.getDefaultToolkit(), runnable, lock, |
|
1012 |
true); |
|
1013 |
||
1014 |
synchronized (lock) { |
|
1015 |
Toolkit.getEventQueue().postEvent(event); |
|
1016 |
lock.wait(); |
|
1017 |
} |
|
1018 |
||
1019 |
Throwable eventThrowable = event.getThrowable(); |
|
1020 |
if (eventThrowable != null) { |
|
1021 |
throw new InvocationTargetException(eventThrowable); |
|
1022 |
} |
|
1023 |
} |
|
1024 |
||
1025 |
/* |
|
1026 |
* Called from PostEventQueue.postEvent to notify that a new event |
|
1027 |
* appeared. First it proceeds to the EventQueue on the top of the |
|
1028 |
* stack, then notifies the associated dispatch thread if it exists |
|
1029 |
* or starts a new one otherwise. |
|
1030 |
*/ |
|
1031 |
private void wakeup(boolean isShutdown) { |
|
1032 |
synchronized(this) { |
|
1033 |
if (nextQueue != null) { |
|
1034 |
// Forward call to the top of EventQueue stack. |
|
1035 |
nextQueue.wakeup(isShutdown); |
|
1036 |
} else if (dispatchThread != null) { |
|
1037 |
notifyAll(); |
|
1038 |
} else if (!isShutdown) { |
|
1039 |
initDispatchThread(); |
|
1040 |
} |
|
1041 |
} |
|
1042 |
} |
|
1043 |
} |
|
1044 |
||
1045 |
/** |
|
1046 |
* The Queue object holds pointers to the beginning and end of one internal |
|
1047 |
* queue. An EventQueue object is composed of multiple internal Queues, one |
|
1048 |
* for each priority supported by the EventQueue. All Events on a particular |
|
1049 |
* internal Queue have identical priority. |
|
1050 |
*/ |
|
1051 |
class Queue { |
|
1052 |
EventQueueItem head; |
|
1053 |
EventQueueItem tail; |
|
1054 |
} |