src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java

Print this page




 519                 this.e = e;
 520             }
 521         }
 522 
 523         public T getResult() throws Exception {
 524             if (e != null) throw e;
 525             return object;
 526         }
 527     }
 528 
 529     public static void invokeAndWait(Runnable event, Component component, boolean detectDeadlocks) throws InterruptedException, InvocationTargetException {
 530         long mediator = createAWTRunLoopMediator();
 531 
 532         InvocationEvent invocationEvent = new CPeerEvent(event, mediator);
 533 
 534         if (component != null) {
 535             AppContext appContext = SunToolkit.targetToAppContext(component);
 536             SunToolkit.postEvent(appContext, invocationEvent);
 537 
 538             // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
 539             sun.awt.SunToolkitSubclass.flushPendingEvents(appContext);
 540         } else {
 541             // This should be the equivalent to EventQueue.invokeAndWait
 542             ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
 543         }
 544 
 545         doAWTRunLoop(mediator, true, detectDeadlocks);
 546 
 547         Throwable eventException = invocationEvent.getException();
 548         if (eventException != null) {
 549             if (eventException instanceof UndeclaredThrowableException) {
 550                 eventException = ((UndeclaredThrowableException)eventException).getUndeclaredThrowable();
 551             }
 552             throw new InvocationTargetException(eventException);
 553         }
 554     }
 555 
 556     public static void invokeLater(Runnable event, Component component) throws InvocationTargetException {
 557         final InvocationEvent invocationEvent = new CPeerEvent(event, 0);
 558 
 559         if (component != null) {
 560             final AppContext appContext = SunToolkit.targetToAppContext(component);
 561             SunToolkit.postEvent(appContext, invocationEvent);
 562 
 563             // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
 564             sun.awt.SunToolkitSubclass.flushPendingEvents(appContext);
 565         } else {
 566             // This should be the equivalent to EventQueue.invokeAndWait
 567             ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
 568         }
 569 
 570         final Throwable eventException = invocationEvent.getException();
 571         if (eventException == null) return;
 572 
 573         if (eventException instanceof UndeclaredThrowableException) {
 574             throw new InvocationTargetException(((UndeclaredThrowableException)eventException).getUndeclaredThrowable());
 575         }
 576         throw new InvocationTargetException(eventException);
 577     }
 578 
 579     // This exists purely to get around permissions issues with getSystemEventQueueImpl
 580     EventQueue getSystemEventQueueForInvokeAndWait() {
 581         return getSystemEventQueueImpl();
 582     }
 583 
 584 




 519                 this.e = e;
 520             }
 521         }
 522 
 523         public T getResult() throws Exception {
 524             if (e != null) throw e;
 525             return object;
 526         }
 527     }
 528 
 529     public static void invokeAndWait(Runnable event, Component component, boolean detectDeadlocks) throws InterruptedException, InvocationTargetException {
 530         long mediator = createAWTRunLoopMediator();
 531 
 532         InvocationEvent invocationEvent = new CPeerEvent(event, mediator);
 533 
 534         if (component != null) {
 535             AppContext appContext = SunToolkit.targetToAppContext(component);
 536             SunToolkit.postEvent(appContext, invocationEvent);
 537 
 538             // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
 539             SunToolkit.flushPendingEvents(appContext);
 540         } else {
 541             // This should be the equivalent to EventQueue.invokeAndWait
 542             ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
 543         }
 544 
 545         doAWTRunLoop(mediator, true, detectDeadlocks);
 546 
 547         Throwable eventException = invocationEvent.getException();
 548         if (eventException != null) {
 549             if (eventException instanceof UndeclaredThrowableException) {
 550                 eventException = ((UndeclaredThrowableException)eventException).getUndeclaredThrowable();
 551             }
 552             throw new InvocationTargetException(eventException);
 553         }
 554     }
 555 
 556     public static void invokeLater(Runnable event, Component component) throws InvocationTargetException {
 557         final InvocationEvent invocationEvent = new CPeerEvent(event, 0);
 558 
 559         if (component != null) {
 560             final AppContext appContext = SunToolkit.targetToAppContext(component);
 561             SunToolkit.postEvent(appContext, invocationEvent);
 562 
 563             // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
 564             SunToolkit.flushPendingEvents(appContext);
 565         } else {
 566             // This should be the equivalent to EventQueue.invokeAndWait
 567             ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
 568         }
 569 
 570         final Throwable eventException = invocationEvent.getException();
 571         if (eventException == null) return;
 572 
 573         if (eventException instanceof UndeclaredThrowableException) {
 574             throw new InvocationTargetException(((UndeclaredThrowableException)eventException).getUndeclaredThrowable());
 575         }
 576         throw new InvocationTargetException(eventException);
 577     }
 578 
 579     // This exists purely to get around permissions issues with getSystemEventQueueImpl
 580     EventQueue getSystemEventQueueForInvokeAndWait() {
 581         return getSystemEventQueueImpl();
 582     }
 583 
 584