Java Code Examples for sun.awt.AppContext#isDisposed()

The following examples show how to use sun.awt.AppContext#isDisposed() . 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: SunClipboard.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private synchronized void initContext() {
    final AppContext context = AppContext.getAppContext();

    if (contentsContext != context) {
        // Need to synchronize on the AppContext to guarantee that it cannot
        // be disposed after the check, but before the listener is added.
        synchronized (context) {
            if (context.isDisposed()) {
                throw new IllegalStateException("Can't set contents from disposed AppContext");
            }
            context.addPropertyChangeListener
                (AppContext.DISPOSED_PROPERTY_NAME, this);
        }
        if (contentsContext != null) {
            contentsContext.removePropertyChangeListener
                (AppContext.DISPOSED_PROPERTY_NAME, this);
        }
        contentsContext = context;
    }
}
 
Example 2
Source File: SunClipboard.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
private synchronized void initContext() {
    final AppContext context = AppContext.getAppContext();

    if (contentsContext != context) {
        // Need to synchronize on the AppContext to guarantee that it cannot
        // be disposed after the check, but before the listener is added.
        synchronized (context) {
            if (context.isDisposed()) {
                throw new IllegalStateException("Can't set contents from disposed AppContext");
            }
            context.addPropertyChangeListener
                (AppContext.DISPOSED_PROPERTY_NAME, this);
        }
        if (contentsContext != null) {
            contentsContext.removePropertyChangeListener
                (AppContext.DISPOSED_PROPERTY_NAME, this);
        }
        contentsContext = context;
    }
}
 
Example 3
Source File: SunClipboard.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private synchronized void initContext() {
    final AppContext context = AppContext.getAppContext();

    if (contentsContext != context) {
        // Need to synchronize on the AppContext to guarantee that it cannot
        // be disposed after the check, but before the listener is added.
        synchronized (context) {
            if (context.isDisposed()) {
                throw new IllegalStateException("Can't set contents from disposed AppContext");
            }
            context.addPropertyChangeListener
                (AppContext.DISPOSED_PROPERTY_NAME, this);
        }
        if (contentsContext != null) {
            contentsContext.removePropertyChangeListener
                (AppContext.DISPOSED_PROPERTY_NAME, this);
        }
        contentsContext = context;
    }
}
 
Example 4
Source File: RepaintManager.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void scheduleDisplayChanges() {
    // To avoid threading problems, we notify each RepaintManager
    // on the thread it was created on.
    for (Object c : AppContext.getAppContexts()) {
        AppContext context = (AppContext) c;
        synchronized(context) {
            if (!context.isDisposed()) {
                EventQueue eventQueue = (EventQueue)context.get(
                    AppContext.EVENT_QUEUE_KEY);
                if (eventQueue != null) {
                    eventQueue.postEvent(new InvocationEvent(
                        Toolkit.getDefaultToolkit(),
                        new DisplayChangedRunnable()));
                }
            }
        }
    }
}
 
Example 5
Source File: RepaintManager.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static void scheduleDisplayChanges() {
    // To avoid threading problems, we notify each RepaintManager
    // on the thread it was created on.
    for (AppContext context : AppContext.getAppContexts()) {
        synchronized(context) {
            if (!context.isDisposed()) {
                EventQueue eventQueue = (EventQueue)context.get(
                    AppContext.EVENT_QUEUE_KEY);
                if (eventQueue != null) {
                    eventQueue.postEvent(new InvocationEvent(
                        Toolkit.getDefaultToolkit(),
                        new DisplayChangedRunnable()));
                }
            }
        }
    }
}
 
Example 6
Source File: RepaintManager.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private void scheduleDisplayChanges() {
    // To avoid threading problems, we notify each RepaintManager
    // on the thread it was created on.
    for (Object c : AppContext.getAppContexts()) {
        AppContext context = (AppContext) c;
        synchronized(context) {
            if (!context.isDisposed()) {
                EventQueue eventQueue = (EventQueue)context.get(
                    AppContext.EVENT_QUEUE_KEY);
                if (eventQueue != null) {
                    eventQueue.postEvent(new InvocationEvent(
                        Toolkit.getDefaultToolkit(),
                        new DisplayChangedRunnable()));
                }
            }
        }
    }
}
 
Example 7
Source File: SunClipboard.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private synchronized void initContext() {
    final AppContext context = AppContext.getAppContext();

    if (contentsContext != context) {
        // Need to synchronize on the AppContext to guarantee that it cannot
        // be disposed after the check, but before the listener is added.
        synchronized (context) {
            if (context.isDisposed()) {
                throw new IllegalStateException("Can't set contents from disposed AppContext");
            }
            context.addPropertyChangeListener
                (AppContext.DISPOSED_PROPERTY_NAME, this);
        }
        if (contentsContext != null) {
            contentsContext.removePropertyChangeListener
                (AppContext.DISPOSED_PROPERTY_NAME, this);
        }
        contentsContext = context;
    }
}
 
Example 8
Source File: RepaintManager.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void scheduleDisplayChanges() {
    // To avoid threading problems, we notify each RepaintManager
    // on the thread it was created on.
    for (AppContext context : AppContext.getAppContexts()) {
        synchronized(context) {
            if (!context.isDisposed()) {
                EventQueue eventQueue = (EventQueue)context.get(
                    AppContext.EVENT_QUEUE_KEY);
                if (eventQueue != null) {
                    eventQueue.postEvent(new InvocationEvent(
                        Toolkit.getDefaultToolkit(),
                        new DisplayChangedRunnable()));
                }
            }
        }
    }
}
 
Example 9
Source File: RepaintManager.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void scheduleDisplayChanges() {
    // To avoid threading problems, we notify each RepaintManager
    // on the thread it was created on.
    for (AppContext context : AppContext.getAppContexts()) {
        synchronized(context) {
            if (!context.isDisposed()) {
                EventQueue eventQueue = (EventQueue)context.get(
                    AppContext.EVENT_QUEUE_KEY);
                if (eventQueue != null) {
                    eventQueue.postEvent(new InvocationEvent(
                        Toolkit.getDefaultToolkit(),
                        new DisplayChangedRunnable()));
                }
            }
        }
    }
}
 
Example 10
Source File: RepaintManager.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private static void scheduleDisplayChanges() {
    // To avoid threading problems, we notify each RepaintManager
    // on the thread it was created on.
    for (AppContext context : AppContext.getAppContexts()) {
        synchronized(context) {
            if (!context.isDisposed()) {
                EventQueue eventQueue = (EventQueue)context.get(
                    AppContext.EVENT_QUEUE_KEY);
                if (eventQueue != null) {
                    eventQueue.postEvent(new InvocationEvent(
                        Toolkit.getDefaultToolkit(),
                        new DisplayChangedRunnable()));
                }
            }
        }
    }
}
 
Example 11
Source File: Toolkit.java    From openjdk-8-source 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 12
Source File: Toolkit.java    From hottub 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: Toolkit.java    From jdk8u-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 14
Source File: Toolkit.java    From openjdk-jdk9 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 15
Source File: DefaultKeyboardFocusManager.java    From openjdk-8-source 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 16
Source File: DefaultKeyboardFocusManager.java    From jdk-1.7-annotated with Apache License 2.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 17
Source File: Toolkit.java    From openjdk-jdk8u-backup 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 18
Source File: DefaultKeyboardFocusManager.java    From JDKSourceCode1.8 with MIT License 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 19
Source File: Toolkit.java    From openjdk-8 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 20
Source File: DefaultKeyboardFocusManager.java    From openjdk-jdk8u 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;
}