116 |
|
|
117 |
if (next_in != next_out) |
if (next_in != next_out) |
118 |
return queue[next_out]; |
return queue[next_out]; |
119 |
else return null; |
else |
120 |
|
return null; |
121 |
} |
} |
122 |
|
|
123 |
/** |
/** |
143 |
{ |
{ |
144 |
AWTEvent qevt = queue[i]; |
AWTEvent qevt = queue[i]; |
145 |
if (qevt.id == id) |
if (qevt.id == id) |
146 |
return qevt; |
return qevt; |
147 |
} |
} |
148 |
return null; |
return null; |
149 |
} |
} |
160 |
if (next != null) |
if (next != null) |
161 |
{ |
{ |
162 |
next.postEvent(evt); |
next.postEvent(evt); |
163 |
return; |
return; |
164 |
} |
} |
165 |
// FIXME: Security checks? |
// FIXME: Security checks? |
166 |
|
|
170 |
while (i != next_in) |
while (i != next_in) |
171 |
{ |
{ |
172 |
AWTEvent qevt = queue[i]; |
AWTEvent qevt = queue[i]; |
173 |
Object src; |
Object src; |
174 |
if (qevt.id == evt.id |
if (qevt.id == evt.id |
175 |
&& (src = qevt.getSource()) == evt.getSource() |
&& (src = qevt.getSource()) == evt.getSource() |
176 |
&& src instanceof Component) |
&& src instanceof Component) |
177 |
{ |
{ |
178 |
/* If there are, call coalesceEvents on the source component |
/* If there are, call coalesceEvents on the source component |
179 |
to see if they can be combined. */ |
to see if they can be combined. */ |
180 |
Component srccmp = (Component) src; |
Component srccmp = (Component) src; |
181 |
AWTEvent coalesced_evt = srccmp.coalesceEvents(qevt, evt); |
AWTEvent coalesced_evt = srccmp.coalesceEvents(qevt, evt); |
182 |
if (coalesced_evt != null) |
if (coalesced_evt != null) |
183 |
{ |
{ |
184 |
/* Yes. Replace the existing event with the combined event. */ |
/* Yes. Replace the existing event with the combined event. */ |
185 |
queue[i] = coalesced_evt; |
queue[i] = coalesced_evt; |
186 |
return; |
return; |
187 |
} |
} |
188 |
break; |
break; |
189 |
} |
} |
190 |
if (++i == queue.length) |
if (++i == queue.length) |
191 |
i = 0; |
i = 0; |
192 |
} |
} |
193 |
|
|
194 |
queue[next_in] = evt; |
queue[next_in] = evt; |
199 |
{ |
{ |
200 |
/* Queue is full. Extend it. */ |
/* Queue is full. Extend it. */ |
201 |
AWTEvent[] oldQueue = queue; |
AWTEvent[] oldQueue = queue; |
202 |
queue = new AWTEvent[queue.length * 2]; |
queue = new AWTEvent[queue.length * 2]; |
203 |
|
|
204 |
int len = oldQueue.length - next_out; |
int len = oldQueue.length - next_out; |
205 |
System.arraycopy(oldQueue, next_out, queue, 0, len); |
System.arraycopy(oldQueue, next_out, queue, 0, len); |
206 |
if (next_out != 0) |
if (next_out != 0) |
207 |
System.arraycopy(oldQueue, 0, queue, len, next_out); |
System.arraycopy(oldQueue, 0, queue, len, next_out); |
208 |
|
|
209 |
next_out = 0; |
next_out = 0; |
210 |
next_in = oldQueue.length; |
next_in = oldQueue.length; |
211 |
} |
} |
212 |
notify(); |
notify(); |
213 |
} |
} |
238 |
|
|
239 |
synchronized (current) |
synchronized (current) |
240 |
{ |
{ |
241 |
eq.postEvent(ie); |
eq.postEvent(ie); |
242 |
current.wait(); |
current.wait(); |
243 |
} |
} |
244 |
|
|
245 |
Exception exception; |
Exception exception; |
248 |
throw new InvocationTargetException(exception); |
throw new InvocationTargetException(exception); |
249 |
} |
} |
250 |
|
|
251 |
/** @since JDK1.2 */ |
/** |
252 |
|
* @since 1.2 |
253 |
|
*/ |
254 |
public static void invokeLater(Runnable runnable) |
public static void invokeLater(Runnable runnable) |
255 |
{ |
{ |
256 |
EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); |
EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); |
267 |
return (Thread.currentThread() == eq.dispatchThread); |
return (Thread.currentThread() == eq.dispatchThread); |
268 |
} |
} |
269 |
|
|
270 |
/** Allows a custom EventQueue implementation to replace this one. |
/** |
271 |
* All pending events are transferred to the new queue. Calls to postEvent, |
* Allows a custom EventQueue implementation to replace this one. |
272 |
* getNextEvent, and peekEvent are forwarded to the pushed queue until it |
* All pending events are transferred to the new queue. Calls to postEvent, |
273 |
* is removed with a pop(). |
* getNextEvent, and peekEvent are forwarded to the pushed queue until it |
274 |
* |
* is removed with a pop(). |
275 |
* @exception NullPointerException if newEventQueue is null. |
* |
276 |
*/ |
* @exception NullPointerException if newEventQueue is null. |
277 |
|
*/ |
278 |
public synchronized void push(EventQueue newEventQueue) |
public synchronized void push(EventQueue newEventQueue) |
279 |
{ |
{ |
280 |
|
if (newEventQueue == null) |
281 |
|
throw new NullPointerException (); |
282 |
|
|
283 |
int i = next_out; |
int i = next_out; |
284 |
while (i != next_in) |
while (i != next_in) |
285 |
{ |
{ |
286 |
newEventQueue.postEvent(queue[i]); |
newEventQueue.postEvent(queue[i]); |
287 |
next_out = i; |
next_out = i; |
288 |
if (++i == queue.length) |
if (++i == queue.length) |
289 |
i = 0; |
i = 0; |
290 |
} |
} |
291 |
|
|
292 |
next = newEventQueue; |
next = newEventQueue; |
308 |
// occur. |
// occur. |
309 |
synchronized (prev) |
synchronized (prev) |
310 |
{ |
{ |
311 |
prev.next = null; |
prev.next = null; |
312 |
} |
} |
313 |
|
|
314 |
synchronized (this) |
synchronized (this) |
315 |
{ |
{ |
316 |
int i = next_out; |
int i = next_out; |
317 |
while (i != next_in) |
while (i != next_in) |
318 |
{ |
{ |
319 |
prev.postEvent(queue[i]); |
prev.postEvent(queue[i]); |
320 |
next_out = i; |
next_out = i; |
321 |
if (++i == queue.length) |
if (++i == queue.length) |
322 |
i = 0; |
i = 0; |
323 |
} |
} |
324 |
} |
} |
325 |
} |
} |
326 |
|
|
335 |
if (evt instanceof ActiveEvent) |
if (evt instanceof ActiveEvent) |
336 |
{ |
{ |
337 |
ActiveEvent active_evt = (ActiveEvent) evt; |
ActiveEvent active_evt = (ActiveEvent) evt; |
338 |
active_evt.dispatch(); |
active_evt.dispatch(); |
339 |
} |
} |
340 |
else |
else |
341 |
{ |
{ |
342 |
Object source = evt.getSource(); |
Object source = evt.getSource(); |
343 |
|
|
344 |
if (source instanceof Component) |
if (source instanceof Component) |
345 |
{ |
{ |
346 |
Component srccmp = (Component) source; |
Component srccmp = (Component) source; |
347 |
srccmp.dispatchEvent(evt); |
srccmp.dispatchEvent(evt); |
348 |
} |
} |
349 |
else if (source instanceof MenuComponent) |
else if (source instanceof MenuComponent) |
350 |
{ |
{ |
351 |
MenuComponent srccmp = (MenuComponent) source; |
MenuComponent srccmp = (MenuComponent) source; |
352 |
srccmp.dispatchEvent(evt); |
srccmp.dispatchEvent(evt); |
353 |
} |
} |
354 |
} |
} |
355 |
} |
} |
356 |
|
|