Search in sources :

Example 1 with EventQueue

use of java.awt.EventQueue in project jdk8u_jdk by JetBrains.

the class InputMethodEvent method getMostRecentEventTimeForSource.

/**
     * Get the most recent event time in the {@code EventQueue} which the {@code source}
     * belongs to.
     *
     * @param source the source of the event
     * @exception  IllegalArgumentException  if source is null.
     * @return most recent event time in the {@code EventQueue}
     */
private static long getMostRecentEventTimeForSource(Object source) {
    if (source == null) {
        // throw the IllegalArgumentException to conform to EventObject spec
        throw new IllegalArgumentException("null source");
    }
    AppContext appContext = SunToolkit.targetToAppContext(source);
    EventQueue eventQueue = SunToolkit.getSystemEventQueueImplPP(appContext);
    return AWTAccessor.getEventQueueAccessor().getMostRecentEventTime(eventQueue);
}
Also used : AppContext(sun.awt.AppContext) EventQueue(java.awt.EventQueue)

Example 2 with EventQueue

use of java.awt.EventQueue in project hackpad by dropbox.

the class RunProxy method dispatchNextGuiEvent.

/**
     * Processes the next GUI event.
     */
public void dispatchNextGuiEvent() throws InterruptedException {
    EventQueue queue = awtEventQueue;
    if (queue == null) {
        queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
        awtEventQueue = queue;
    }
    AWTEvent event = queue.getNextEvent();
    if (event instanceof ActiveEvent) {
        ((ActiveEvent) event).dispatch();
    } else {
        Object source = event.getSource();
        if (source instanceof Component) {
            Component comp = (Component) source;
            comp.dispatchEvent(event);
        } else if (source instanceof MenuComponent) {
            ((MenuComponent) source).dispatchEvent(event);
        }
    }
}
Also used : ActiveEvent(java.awt.ActiveEvent) AWTEvent(java.awt.AWTEvent) EventObject(java.util.EventObject) MenuComponent(java.awt.MenuComponent) Component(java.awt.Component) MenuComponent(java.awt.MenuComponent) EventQueue(java.awt.EventQueue)

Example 3 with EventQueue

use of java.awt.EventQueue in project jodd by oblac.

the class CaddyDialog method setVisible.

@Override
public void setVisible(boolean visible) {
    boolean blockParent = (visible && modal);
    owner.setEnabled(!blockParent);
    owner.setFocusableWindowState(!blockParent);
    super.setVisible(visible);
    if (blockParent) {
        owner.addWindowListener(parentWindowListener);
        try {
            if (SwingUtilities.isEventDispatchThread()) {
                EventQueue theQueue = getToolkit().getSystemEventQueue();
                while (isVisible()) {
                    AWTEvent event = theQueue.getNextEvent();
                    Object src = event.getSource();
                    if (event instanceof ActiveEvent) {
                        ((ActiveEvent) event).dispatch();
                    } else if (src instanceof Component) {
                        ((Component) src).dispatchEvent(event);
                    }
                }
            } else {
                synchronized (getTreeLock()) {
                    while (isVisible()) {
                        try {
                            getTreeLock().wait();
                        } catch (InterruptedException e) {
                            break;
                        }
                    }
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else {
        owner.removeWindowListener(parentWindowListener);
        // added 2 lines
        owner.setEnabled(true);
        owner.setFocusableWindowState(true);
    }
}
Also used : ActiveEvent(java.awt.ActiveEvent) AWTEvent(java.awt.AWTEvent) Component(java.awt.Component) EventQueue(java.awt.EventQueue)

Example 4 with EventQueue

use of java.awt.EventQueue in project jdk8u_jdk by JetBrains.

the class EDTShutdownTest method main.

public static void main(String[] args) {
    // Force EDT start with InvocationEvent
    EventQueue.invokeLater(() -> {
        // EventQueue is empty now
        EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
        Thread thread = AWTAccessor.getEventQueueAccessor().getDispatchThread(queue);
        try {
            /*
                 * Clear EventDispatchThread.doDispatch flag to break message
                 * loop in EventDispatchThread.pumpEventsForFilter()
                 */
            Method stopDispatching = thread.getClass().getDeclaredMethod("stopDispatching", null);
            stopDispatching.setAccessible(true);
            stopDispatching.invoke(thread, null);
            /*
                 * Post another InvocationEvent that must be handled by another
                 * instance of EDT
                 */
            EventQueue.invokeLater(() -> {
                passed = true;
            });
        } catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
        }
    });
    // Wait for EDT shutdown
    EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
    Thread thread = AWTAccessor.getEventQueueAccessor().getDispatchThread(queue);
    try {
        thread.join();
        /*
             * Wait for another EDT instance to handle the InvocationEvent
             * and shutdown
             */
        thread = AWTAccessor.getEventQueueAccessor().getDispatchThread(queue);
        if (thread != null) {
            thread.join();
        }
    } catch (InterruptedException e) {
    }
    if (passed) {
        System.out.println("Test PASSED!");
    } else {
        throw new RuntimeException("Test FAILED!");
    }
}
Also used : Method(java.lang.reflect.Method) EventQueue(java.awt.EventQueue) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

EventQueue (java.awt.EventQueue)4 AWTEvent (java.awt.AWTEvent)2 ActiveEvent (java.awt.ActiveEvent)2 Component (java.awt.Component)2 MenuComponent (java.awt.MenuComponent)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 EventObject (java.util.EventObject)1 AppContext (sun.awt.AppContext)1