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