Search in sources :

Example 1 with InvocationEvent

use of java.awt.event.InvocationEvent in project intellij-community by JetBrains.

the class PlatformTestUtil method dispatchAllInvocationEventsInIdeEventQueue.

/**
   * Dispatch all pending invocation events (if any) in the {@link IdeEventQueue}.
   * Should only be invoked in Swing thread (asserted inside {@link IdeEventQueue#dispatchEvent(AWTEvent)})
   */
@TestOnly
public static void dispatchAllInvocationEventsInIdeEventQueue() throws InterruptedException {
    IdeEventQueue eventQueue = IdeEventQueue.getInstance();
    while (true) {
        AWTEvent event = eventQueue.peekEvent();
        if (event == null)
            break;
        AWTEvent event1 = eventQueue.getNextEvent();
        if (event1 instanceof InvocationEvent) {
            eventQueue.dispatchEvent(event1);
        }
    }
}
Also used : InvocationEvent(java.awt.event.InvocationEvent) IdeEventQueue(com.intellij.ide.IdeEventQueue)

Example 2 with InvocationEvent

use of java.awt.event.InvocationEvent in project jdk8u_jdk by JetBrains.

the class ExecutableInputMethodManager method showInputMethodMenuOnRequesterEDT.

// Shows Input Method Menu on the EDT of requester component
// to avoid side effects. See 6544309.
private void showInputMethodMenuOnRequesterEDT(Component requester) throws InterruptedException, InvocationTargetException {
    if (requester == null) {
        return;
    }
    class AWTInvocationLock {
    }
    Object lock = new AWTInvocationLock();
    InvocationEvent event = new InvocationEvent(requester, new Runnable() {

        public void run() {
            showInputMethodMenu();
        }
    }, lock, true);
    AppContext requesterAppContext = SunToolkit.targetToAppContext(requester);
    synchronized (lock) {
        SunToolkit.postEvent(requesterAppContext, event);
        while (!event.isDispatched()) {
            lock.wait();
        }
    }
    Throwable eventThrowable = event.getThrowable();
    if (eventThrowable != null) {
        throw new InvocationTargetException(eventThrowable);
    }
}
Also used : InvocationEvent(java.awt.event.InvocationEvent) AppContext(sun.awt.AppContext) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with InvocationEvent

use of java.awt.event.InvocationEvent in project jdk8u_jdk by JetBrains.

the class LWCToolkit method invokeAndWait.

/**
     * Submit event to the event queue as the method above
     * @param processEvents if <code>true<code/>  always process system events
     */
public static void invokeAndWait(Runnable runnable, Component component, boolean processEvents) throws InvocationTargetException {
    boolean nonBlockingRunLoop;
    if (!processEvents) {
        synchronized (priorityInvocationPending) {
            nonBlockingRunLoop = priorityInvocationPending.get();
            if (!nonBlockingRunLoop)
                blockingRunLoopCounter.incrementAndGet();
        }
    } else {
        nonBlockingRunLoop = true;
    }
    final long mediator = createAWTRunLoopMediator();
    InvocationEvent invocationEvent = new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(), runnable, () -> {
        if (mediator != 0) {
            stopAWTRunLoop(mediator);
        }
    }, true);
    if (!SelectorPerformer.offer(invocationEvent)) {
        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, nonBlockingRunLoop);
    if (!nonBlockingRunLoop)
        blockingRunLoopCounter.decrementAndGet();
    Throwable eventException = invocationEvent.getException();
    if (eventException != null) {
        if (eventException instanceof UndeclaredThrowableException) {
            eventException = ((UndeclaredThrowableException) eventException).getUndeclaredThrowable();
        }
        throw new InvocationTargetException(eventException);
    }
}
Also used : InvocationEvent(java.awt.event.InvocationEvent)

Example 4 with InvocationEvent

use of java.awt.event.InvocationEvent in project jdk8u_jdk by JetBrains.

the class XDecoratedPeer method handleWindowFocusIn.

public void handleWindowFocusIn(long serial) {
    if (null == actualFocusedWindow) {
        super.handleWindowFocusIn(serial);
    } else {
        /*
             * Fix for 6314575.
             * If this is a result of clicking on one of the Frame's component
             * then 'actualFocusedWindow' shouldn't be focused. A decision of focusing
             * it or not should be made after the appropriate Java mouse event (if any)
             * is handled by the component where 'actualFocusedWindow' value may be reset.
             *
             * The fix is based on the empiric fact consisting in that the component
             * receives native mouse event nearly at the same time the Frame receives
             * WM_TAKE_FOCUS (when FocusIn is generated via XSetInputFocus call) but
             * definetely before the Frame gets FocusIn event (when this method is called).
             */
        postEvent(new InvocationEvent(target, new Runnable() {

            public void run() {
                XWindowPeer fw = null;
                synchronized (getStateLock()) {
                    fw = actualFocusedWindow;
                    actualFocusedWindow = null;
                    if (null == fw || !fw.isVisible() || !fw.isFocusableWindow()) {
                        fw = XDecoratedPeer.this;
                    }
                }
                fw.handleWindowFocusIn_Dispatch();
            }
        }));
    }
}
Also used : InvocationEvent(java.awt.event.InvocationEvent)

Example 5 with InvocationEvent

use of java.awt.event.InvocationEvent in project jdk8u_jdk by JetBrains.

the class WComponentPeer method replaceSurfaceDataLater.

public void replaceSurfaceDataLater() {
    Runnable r = new Runnable() {

        @Override
        public void run() {
            // on EDT
            if (!isDisposed()) {
                try {
                    replaceSurfaceData();
                } catch (InvalidPipeException e) {
                // REMIND : what do we do if our surface creation failed?
                }
            }
        }
    };
    Component c = (Component) target;
    // Fix 6255371.
    if (!PaintEventDispatcher.getPaintEventDispatcher().queueSurfaceDataReplacing(c, r)) {
        postEvent(new InvocationEvent(c, r));
    }
}
Also used : InvalidPipeException(sun.java2d.InvalidPipeException) InvocationEvent(java.awt.event.InvocationEvent)

Aggregations

InvocationEvent (java.awt.event.InvocationEvent)8 IdeEventQueue (com.intellij.ide.IdeEventQueue)1 SystemTray (java.awt.SystemTray)1 TrayIcon (java.awt.TrayIcon)1 Window (java.awt.Window)1 PropertyChangeSupport (java.beans.PropertyChangeSupport)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 AppContext (sun.awt.AppContext)1 InvalidPipeException (sun.java2d.InvalidPipeException)1