Java Code Examples for java.awt.event.InvocationEvent#getException()

The following examples show how to use java.awt.event.InvocationEvent#getException() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LWCToolkit.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void invokeLater(Runnable event, Component component)
        throws InvocationTargetException {
    final InvocationEvent invocationEvent =
            new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(), event);

    if (component != null) {
        final AppContext appContext = SunToolkit.targetToAppContext(component);
        SunToolkit.postEvent(appContext, invocationEvent);

        // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
        SunToolkit.flushPendingEvents(appContext);
    } else {
        // This should be the equivalent to EventQueue.invokeAndWait
        ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
    }

    final Throwable eventException = invocationEvent.getException();
    if (eventException == null) return;

    if (eventException instanceof UndeclaredThrowableException) {
        throw new InvocationTargetException(((UndeclaredThrowableException)eventException).getUndeclaredThrowable());
    }
    throw new InvocationTargetException(eventException);
}
 
Example 2
Source File: LWCToolkit.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void invokeLater(Runnable event, Component component) throws InvocationTargetException {
    final InvocationEvent invocationEvent =
            new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(), event);

    if (component != null) {
        final AppContext appContext = SunToolkit.targetToAppContext(component);
        SunToolkit.postEvent(appContext, invocationEvent);

        // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
        SunToolkit.flushPendingEvents(appContext);
    } else {
        // This should be the equivalent to EventQueue.invokeAndWait
        ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
    }

    final Throwable eventException = invocationEvent.getException();
    if (eventException == null) return;

    if (eventException instanceof UndeclaredThrowableException) {
        throw new InvocationTargetException(((UndeclaredThrowableException)eventException).getUndeclaredThrowable());
    }
    throw new InvocationTargetException(eventException);
}
 
Example 3
Source File: LWCToolkit.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void invokeLater(Runnable event, Component component)
        throws InvocationTargetException {
    final InvocationEvent invocationEvent =
            new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(), event);

    if (component != null) {
        final AppContext appContext = SunToolkit.targetToAppContext(component);
        SunToolkit.postEvent(appContext, invocationEvent);

        // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
        SunToolkit.flushPendingEvents(appContext);
    } else {
        // This should be the equivalent to EventQueue.invokeAndWait
        ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
    }

    final Throwable eventException = invocationEvent.getException();
    if (eventException == null) return;

    if (eventException instanceof UndeclaredThrowableException) {
        throw new InvocationTargetException(((UndeclaredThrowableException)eventException).getUndeclaredThrowable());
    }
    throw new InvocationTargetException(eventException);
}
 
Example 4
Source File: LWCToolkit.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void invokeLater(Runnable event, Component component)
        throws InvocationTargetException {
    final InvocationEvent invocationEvent =
            new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(), event);

    if (component != null) {
        final AppContext appContext = SunToolkit.targetToAppContext(component);
        SunToolkit.postEvent(appContext, invocationEvent);

        // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
        SunToolkit.flushPendingEvents(appContext);
    } else {
        // This should be the equivalent to EventQueue.invokeAndWait
        ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
    }

    final Throwable eventException = invocationEvent.getException();
    if (eventException == null) return;

    if (eventException instanceof UndeclaredThrowableException) {
        throw new InvocationTargetException(((UndeclaredThrowableException)eventException).getUndeclaredThrowable());
    }
    throw new InvocationTargetException(eventException);
}
 
Example 5
Source File: LWCToolkit.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void invokeLater(Runnable event, Component component)
        throws InvocationTargetException {
    final InvocationEvent invocationEvent =
            new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(), event);

    if (component != null) {
        final AppContext appContext = SunToolkit.targetToAppContext(component);
        SunToolkit.postEvent(appContext, invocationEvent);

        // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
        SunToolkit.flushPendingEvents(appContext);
    } else {
        // This should be the equivalent to EventQueue.invokeAndWait
        ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
    }

    final Throwable eventException = invocationEvent.getException();
    if (eventException == null) return;

    if (eventException instanceof UndeclaredThrowableException) {
        throw new InvocationTargetException(((UndeclaredThrowableException)eventException).getUndeclaredThrowable());
    }
    throw new InvocationTargetException(eventException);
}
 
Example 6
Source File: LWCToolkit.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void invokeLater(Runnable event, Component component)
        throws InvocationTargetException {
    final InvocationEvent invocationEvent =
            new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(), event);

    if (component != null) {
        final AppContext appContext = SunToolkit.targetToAppContext(component);
        SunToolkit.postEvent(appContext, invocationEvent);

        // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
        SunToolkit.flushPendingEvents(appContext);
    } else {
        // This should be the equivalent to EventQueue.invokeAndWait
        ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
    }

    final Throwable eventException = invocationEvent.getException();
    if (eventException == null) return;

    if (eventException instanceof UndeclaredThrowableException) {
        throw new InvocationTargetException(((UndeclaredThrowableException)eventException).getUndeclaredThrowable());
    }
    throw new InvocationTargetException(eventException);
}
 
Example 7
Source File: EventLock.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Similar to {@link EventQueue#invokeAndWait} but posts the event at the same
 * priority as paint requests, to avoid bad visual artifacts.
 */
static void invokeAndWaitLowPriority(RWLock m, Runnable r)
        throws InterruptedException, InvocationTargetException {
    Toolkit t = Toolkit.getDefaultToolkit();
    EventQueue q = t.getSystemEventQueue();
    Object lock = new PaintPriorityEventLock();
    InvocationEvent ev = new PaintPriorityEvent(m, t, r, lock, true);
    synchronized (lock) {
        q.postEvent(ev);
        lock.wait();
    }
    Exception e = ev.getException();
    if (e != null) {
        throw new InvocationTargetException(e);
    }
}
 
Example 8
Source File: LWCToolkit.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void invokeLater(Runnable event, Component component)
        throws InvocationTargetException {
    final InvocationEvent invocationEvent =
            new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(), event);

    if (component != null) {
        final AppContext appContext = SunToolkit.targetToAppContext(component);
        SunToolkit.postEvent(appContext, invocationEvent);

        // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
        SunToolkit.flushPendingEvents(appContext);
    } else {
        // This should be the equivalent to EventQueue.invokeAndWait
        ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
    }

    final Throwable eventException = invocationEvent.getException();
    if (eventException == null) return;

    if (eventException instanceof UndeclaredThrowableException) {
        throw new InvocationTargetException(((UndeclaredThrowableException)eventException).getUndeclaredThrowable());
    }
    throw new InvocationTargetException(eventException);
}
 
Example 9
Source File: LWCToolkit.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public static void invokeLater(Runnable event, Component component)
        throws InvocationTargetException {
    final InvocationEvent invocationEvent =
            new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(), event);

    if (component != null) {
        final AppContext appContext = SunToolkit.targetToAppContext(component);
        SunToolkit.postEvent(appContext, invocationEvent);

        // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
        SunToolkit.flushPendingEvents(appContext);
    } else {
        // This should be the equivalent to EventQueue.invokeAndWait
        ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
    }

    final Throwable eventException = invocationEvent.getException();
    if (eventException == null) return;

    if (eventException instanceof UndeclaredThrowableException) {
        throw new InvocationTargetException(((UndeclaredThrowableException)eventException).getUndeclaredThrowable());
    }
    throw new InvocationTargetException(eventException);
}
 
Example 10
Source File: LWCToolkit.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void invokeLater(Runnable event, Component component)
        throws InvocationTargetException {
    final InvocationEvent invocationEvent =
            new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(), event);

    if (component != null) {
        final AppContext appContext = SunToolkit.targetToAppContext(component);
        SunToolkit.postEvent(appContext, invocationEvent);

        // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
        SunToolkit.flushPendingEvents(appContext);
    } else {
        // This should be the equivalent to EventQueue.invokeAndWait
        ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
    }

    final Throwable eventException = invocationEvent.getException();
    if (eventException == null) return;

    if (eventException instanceof UndeclaredThrowableException) {
        throw new InvocationTargetException(((UndeclaredThrowableException)eventException).getUndeclaredThrowable());
    }
    throw new InvocationTargetException(eventException);
}
 
Example 11
Source File: LWCToolkit.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void invokeLater(Runnable event, Component component)
        throws InvocationTargetException {
    final InvocationEvent invocationEvent =
            new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(), event);

    if (component != null) {
        final AppContext appContext = SunToolkit.targetToAppContext(component);
        SunToolkit.postEvent(appContext, invocationEvent);

        // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
        SunToolkit.flushPendingEvents(appContext);
    } else {
        // This should be the equivalent to EventQueue.invokeAndWait
        ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
    }

    final Throwable eventException = invocationEvent.getException();
    if (eventException == null) return;

    if (eventException instanceof UndeclaredThrowableException) {
        throw new InvocationTargetException(((UndeclaredThrowableException)eventException).getUndeclaredThrowable());
    }
    throw new InvocationTargetException(eventException);
}
 
Example 12
Source File: LWCToolkit.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Kicks an event over to the appropriate eventqueue and waits for it to
 * finish To avoid deadlocking, we manually run the NSRunLoop while waiting
 * Any selector invoked using ThreadUtilities performOnMainThread will be
 * processed in doAWTRunLoop The InvocationEvent will call
 * LWCToolkit.stopAWTRunLoop() when finished, which will stop our manual
 * runloop Does not dispatch native events while in the loop
 */
public static void invokeAndWait(Runnable runnable, Component component)
        throws InvocationTargetException {
    final long mediator = createAWTRunLoopMediator();

    InvocationEvent invocationEvent =
            new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(),
                    runnable,
                    () -> {
                        if (mediator != 0) {
                            stopAWTRunLoop(mediator);
                        }
                    },
                    true);

    if (component != null) {
        AppContext appContext = SunToolkit.targetToAppContext(component);
        SunToolkit.postEvent(appContext, invocationEvent);

        // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
        SunToolkit.flushPendingEvents(appContext);
    } else {
        // This should be the equivalent to EventQueue.invokeAndWait
        ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
    }

    doAWTRunLoop(mediator, false);

    Throwable eventException = invocationEvent.getException();
    if (eventException != null) {
        if (eventException instanceof UndeclaredThrowableException) {
            eventException = ((UndeclaredThrowableException)eventException).getUndeclaredThrowable();
        }
        throw new InvocationTargetException(eventException);
    }
}
 
Example 13
Source File: LWCToolkit.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Kicks an event over to the appropriate eventqueue and waits for it to
 * finish To avoid deadlocking, we manually run the NSRunLoop while waiting
 * Any selector invoked using ThreadUtilities performOnMainThread will be
 * processed in doAWTRunLoop The InvocationEvent will call
 * LWCToolkit.stopAWTRunLoop() when finished, which will stop our manual
 * runloop Does not dispatch native events while in the loop
 */
public static void invokeAndWait(Runnable runnable, Component component)
        throws InvocationTargetException {
    final long mediator = createAWTRunLoopMediator();

    InvocationEvent invocationEvent =
            new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(),
                    runnable,
                    () -> {
                        if (mediator != 0) {
                            stopAWTRunLoop(mediator);
                        }
                    },
                    true);

    if (component != null) {
        AppContext appContext = SunToolkit.targetToAppContext(component);
        SunToolkit.postEvent(appContext, invocationEvent);

        // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
        SunToolkit.flushPendingEvents(appContext);
    } else {
        // This should be the equivalent to EventQueue.invokeAndWait
        ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
    }

    doAWTRunLoop(mediator, false);

    Throwable eventException = invocationEvent.getException();
    if (eventException != null) {
        if (eventException instanceof UndeclaredThrowableException) {
            eventException = ((UndeclaredThrowableException)eventException).getUndeclaredThrowable();
        }
        throw new InvocationTargetException(eventException);
    }
}
 
Example 14
Source File: LWCToolkit.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks if exception occurred while {@code InvocationEvent} was processed and rethrows it as
 * an {@code InvocationTargetException}
 *
 * @param event the event to check for an exception
 * @throws InvocationTargetException if exception occurred when event was processed
 */
private static void checkException(InvocationEvent event) throws InvocationTargetException {
    Throwable eventException = event.getException();
    if (eventException == null) return;

    if (eventException instanceof UndeclaredThrowableException) {
        eventException = ((UndeclaredThrowableException)eventException).getUndeclaredThrowable();
    }
    throw new InvocationTargetException(eventException);
}
 
Example 15
Source File: LWCToolkit.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Kicks an event over to the appropriate eventqueue and waits for it to
 * finish To avoid deadlocking, we manually run the NSRunLoop while waiting
 * Any selector invoked using ThreadUtilities performOnMainThread will be
 * processed in doAWTRunLoop The InvocationEvent will call
 * LWCToolkit.stopAWTRunLoop() when finished, which will stop our manual
 * runloop Does not dispatch native events while in the loop
 */
public static void invokeAndWait(Runnable runnable, Component component)
        throws InvocationTargetException {
    final long mediator = createAWTRunLoopMediator();

    InvocationEvent invocationEvent =
            new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(),
                    runnable,
                    () -> {
                        if (mediator != 0) {
                            stopAWTRunLoop(mediator);
                        }
                    },
                    true);

    if (component != null) {
        AppContext appContext = SunToolkit.targetToAppContext(component);
        SunToolkit.postEvent(appContext, invocationEvent);

        // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
        SunToolkit.flushPendingEvents(appContext);
    } else {
        // This should be the equivalent to EventQueue.invokeAndWait
        ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
    }

    doAWTRunLoop(mediator, false);

    Throwable eventException = invocationEvent.getException();
    if (eventException != null) {
        if (eventException instanceof UndeclaredThrowableException) {
            eventException = ((UndeclaredThrowableException)eventException).getUndeclaredThrowable();
        }
        throw new InvocationTargetException(eventException);
    }
}
 
Example 16
Source File: LWCToolkit.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Kicks an event over to the appropriate eventqueue and waits for it to
 * finish To avoid deadlocking, we manually run the NSRunLoop while waiting
 * Any selector invoked using ThreadUtilities performOnMainThread will be
 * processed in doAWTRunLoop The InvocationEvent will call
 * LWCToolkit.stopAWTRunLoop() when finished, which will stop our manual
 * runloop Does not dispatch native events while in the loop
 */
public static void invokeAndWait(Runnable runnable, Component component)
        throws InvocationTargetException {
    final long mediator = createAWTRunLoopMediator();

    InvocationEvent invocationEvent =
            new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(),
                    runnable,
                    () -> {
                        if (mediator != 0) {
                            stopAWTRunLoop(mediator);
                        }
                    },
                    true);

    if (component != null) {
        AppContext appContext = SunToolkit.targetToAppContext(component);
        SunToolkit.postEvent(appContext, invocationEvent);

        // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
        SunToolkit.flushPendingEvents(appContext);
    } else {
        // This should be the equivalent to EventQueue.invokeAndWait
        ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
    }

    doAWTRunLoop(mediator, false);

    Throwable eventException = invocationEvent.getException();
    if (eventException != null) {
        if (eventException instanceof UndeclaredThrowableException) {
            eventException = ((UndeclaredThrowableException)eventException).getUndeclaredThrowable();
        }
        throw new InvocationTargetException(eventException);
    }
}
 
Example 17
Source File: LWCToolkit.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Kicks an event over to the appropriate eventqueue and waits for it to
 * finish To avoid deadlocking, we manually run the NSRunLoop while waiting
 * Any selector invoked using ThreadUtilities performOnMainThread will be
 * processed in doAWTRunLoop The InvocationEvent will call
 * LWCToolkit.stopAWTRunLoop() when finished, which will stop our manual
 * runloop Does not dispatch native events while in the loop
 */
public static void invokeAndWait(Runnable runnable, Component component)
        throws InvocationTargetException {
    final long mediator = createAWTRunLoopMediator();

    InvocationEvent invocationEvent =
            new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(),
                    runnable,
                    () -> {
                        if (mediator != 0) {
                            stopAWTRunLoop(mediator);
                        }
                    },
                    true);

    if (component != null) {
        AppContext appContext = SunToolkit.targetToAppContext(component);
        SunToolkit.postEvent(appContext, invocationEvent);

        // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
        SunToolkit.flushPendingEvents(appContext);
    } else {
        // This should be the equivalent to EventQueue.invokeAndWait
        ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
    }

    doAWTRunLoop(mediator, false);

    Throwable eventException = invocationEvent.getException();
    if (eventException != null) {
        if (eventException instanceof UndeclaredThrowableException) {
            eventException = ((UndeclaredThrowableException)eventException).getUndeclaredThrowable();
        }
        throw new InvocationTargetException(eventException);
    }
}
 
Example 18
Source File: LWCToolkit.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Kicks an event over to the appropriate eventqueue and waits for it to
 * finish To avoid deadlocking, we manually run the NSRunLoop while waiting
 * Any selector invoked using ThreadUtilities performOnMainThread will be
 * processed in doAWTRunLoop The InvocationEvent will call
 * LWCToolkit.stopAWTRunLoop() when finished, which will stop our manual
 * runloop Does not dispatch native events while in the loop
 */
public static void invokeAndWait(Runnable runnable, Component component)
        throws InvocationTargetException {
    final long mediator = createAWTRunLoopMediator();

    InvocationEvent invocationEvent =
            new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(),
                    runnable,
                    () -> {
                        if (mediator != 0) {
                            stopAWTRunLoop(mediator);
                        }
                    },
                    true);

    if (component != null) {
        AppContext appContext = SunToolkit.targetToAppContext(component);
        SunToolkit.postEvent(appContext, invocationEvent);

        // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
        SunToolkit.flushPendingEvents(appContext);
    } else {
        // This should be the equivalent to EventQueue.invokeAndWait
        ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
    }

    doAWTRunLoop(mediator, false);

    Throwable eventException = invocationEvent.getException();
    if (eventException != null) {
        if (eventException instanceof UndeclaredThrowableException) {
            eventException = ((UndeclaredThrowableException)eventException).getUndeclaredThrowable();
        }
        throw new InvocationTargetException(eventException);
    }
}
 
Example 19
Source File: LWCToolkit.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void invokeAndWait(Runnable runnable, Component component) throws InvocationTargetException {
    final long mediator = createAWTRunLoopMediator();

    InvocationEvent invocationEvent =
            new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(),
                    runnable,
                    () -> {
                        if (mediator != 0) {
                            stopAWTRunLoop(mediator);
                        }
                    },
                    true);

    if (component != null) {
        AppContext appContext = SunToolkit.targetToAppContext(component);
        SunToolkit.postEvent(appContext, invocationEvent);

        // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
        SunToolkit.flushPendingEvents(appContext);
    } else {
        // This should be the equivalent to EventQueue.invokeAndWait
        ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
    }

    doAWTRunLoop(mediator, false);

    Throwable eventException = invocationEvent.getException();
    if (eventException != null) {
        if (eventException instanceof UndeclaredThrowableException) {
            eventException = ((UndeclaredThrowableException)eventException).getUndeclaredThrowable();
        }
        throw new InvocationTargetException(eventException);
    }
}
 
Example 20
Source File: LWCToolkit.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Kicks an event over to the appropriate eventqueue and waits for it to
 * finish To avoid deadlocking, we manually run the NSRunLoop while waiting
 * Any selector invoked using ThreadUtilities performOnMainThread will be
 * processed in doAWTRunLoop The InvocationEvent will call
 * LWCToolkit.stopAWTRunLoop() when finished, which will stop our manual
 * runloop Does not dispatch native events while in the loop
 */
public static void invokeAndWait(Runnable runnable, Component component)
        throws InvocationTargetException {
    final long mediator = createAWTRunLoopMediator();

    InvocationEvent invocationEvent =
            new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(),
                    runnable,
                    () -> {
                        if (mediator != 0) {
                            stopAWTRunLoop(mediator);
                        }
                    },
                    true);

    if (component != null) {
        AppContext appContext = SunToolkit.targetToAppContext(component);
        SunToolkit.postEvent(appContext, invocationEvent);

        // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
        SunToolkit.flushPendingEvents(appContext);
    } else {
        // This should be the equivalent to EventQueue.invokeAndWait
        ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
    }

    doAWTRunLoop(mediator, false);

    Throwable eventException = invocationEvent.getException();
    if (eventException != null) {
        if (eventException instanceof UndeclaredThrowableException) {
            eventException = ((UndeclaredThrowableException)eventException).getUndeclaredThrowable();
        }
        throw new InvocationTargetException(eventException);
    }
}