Java Code Examples for java.awt.event.InvocationEvent

The following are top voted examples for showing how to use java.awt.event.InvocationEvent. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: incubator-netbeans   File: EventLock.java   View source code 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 2
Project: OpenJSharp   File: LWCToolkit.java   View source code 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
Project: OpenJSharp   File: WEmbeddedFrame.java   View source code 6 votes vote down vote up
@SuppressWarnings("deprecation")
public void synthesizeWindowActivation(final boolean activate) {
    if (!activate || EventQueue.isDispatchThread()) {
        ((WFramePeer)getPeer()).emulateActivation(activate);
    } else {
        // To avoid focus concurrence b/w IE and EmbeddedFrame
        // activation is postponed by means of posting it to EDT.
        Runnable r = new Runnable() {
            public void run() {
                ((WFramePeer)getPeer()).emulateActivation(true);
            }
        };
        WToolkit.postEvent(WToolkit.targetToAppContext(this),
                           new InvocationEvent(this, r));
    }
}
 
Example 4
Project: OpenJSharp   File: WComponentPeer.java   View source code 6 votes vote down vote up
public void replaceSurfaceDataLater() {
    Runnable r = new Runnable() {
        @Override
        public void run() {
            // Shouldn't do anything if object is disposed in meanwhile
            // No need for sync as disposeAction in Window is performed
            // 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));
    }
}
 
Example 5
Project: jdk8u-jdk   File: LWCToolkit.java   View source code 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
Project: jdk8u-jdk   File: WEmbeddedFrame.java   View source code 6 votes vote down vote up
@SuppressWarnings("deprecation")
public void synthesizeWindowActivation(final boolean activate) {
    if (!activate || EventQueue.isDispatchThread()) {
        ((WFramePeer)getPeer()).emulateActivation(activate);
    } else {
        // To avoid focus concurrence b/w IE and EmbeddedFrame
        // activation is postponed by means of posting it to EDT.
        Runnable r = new Runnable() {
            public void run() {
                ((WFramePeer)getPeer()).emulateActivation(true);
            }
        };
        WToolkit.postEvent(WToolkit.targetToAppContext(this),
                           new InvocationEvent(this, r));
    }
}
 
Example 7
Project: jdk8u-jdk   File: WComponentPeer.java   View source code 6 votes vote down vote up
public void replaceSurfaceDataLater() {
    Runnable r = new Runnable() {
        @Override
        public void run() {
            // Shouldn't do anything if object is disposed in meanwhile
            // No need for sync as disposeAction in Window is performed
            // 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));
    }
}
 
Example 8
Project: openjdk-jdk10   File: LWCToolkit.java   View source code 6 votes vote down vote up
/**
 * Kicks an event over to the appropriate event queue 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
 * run loop. Does not dispatch native events while in the loop
 */
public static void invokeAndWait(Runnable runnable, Component component)
        throws InvocationTargetException {
    Objects.requireNonNull(component, "Null component provided to invokeAndWait");

    long mediator = createAWTRunLoopMediator();
    InvocationEvent invocationEvent =
            new InvocationEvent(component,
                    runnable,
                    () -> {
                        if (mediator != 0) {
                            stopAWTRunLoop(mediator);
                        }
                    },
                    true);

    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);
    doAWTRunLoop(mediator, false);

    checkException(invocationEvent);
}
 
Example 9
Project: openjdk-jdk10   File: WEmbeddedFrame.java   View source code 6 votes vote down vote up
public void synthesizeWindowActivation(final boolean activate) {
    final FramePeer peer = AWTAccessor.getComponentAccessor().getPeer(this);
    if (!activate || EventQueue.isDispatchThread()) {
        peer.emulateActivation(activate);
    } else {
        // To avoid focus concurrence b/w IE and EmbeddedFrame
        // activation is postponed by means of posting it to EDT.
        Runnable r = new Runnable() {
            public void run() {
                peer.emulateActivation(true);
            }
        };
        WToolkit.postEvent(WToolkit.targetToAppContext(this),
                           new InvocationEvent(this, r));
    }
}
 
Example 10
Project: openjdk-jdk10   File: WComponentPeer.java   View source code 6 votes vote down vote up
public void replaceSurfaceDataLater() {
    Runnable r = new Runnable() {
        @Override
        public void run() {
            // Shouldn't do anything if object is disposed in meanwhile
            // No need for sync as disposeAction in Window is performed
            // 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));
    }
}
 
Example 11
Project: openjdk9   File: LWCToolkit.java   View source code 6 votes vote down vote up
/**
 * Kicks an event over to the appropriate event queue 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
 * run loop. Does not dispatch native events while in the loop
 */
public static void invokeAndWait(Runnable runnable, Component component)
        throws InvocationTargetException {
    Objects.requireNonNull(component, "Null component provided to invokeAndWait");

    long mediator = createAWTRunLoopMediator();
    InvocationEvent invocationEvent =
            new InvocationEvent(component,
                    runnable,
                    () -> {
                        if (mediator != 0) {
                            stopAWTRunLoop(mediator);
                        }
                    },
                    true);

    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);
    doAWTRunLoop(mediator, false);

    checkException(invocationEvent);
}
 
Example 12
Project: openjdk9   File: WEmbeddedFrame.java   View source code 6 votes vote down vote up
public void synthesizeWindowActivation(final boolean activate) {
    final FramePeer peer = AWTAccessor.getComponentAccessor().getPeer(this);
    if (!activate || EventQueue.isDispatchThread()) {
        peer.emulateActivation(activate);
    } else {
        // To avoid focus concurrence b/w IE and EmbeddedFrame
        // activation is postponed by means of posting it to EDT.
        Runnable r = new Runnable() {
            public void run() {
                peer.emulateActivation(true);
            }
        };
        WToolkit.postEvent(WToolkit.targetToAppContext(this),
                           new InvocationEvent(this, r));
    }
}
 
Example 13
Project: openjdk9   File: WComponentPeer.java   View source code 6 votes vote down vote up
public void replaceSurfaceDataLater() {
    Runnable r = new Runnable() {
        @Override
        public void run() {
            // Shouldn't do anything if object is disposed in meanwhile
            // No need for sync as disposeAction in Window is performed
            // 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));
    }
}
 
Example 14
Project: jdk8u_jdk   File: LWCToolkit.java   View source code 6 votes vote down vote up
/**
 * Checks if there's an active SelectorPerformer corresponding to the invocation's AppContext,
 * adds the invocation to the SelectorPerformer's queue and returns true.
 * Otherwise does nothing and returns false.
 */
public static boolean offer(InvocationEvent invocation) {
    Object source = invocation.getSource();

    SelectorPerformer performer = (source instanceof Component) ?
            getInstance((Component)source) :
            getInstance(Toolkit.getDefaultToolkit().getSystemEventQueue());

    if (performer == null) return false;

    synchronized (performer.invocations) {
        if (!performer.invocations.isEmpty()) {
            performer.invocations.peek().add(invocation);
            return true;
        }
    }
    return false;
}
 
Example 15
Project: jdk8u_jdk   File: LWCToolkit.java   View source code 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 16
Project: jdk8u_jdk   File: WEmbeddedFrame.java   View source code 6 votes vote down vote up
@SuppressWarnings("deprecation")
public void synthesizeWindowActivation(final boolean activate) {
    if (!activate || EventQueue.isDispatchThread()) {
        ((WFramePeer)getPeer()).emulateActivation(activate);
    } else {
        // To avoid focus concurrence b/w IE and EmbeddedFrame
        // activation is postponed by means of posting it to EDT.
        Runnable r = new Runnable() {
            public void run() {
                ((WFramePeer)getPeer()).emulateActivation(true);
            }
        };
        WToolkit.postEvent(WToolkit.targetToAppContext(this),
                           new InvocationEvent(this, r));
    }
}
 
Example 17
Project: jdk8u_jdk   File: WComponentPeer.java   View source code 6 votes vote down vote up
public void replaceSurfaceDataLater() {
    Runnable r = new Runnable() {
        @Override
        public void run() {
            // Shouldn't do anything if object is disposed in meanwhile
            // No need for sync as disposeAction in Window is performed
            // 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));
    }
}
 
Example 18
Project: lookaside_java-1.8.0-openjdk   File: LWCToolkit.java   View source code 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 19
Project: lookaside_java-1.8.0-openjdk   File: WEmbeddedFrame.java   View source code 6 votes vote down vote up
@SuppressWarnings("deprecation")
public void synthesizeWindowActivation(final boolean activate) {
    if (!activate || EventQueue.isDispatchThread()) {
        ((WFramePeer)getPeer()).emulateActivation(activate);
    } else {
        // To avoid focus concurrence b/w IE and EmbeddedFrame
        // activation is postponed by means of posting it to EDT.
        Runnable r = new Runnable() {
            public void run() {
                ((WFramePeer)getPeer()).emulateActivation(true);
            }
        };
        WToolkit.postEvent(WToolkit.targetToAppContext(this),
                           new InvocationEvent(this, r));
    }
}
 
Example 20
Project: lookaside_java-1.8.0-openjdk   File: WComponentPeer.java   View source code 6 votes vote down vote up
public void replaceSurfaceDataLater() {
    Runnable r = new Runnable() {
        @Override
        public void run() {
            // Shouldn't do anything if object is disposed in meanwhile
            // No need for sync as disposeAction in Window is performed
            // 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));
    }
}
 
Example 21
Project: javify   File: EventQueue.java   View source code 6 votes vote down vote up
/**
 * Causes runnable to have its run method called in the dispatch thread of the
 * EventQueue. This will happen after all pending events are processed. The
 * call blocks until this has happened. This method will throw an Error if
 * called from the event dispatcher thread.
 *
 * @exception InterruptedException If another thread has interrupted
 * this thread.
 * @exception InvocationTargetException If an exception is thrown when running
 * runnable.
 *
 * @since 1.2
 */
public static void invokeAndWait(Runnable runnable)
  throws InterruptedException, InvocationTargetException
{
  if (isDispatchThread ())
    throw new Error("Can't call invokeAndWait from event dispatch thread");

  EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
  Object notifyObject = new Object();

  InvocationEvent ie =
    new InvocationEvent(eq, runnable, notifyObject, true);

  synchronized (notifyObject)
    {
      eq.postEvent(ie);
      notifyObject.wait();
    }

  Exception exception;

  if ((exception = ie.getException()) != null)
    throw new InvocationTargetException(exception);
}
 
Example 22
Project: jvm-stm   File: EventQueue.java   View source code 6 votes vote down vote up
/**
 * Causes runnable to have its run method called in the dispatch thread of the
 * EventQueue. This will happen after all pending events are processed. The
 * call blocks until this has happened. This method will throw an Error if
 * called from the event dispatcher thread.
 *
 * @exception InterruptedException If another thread has interrupted
 * this thread.
 * @exception InvocationTargetException If an exception is thrown when running
 * runnable.
 *
 * @since 1.2
 */
public static void invokeAndWait(Runnable runnable)
  throws InterruptedException, InvocationTargetException
{
  if (isDispatchThread ())
    throw new Error("Can't call invokeAndWait from event dispatch thread");

  EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); 
  Object notifyObject = new Object();

  InvocationEvent ie =
    new InvocationEvent(eq, runnable, notifyObject, true);

  synchronized (notifyObject)
    {
      eq.postEvent(ie);
      notifyObject.wait();
    }

  Exception exception;

  if ((exception = ie.getException()) != null)
    throw new InvocationTargetException(exception);
}
 
Example 23
Project: VarJ   File: EventQueue.java   View source code 6 votes vote down vote up
/**
    * Causes <code>runnable</code> to have its <code>run</code>
    * method called in the dispatch thread of
    * {@link Toolkit#getSystemEventQueue the system EventQueue}.
    * This will happen after all pending events are processed.
    * The call blocks until this has happened.  This method
    * will throw an Error if called from the event dispatcher thread.
    *
    * @param runnable  the <code>Runnable</code> whose <code>run</code>
    *                  method should be executed
    *                  synchronously on the <code>EventQueue</code>
    * @exception       InterruptedException  if any thread has
    *                  interrupted this thread
    * @exception       InvocationTargetException  if an throwable is thrown
    *                  when running <code>runnable</code>
    * @see             #invokeLater
    * @since           1.2
    */
   public static void invokeAndWait(Runnable runnable)
            throws InterruptedException, InvocationTargetException {

       if (EventQueue.isDispatchThread()) {
           throw new Error("Cannot call invokeAndWait from the event dispatcher thread");
       }

class AWTInvocationLock {}
       Object lock = new AWTInvocationLock();

       InvocationEvent event = 
           new InvocationEvent(Toolkit.getDefaultToolkit(), runnable, lock,
			true);

       synchronized (lock) {
           Toolkit.getEventQueue().postEvent(event);
           lock.wait();
       }

       Throwable eventThrowable = event.getThrowable();
       if (eventThrowable != null) {
           throw new InvocationTargetException(eventThrowable);
       }
   }
 
Example 24
Project: infobip-open-jdk-8   File: LWCToolkit.java   View source code 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 25
Project: infobip-open-jdk-8   File: WEmbeddedFrame.java   View source code 6 votes vote down vote up
@SuppressWarnings("deprecation")
public void synthesizeWindowActivation(final boolean activate) {
    if (!activate || EventQueue.isDispatchThread()) {
        ((WFramePeer)getPeer()).emulateActivation(activate);
    } else {
        // To avoid focus concurrence b/w IE and EmbeddedFrame
        // activation is postponed by means of posting it to EDT.
        Runnable r = new Runnable() {
            public void run() {
                ((WFramePeer)getPeer()).emulateActivation(true);
            }
        };
        WToolkit.postEvent(WToolkit.targetToAppContext(this),
                           new InvocationEvent(this, r));
    }
}
 
Example 26
Project: infobip-open-jdk-8   File: WComponentPeer.java   View source code 6 votes vote down vote up
public void replaceSurfaceDataLater() {
    Runnable r = new Runnable() {
        @Override
        public void run() {
            // Shouldn't do anything if object is disposed in meanwhile
            // No need for sync as disposeAction in Window is performed
            // 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));
    }
}
 
Example 27
Project: jdk8u-dev-jdk   File: LWCToolkit.java   View source code 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 28
Project: jdk8u-dev-jdk   File: WEmbeddedFrame.java   View source code 6 votes vote down vote up
@SuppressWarnings("deprecation")
public void synthesizeWindowActivation(final boolean activate) {
    if (!activate || EventQueue.isDispatchThread()) {
        ((WFramePeer)getPeer()).emulateActivation(activate);
    } else {
        // To avoid focus concurrence b/w IE and EmbeddedFrame
        // activation is postponed by means of posting it to EDT.
        Runnable r = new Runnable() {
            public void run() {
                ((WFramePeer)getPeer()).emulateActivation(true);
            }
        };
        WToolkit.postEvent(WToolkit.targetToAppContext(this),
                           new InvocationEvent(this, r));
    }
}
 
Example 29
Project: jdk8u-dev-jdk   File: WComponentPeer.java   View source code 6 votes vote down vote up
public void replaceSurfaceDataLater() {
    Runnable r = new Runnable() {
        @Override
        public void run() {
            // Shouldn't do anything if object is disposed in meanwhile
            // No need for sync as disposeAction in Window is performed
            // 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));
    }
}
 
Example 30
Project: jdk7-jdk   File: WComponentPeer.java   View source code 6 votes vote down vote up
public void replaceSurfaceDataLater() {
    Runnable r = new Runnable() {
        public void run() {
            // Shouldn't do anything if object is disposed in meanwhile
            // No need for sync as disposeAction in Window is performed
            // on EDT
            if (!isDisposed()) {
                try {
                    replaceSurfaceData();
                } catch (InvalidPipeException e) {
                // REMIND : what do we do if our surface creation failed?
                }
            }
        }
    };
    // Fix 6255371.
    if (!PaintEventDispatcher.getPaintEventDispatcher().queueSurfaceDataReplacing((Component)target, r)) {
        postEvent(new InvocationEvent(Toolkit.getDefaultToolkit(), r));
    }
}
 
Example 31
Project: jdk7-jdk   File: XComponentPeer.java   View source code 6 votes vote down vote up
public void handleButtonPressRelease(XEvent xev) {
    /*
     * Fix for 6385277.
     * We request focus on simple Window by click in order
     * to make it behave like Frame/Dialog in this case and also to unify
     * the behaviour with what we have on MS Windows.
     * handleJavaMouseEvent() would be more suitable place to do this
     * but we want Swing to have this functionality also.
     */
    if (xev.get_type() == XConstants.ButtonPress) {
        final XWindowPeer parentXWindow = getParentTopLevel();
        Window parentWindow = (Window)parentXWindow.getTarget();
        if (parentXWindow.isFocusableWindow() && parentXWindow.isSimpleWindow() &&
            XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow() != parentWindow)
        {
            postEvent(new InvocationEvent(parentWindow, new  Runnable() {
                    public void run() {
                        // Request focus on the EDT of 'parentWindow' because
                        // XDecoratedPeer.requestWindowFocus() calls client code.
                        parentXWindow.requestXFocus();
                    }
                }));
        }
    }
    super.handleButtonPressRelease(xev);
}
 
Example 32
Project: openjdk-source-code-learn   File: WComponentPeer.java   View source code 6 votes vote down vote up
public void replaceSurfaceDataLater() {
    Runnable r = new Runnable() {
        public void run() {
            // Shouldn't do anything if object is disposed in meanwhile
            // No need for sync as disposeAction in Window is performed
            // on EDT
            if (!isDisposed()) {
                try {
                    replaceSurfaceData();
                } catch (InvalidPipeException e) {
                // REMIND : what do we do if our surface creation failed?
                }
            }
        }
    };
    // Fix 6255371.
    if (!PaintEventDispatcher.getPaintEventDispatcher().queueSurfaceDataReplacing((Component)target, r)) {
        postEvent(new InvocationEvent(Toolkit.getDefaultToolkit(), r));
    }
}
 
Example 33
Project: openjdk-source-code-learn   File: XComponentPeer.java   View source code 6 votes vote down vote up
public void handleButtonPressRelease(XEvent xev) {
    /*
     * Fix for 6385277.
     * We request focus on simple Window by click in order
     * to make it behave like Frame/Dialog in this case and also to unify
     * the behaviour with what we have on MS Windows.
     * handleJavaMouseEvent() would be more suitable place to do this
     * but we want Swing to have this functionality also.
     */
    if (xev.get_type() == XConstants.ButtonPress) {
        final XWindowPeer parentXWindow = getParentTopLevel();
        Window parentWindow = (Window)parentXWindow.getTarget();
        if (parentXWindow.isFocusableWindow() && parentXWindow.isSimpleWindow() &&
            XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow() != parentWindow)
        {
            postEvent(new InvocationEvent(parentWindow, new  Runnable() {
                    public void run() {
                        // Request focus on the EDT of 'parentWindow' because
                        // XDecoratedPeer.requestWindowFocus() calls client code.
                        parentXWindow.requestXFocus();
                    }
                }));
        }
    }
    super.handleButtonPressRelease(xev);
}
 
Example 34
Project: OLD-OpenJDK8   File: LWCToolkit.java   View source code 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 35
Project: OLD-OpenJDK8   File: WEmbeddedFrame.java   View source code 6 votes vote down vote up
@SuppressWarnings("deprecation")
public void synthesizeWindowActivation(final boolean activate) {
    if (!activate || EventQueue.isDispatchThread()) {
        ((WFramePeer)getPeer()).emulateActivation(activate);
    } else {
        // To avoid focus concurrence b/w IE and EmbeddedFrame
        // activation is postponed by means of posting it to EDT.
        Runnable r = new Runnable() {
            public void run() {
                ((WFramePeer)getPeer()).emulateActivation(true);
            }
        };
        WToolkit.postEvent(WToolkit.targetToAppContext(this),
                           new InvocationEvent(this, r));
    }
}
 
Example 36
Project: OLD-OpenJDK8   File: WComponentPeer.java   View source code 6 votes vote down vote up
public void replaceSurfaceDataLater() {
    Runnable r = new Runnable() {
        public void run() {
            // Shouldn't do anything if object is disposed in meanwhile
            // No need for sync as disposeAction in Window is performed
            // 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));
    }
}
 
Example 37
Project: cn1   File: EventQueueCore.java   View source code 6 votes vote down vote up
private void updateCurrentEventAndTime(AWTEvent event) {
    currentEvent = event;
    long when = 0;
    if (event instanceof ActionEvent) {
        when = ((ActionEvent) event).getWhen();
    } else if (event instanceof InputEvent) {
        when = ((InputEvent) event).getWhen();
    } else if (event instanceof InputMethodEvent) {
        when = ((InputMethodEvent) event).getWhen();
    } else if (event instanceof InvocationEvent) {
        when = ((InvocationEvent) event).getWhen();
    }
    if (when != 0) {
        mostRecentEventTime = when;
    }
}
 
Example 38
Project: cn1   File: Component.java   View source code 6 votes vote down vote up
/**
 * Set native caret at the given position <br>
 * Note: this method takes AWT lock inside because it walks through the
 * component hierarchy
 */
void setCaretPos(final int x, final int y) {
    Runnable r = new Runnable() {
        public void run() {
            toolkit.lockAWT();
            try {
                setCaretPosImpl(x, y);
            } finally {
                toolkit.unlockAWT();
            }
        }
    };
    if (Thread.currentThread() instanceof EventDispatchThread) {
        r.run();
    } else {
        toolkit.getSystemEventQueueImpl().postEvent(new InvocationEvent(this, r));
    }
}
 
Example 39
Project: cn1   File: EventQueue.java   View source code 6 votes vote down vote up
public static void invokeAndWait(Runnable runnable)
        throws InterruptedException, InvocationTargetException {

    if (isDispatchThread()) {
        throw new Error();
    }

    final Toolkit toolkit = Toolkit.getDefaultToolkit();
    final Object notifier = new Object();  //$NON-LOCK-1$
    InvocationEvent event = new InvocationEvent(
            toolkit, runnable, notifier, true);

    synchronized (notifier) {
        toolkit.getSystemEventQueueImpl().postEvent(event);
        notifier.wait();
    }

    Exception exception = event.getException();

    if (exception != null) {
        throw new InvocationTargetException(exception);
    }
}
 
Example 40
Project: cn1   File: ScrollPaneAdjustable.java   View source code 6 votes vote down vote up
private void postAdjustmentEvent(final int type) {
    // create and post invocation event here:
    comp.postEvent(new InvocationEvent(ScrollPaneAdjustable.this, new Runnable() {
        public void run() {
            AdjustmentEvent event = new AdjustmentEvent(ScrollPaneAdjustable.this,
                    AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED, type, value,
                    getValueIsAdjusting());
            if (callAWTListener) {
                comp.toolkit.lockAWT();
                try {
                    processAdjustmentEvent(event, adjustmentListeners.getSystemListeners());
                } finally {
                    comp.toolkit.unlockAWT();
                }
            }
            processAdjustmentEvent(event, adjustmentListeners.getUserListeners());
        }
    }));
}