192 public boolean isDispatchThreadImpl(EventQueue eventQueue) { |
192 public boolean isDispatchThreadImpl(EventQueue eventQueue) { |
193 return eventQueue.isDispatchThreadImpl(); |
193 return eventQueue.isDispatchThreadImpl(); |
194 } |
194 } |
195 public void removeSourceEvents(EventQueue eventQueue, |
195 public void removeSourceEvents(EventQueue eventQueue, |
196 Object source, |
196 Object source, |
197 boolean removeAllEvents) { |
197 boolean removeAllEvents) |
|
198 { |
198 eventQueue.removeSourceEvents(source, removeAllEvents); |
199 eventQueue.removeSourceEvents(source, removeAllEvents); |
199 } |
200 } |
200 public boolean noEvents(EventQueue eventQueue) { |
201 public boolean noEvents(EventQueue eventQueue) { |
201 return eventQueue.noEvents(); |
202 return eventQueue.noEvents(); |
202 } |
203 } |
203 public void wakeup(EventQueue eventQueue, boolean isShutdown) { |
204 public void wakeup(EventQueue eventQueue, boolean isShutdown) { |
204 eventQueue.wakeup(isShutdown); |
205 eventQueue.wakeup(isShutdown); |
|
206 } |
|
207 public void invokeAndWait(Object source, Runnable r) |
|
208 throws InterruptedException, InvocationTargetException |
|
209 { |
|
210 EventQueue.invokeAndWait(source, r); |
205 } |
211 } |
206 }); |
212 }); |
207 } |
213 } |
208 |
214 |
209 public EventQueue() { |
215 public EventQueue() { |
1243 * @see Toolkit#getSystemEventQueue |
1249 * @see Toolkit#getSystemEventQueue |
1244 * @see #isDispatchThread |
1250 * @see #isDispatchThread |
1245 * @since 1.2 |
1251 * @since 1.2 |
1246 */ |
1252 */ |
1247 public static void invokeAndWait(Runnable runnable) |
1253 public static void invokeAndWait(Runnable runnable) |
1248 throws InterruptedException, InvocationTargetException { |
1254 throws InterruptedException, InvocationTargetException |
1249 |
1255 { |
|
1256 invokeAndWait(Toolkit.getDefaultToolkit(), runnable); |
|
1257 } |
|
1258 |
|
1259 static void invokeAndWait(Object source, Runnable runnable) |
|
1260 throws InterruptedException, InvocationTargetException |
|
1261 { |
1250 if (EventQueue.isDispatchThread()) { |
1262 if (EventQueue.isDispatchThread()) { |
1251 throw new Error("Cannot call invokeAndWait from the event dispatcher thread"); |
1263 throw new Error("Cannot call invokeAndWait from the event dispatcher thread"); |
1252 } |
1264 } |
1253 |
1265 |
1254 class AWTInvocationLock {} |
1266 class AWTInvocationLock {} |
1255 Object lock = new AWTInvocationLock(); |
1267 Object lock = new AWTInvocationLock(); |
1256 |
1268 |
1257 InvocationEvent event = |
1269 InvocationEvent event = |
1258 new InvocationEvent(Toolkit.getDefaultToolkit(), runnable, lock, |
1270 new InvocationEvent(source, runnable, lock, true); |
1259 true); |
|
1260 |
1271 |
1261 synchronized (lock) { |
1272 synchronized (lock) { |
1262 Toolkit.getEventQueue().postEvent(event); |
1273 Toolkit.getEventQueue().postEvent(event); |
1263 while (!event.isDispatched()) { |
1274 while (!event.isDispatched()) { |
1264 lock.wait(); |
1275 lock.wait(); |