Java Code Examples for sun.awt.SunToolkit#postEvent()

The following examples show how to use sun.awt.SunToolkit#postEvent() . 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: Container.java    From jdk-1.7-annotated with Apache License 2.0 6 votes vote down vote up
private void stopLWModal() {
    synchronized (getTreeLock()) {
        if (modalAppContext != null) {
            Container nativeContainer = getHeavyweightContainer();
            if(nativeContainer != null) {
                if (this.modalComp !=  null) {
                    nativeContainer.modalComp = this.modalComp;
                    this.modalComp = null;
                    return;
                }
                else {
                    nativeContainer.modalComp = null;
                }
            }
            // Wake up event dispatch thread on which the dialog was
            // initially shown
            SunToolkit.postEvent(modalAppContext,
                    new PeerEvent(this,
                            new WakingRunnable(),
                            PeerEvent.PRIORITY_EVENT));
        }
        EventQueue.invokeLater(new WakingRunnable());
        getTreeLock().notifyAll();
    }
}
 
Example 2
Source File: Container.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void stopLWModal() {
    synchronized (getTreeLock()) {
        if (modalAppContext != null) {
            Container nativeContainer = getHeavyweightContainer();
            if(nativeContainer != null) {
                if (this.modalComp !=  null) {
                    nativeContainer.modalComp = this.modalComp;
                    this.modalComp = null;
                    return;
                }
                else {
                    nativeContainer.modalComp = null;
                }
            }
            // Wake up event dispatch thread on which the dialog was
            // initially shown
            SunToolkit.postEvent(modalAppContext,
                    new PeerEvent(this,
                            new WakingRunnable(),
                            PeerEvent.PRIORITY_EVENT));
        }
        EventQueue.invokeLater(new WakingRunnable());
        getTreeLock().notifyAll();
    }
}
 
Example 3
Source File: DefaultKeyboardFocusManager.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private boolean repostIfFollowsKeyEvents(WindowEvent e) {
    if (!(e instanceof TimedWindowEvent)) {
        return false;
    }
    TimedWindowEvent we = (TimedWindowEvent)e;
    long time = we.getWhen();
    synchronized (this) {
        KeyEvent ke = enqueuedKeyEvents.isEmpty() ? null : enqueuedKeyEvents.getFirst();
        if (ke != null && time >= ke.getWhen()) {
            TypeAheadMarker marker = typeAheadMarkers.isEmpty() ? null : typeAheadMarkers.getFirst();
            if (marker != null) {
                Window toplevel = marker.untilFocused.getContainingWindow();
                // Check that the component awaiting focus belongs to
                // the current focused window. See 8015454.
                if (toplevel != null && toplevel.isFocused()) {
                    SunToolkit.postEvent(AppContext.getAppContext(), new SequencedEvent(e));
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 4
Source File: ExecutableInputMethodManager.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 5
Source File: SentEvent.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void dispatch() {
    try {
        if (nested != null) {
            Toolkit.getEventQueue().dispatchEvent(nested);
        }
    } finally {
        dispatched = true;
        if (toNotify != null) {
            SunToolkit.postEvent(toNotify, new SentEvent());
        }
        synchronized (this) {
            notifyAll();
        }
    }
}
 
Example 6
Source File: PostEventOrderingTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    EventQueue q = Toolkit.getDefaultToolkit().getSystemEventQueue();
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            q.postEvent(new PostActionEvent());
            for (int k = 0; k < 10; k++) {
                SunToolkit.postEvent(AppContext.getAppContext(), new PostActionEvent());
            }
        }
        for (int k = 0; k < 100; k++) {
            SunToolkit.postEvent(AppContext.getAppContext(), new PostActionEvent());
        }
    }

    for (;;) {
        Thread.currentThread().sleep(100);
        if (q.peekEvent() == null) {
            Thread.currentThread().sleep(100);
            if (q.peekEvent() == null)
                break;
        }
    }

    if (!testPassed) {
        throw new Exception("PostEventOrderingTest FAILED -- events dispatched out of order.");
    } else {
        System.out.println("PostEventOrderingTest passed!");
    }
}
 
Example 7
Source File: SentEvent.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
final void dispose() {
    dispatched = true;
    if (toNotify != null) {
        SunToolkit.postEvent(toNotify, new SentEvent());
    }
    synchronized (this) {
        notifyAll();
    }
}
 
Example 8
Source File: ExecutableInputMethodManager.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 9
Source File: CCheckboxMenuItem.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void handleAction(final boolean state) {
    final CheckboxMenuItem target = (CheckboxMenuItem)getTarget();
    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
        public void run() {
            target.setState(state);
        }
    });
    ItemEvent event = new ItemEvent(target, ItemEvent.ITEM_STATE_CHANGED, target.getLabel(), state ? ItemEvent.SELECTED : ItemEvent.DESELECTED);
    SunToolkit.postEvent(SunToolkit.targetToAppContext(getTarget()), event);
}
 
Example 10
Source File: DefaultKeyboardFocusManager.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sends a synthetic AWTEvent to a Component. If the Component is in
 * the current AppContext, then the event is immediately dispatched.
 * If the Component is in a different AppContext, then the event is
 * posted to the other AppContext's EventQueue, and this method blocks
 * until the event is handled or target AppContext is disposed.
 * Returns true if successfuly dispatched event, false if failed
 * to dispatch.
 */
static boolean sendMessage(Component target, AWTEvent e) {
    e.isPosted = true;
    AppContext myAppContext = AppContext.getAppContext();
    final AppContext targetAppContext = target.appContext;
    final SentEvent se =
        new DefaultKeyboardFocusManagerSentEvent(e, myAppContext);

    if (myAppContext == targetAppContext) {
        se.dispatch();
    } else {
        if (targetAppContext.isDisposed()) {
            return false;
        }
        SunToolkit.postEvent(targetAppContext, se);
        if (EventQueue.isDispatchThread()) {
            EventDispatchThread edt = (EventDispatchThread)
                Thread.currentThread();
            edt.pumpEvents(SentEvent.ID, new Conditional() {
                    public boolean evaluate() {
                        return !se.dispatched && !targetAppContext.isDisposed();
                    }
                });
        } else {
            synchronized (se) {
                while (!se.dispatched && !targetAppContext.isDisposed()) {
                    try {
                        se.wait(1000);
                    } catch (InterruptedException ie) {
                        break;
                    }
                }
            }
        }
    }
    return se.dispatched;
}
 
Example 11
Source File: CCheckboxMenuItem.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void handleAction(final boolean state) {
    final CheckboxMenuItem target = (CheckboxMenuItem)getTarget();
    SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
        public void run() {
            target.setState(state);
        }
    });
    ItemEvent event = new ItemEvent(target, ItemEvent.ITEM_STATE_CHANGED, target.getLabel(), state ? ItemEvent.SELECTED : ItemEvent.DESELECTED);
    SunToolkit.postEvent(SunToolkit.targetToAppContext(getTarget()), event);
}
 
Example 12
Source File: Toolkit.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void firePropertyChange(final PropertyChangeEvent evt) {
    Object oldValue = evt.getOldValue();
    Object newValue = evt.getNewValue();
    String propertyName = evt.getPropertyName();
    if (oldValue != null && newValue != null && oldValue.equals(newValue)) {
        return;
    }
    Runnable updater = new Runnable() {
        public void run() {
            PropertyChangeSupport pcs = (PropertyChangeSupport)
                    AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
            if (null != pcs) {
                pcs.firePropertyChange(evt);
            }
        }
    };
    final AppContext currentAppContext = AppContext.getAppContext();
    for (AppContext appContext : AppContext.getAppContexts()) {
        if (null == appContext || appContext.isDisposed()) {
            continue;
        }
        if (currentAppContext == appContext) {
            updater.run();
        } else {
            final PeerEvent e = new PeerEvent(source, updater, PeerEvent.ULTIMATE_PRIORITY_EVENT);
            SunToolkit.postEvent(appContext, e);
        }
    }
}
 
Example 13
Source File: PushPopTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
        frame = new Frame("");
        frame.pack();

        Runnable dummy = new Runnable() {
                public void run() {
                    System.err.println("Dummy is here.");
                    System.err.flush();
                }
            };
        EventQueue seq = Toolkit.getDefaultToolkit().getSystemEventQueue();
        MyEventQueue1 eq1 = new MyEventQueue1();
        MyEventQueue2 eq2 = new MyEventQueue2();
        EventQueue.invokeLater(dummy);

        seq.push(eq1);
        EventQueue.invokeLater(dummy);

        eq1.push(eq2);
        EventQueue.invokeLater(dummy);
        Runnable runnable = new Runnable() {
                public void run() {
                    System.err.println("Dummy from SunToolkit");
                    System.err.flush();
                }
            };
        InvocationEvent ie = new InvocationEvent(eq2, runnable, null, false);
//        System.err.println(ie);
        SunToolkit.postEvent(SunToolkit.targetToAppContext(frame), ie);
        eq1.pop();
        frame.dispose();
    }
 
Example 14
Source File: DefaultKeyboardFocusManager.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sends a synthetic AWTEvent to a Component. If the Component is in
 * the current AppContext, then the event is immediately dispatched.
 * If the Component is in a different AppContext, then the event is
 * posted to the other AppContext's EventQueue, and this method blocks
 * until the event is handled or target AppContext is disposed.
 * Returns true if successfuly dispatched event, false if failed
 * to dispatch.
 */
static boolean sendMessage(Component target, AWTEvent e) {
    e.isPosted = true;
    AppContext myAppContext = AppContext.getAppContext();
    final AppContext targetAppContext = target.appContext;
    final SentEvent se =
        new DefaultKeyboardFocusManagerSentEvent(e, myAppContext);

    if (myAppContext == targetAppContext) {
        se.dispatch();
    } else {
        if (targetAppContext.isDisposed()) {
            return false;
        }
        SunToolkit.postEvent(targetAppContext, se);
        if (EventQueue.isDispatchThread()) {
            EventDispatchThread edt = (EventDispatchThread)
                Thread.currentThread();
            edt.pumpEvents(SentEvent.ID, new Conditional() {
                    public boolean evaluate() {
                        return !se.dispatched && !targetAppContext.isDisposed();
                    }
                });
        } else {
            synchronized (se) {
                while (!se.dispatched && !targetAppContext.isDisposed()) {
                    try {
                        se.wait(1000);
                    } catch (InterruptedException ie) {
                        break;
                    }
                }
            }
        }
    }
    return se.dispatched;
}
 
Example 15
Source File: SentEvent.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void dispatch() {
    try {
        if (nested != null) {
            Toolkit.getEventQueue().dispatchEvent(nested);
        }
    } finally {
        dispatched = true;
        if (toNotify != null) {
            SunToolkit.postEvent(toNotify, new SentEvent());
        }
        synchronized (this) {
            notifyAll();
        }
    }
}
 
Example 16
Source File: SentEvent.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void dispatch() {
    try {
        if (nested != null) {
            Toolkit.getEventQueue().dispatchEvent(nested);
        }
    } finally {
        dispatched = true;
        if (toNotify != null) {
            SunToolkit.postEvent(toNotify, new SentEvent());
        }
        synchronized (this) {
            notifyAll();
        }
    }
}
 
Example 17
Source File: ExecutableInputMethodManager.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 18
Source File: Toolkit.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
@Override
public void firePropertyChange(final PropertyChangeEvent evt) {
    Object oldValue = evt.getOldValue();
    Object newValue = evt.getNewValue();
    String propertyName = evt.getPropertyName();
    if (oldValue != null && newValue != null && oldValue.equals(newValue)) {
        return;
    }
    Runnable updater = new Runnable() {
        public void run() {
            PropertyChangeSupport pcs = (PropertyChangeSupport)
                    AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
            if (null != pcs) {
                pcs.firePropertyChange(evt);
            }
        }
    };
    final AppContext currentAppContext = AppContext.getAppContext();
    for (AppContext appContext : AppContext.getAppContexts()) {
        if (null == appContext || appContext.isDisposed()) {
            continue;
        }
        if (currentAppContext == appContext) {
            updater.run();
        } else {
            final PeerEvent e = new PeerEvent(source, updater, PeerEvent.ULTIMATE_PRIORITY_EVENT);
            SunToolkit.postEvent(appContext, e);
        }
    }
}
 
Example 19
Source File: SunClipboard.java    From jdk8u_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Clears the clipboard state (contents, owner and contents context) and
 * notifies the current owner that ownership is lost. Does nothing if the
 * argument is not <code>null</code> and is not equal to the current
 * contents context.
 *
 * @param disposedContext the AppContext that is disposed or
 *        <code>null</code> if the ownership is lost because another
 *        application acquired ownership.
 */
protected void lostOwnershipLater(final AppContext disposedContext) {
    final AppContext context = this.contentsContext;
    if (context == null) {
        return;
    }

    SunToolkit.postEvent(context, new PeerEvent(this, () -> lostOwnershipNow(disposedContext),
                                                PeerEvent.PRIORITY_EVENT));
}
 
Example 20
Source File: SunClipboard.java    From jdk8u-dev-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Clears the clipboard state (contents, owner and contents context) and
 * notifies the current owner that ownership is lost. Does nothing if the
 * argument is not <code>null</code> and is not equal to the current
 * contents context.
 *
 * @param disposedContext the AppContext that is disposed or
 *        <code>null</code> if the ownership is lost because another
 *        application acquired ownership.
 */
protected void lostOwnershipLater(final AppContext disposedContext) {
    final AppContext context = this.contentsContext;
    if (context == null) {
        return;
    }

    SunToolkit.postEvent(context, new PeerEvent(this, () -> lostOwnershipNow(disposedContext),
                                                PeerEvent.PRIORITY_EVENT));
}