Search in sources :

Example 41 with AppContext

use of sun.awt.AppContext in project jdk8u_jdk by JetBrains.

the class DefaultKeyboardFocusManager method sendMessage.

/**
     * 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;
}
Also used : AppContext(sun.awt.AppContext)

Example 42 with AppContext

use of sun.awt.AppContext in project jdk8u_jdk by JetBrains.

the class ImageIO method getCacheInfo.

/**
     * Returns the <code>CacheInfo</code> object associated with this
     * <code>ThreadGroup</code>.
     */
private static synchronized CacheInfo getCacheInfo() {
    AppContext context = AppContext.getAppContext();
    CacheInfo info = (CacheInfo) context.get(CacheInfo.class);
    if (info == null) {
        info = new CacheInfo();
        context.put(CacheInfo.class, info);
    }
    return info;
}
Also used : AppContext(sun.awt.AppContext)

Example 43 with AppContext

use of sun.awt.AppContext in project jdk8u_jdk by JetBrains.

the class AppletSecurity method checkAwtEventQueueAccess.

/**
     * Tests if a client can get access to the AWT event queue.
     * <p>
     * This method calls <code>checkPermission</code> with the
     * <code>AWTPermission("accessEventQueue")</code> permission.
     *
     * @since   JDK1.1
     * @exception  SecurityException  if the caller does not have
     *             permission to access the AWT event queue.
     */
public void checkAwtEventQueueAccess() {
    AppContext appContext = AppContext.getAppContext();
    AppletClassLoader appletClassLoader = currentAppletClassLoader();
    if (AppContext.isMainContext(appContext) && (appletClassLoader != null)) {
        // If we're about to allow access to the main EventQueue,
        // and anything untrusted is on the class context stack,
        // disallow access.
        super.checkPermission(SecurityConstants.AWT.CHECK_AWT_EVENTQUEUE_PERMISSION);
    }
}
Also used : AppContext(sun.awt.AppContext)

Example 44 with AppContext

use of sun.awt.AppContext in project jdk8u_jdk by JetBrains.

the class AppletPanel method appletResize.

/**
     * Is called when the applet wants to be resized.
     */
@Override
public void appletResize(int width, int height) {
    currentAppletSize.width = width;
    currentAppletSize.height = height;
    final Dimension currentSize = new Dimension(currentAppletSize.width, currentAppletSize.height);
    if (loader != null) {
        AppContext appCtxt = loader.getAppContext();
        if (appCtxt != null)
            appEvtQ = (java.awt.EventQueue) appCtxt.get(AppContext.EVENT_QUEUE_KEY);
    }
    final AppletPanel ap = this;
    if (appEvtQ != null) {
        appEvtQ.postEvent(new InvocationEvent(Toolkit.getDefaultToolkit(), new Runnable() {

            @Override
            public void run() {
                if (ap != null) {
                    ap.dispatchAppletEvent(APPLET_RESIZE, currentSize);
                }
            }
        }));
    }
}
Also used : AppContext(sun.awt.AppContext)

Example 45 with AppContext

use of sun.awt.AppContext in project jdk8u_jdk by JetBrains.

the class AppletPanel method changeFrameAppContext.

public static void changeFrameAppContext(Frame frame, AppContext newAppContext) {
    // Fixed #4754451: Applet can have methods running on main
    // thread event queue.
    //
    // The cause of this bug is that the frame of the applet
    // is created in main thread group. Thus, when certain
    // AWT/Swing events are generated, the events will be
    // dispatched through the wrong event dispatch thread.
    //
    // To fix this, we rearrange the AppContext with the frame,
    // so the proper event queue will be looked up.
    //
    // Swing also maintains a Frame list for the AppContext,
    // so we will have to rearrange it as well.
    // Check if frame's AppContext has already been set properly
    AppContext oldAppContext = SunToolkit.targetToAppContext(frame);
    if (oldAppContext == newAppContext)
        return;
    // critical section of the window list in AppContext.
    synchronized (Window.class) {
        WeakReference weakRef = null;
        // Remove frame from the Window list in wrong AppContext
        {
            // Lookup current frame's AppContext
            Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>) oldAppContext.get(Window.class);
            if (windowList != null) {
                for (WeakReference ref : windowList) {
                    if (ref.get() == frame) {
                        weakRef = ref;
                        break;
                    }
                }
                // Remove frame from wrong AppContext
                if (weakRef != null)
                    windowList.remove(weakRef);
            }
        }
        // Put the frame into the applet's AppContext map
        SunToolkit.insertTargetMapping(frame, newAppContext);
        // Insert frame into the Window list in the applet's AppContext map
        {
            Vector<WeakReference<Window>> windowList = (Vector) newAppContext.get(Window.class);
            if (windowList == null) {
                windowList = new Vector<WeakReference<Window>>();
                newAppContext.put(Window.class, windowList);
            }
            // use the same weakRef here as it is used elsewhere
            windowList.add(weakRef);
        }
    }
}
Also used : AppContext(sun.awt.AppContext) WeakReference(java.lang.ref.WeakReference)

Aggregations

AppContext (sun.awt.AppContext)74 HashMap (java.util.HashMap)3 Hashtable (java.util.Hashtable)3 Locale (java.util.Locale)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 EventListenerAggregate (sun.awt.EventListenerAggregate)3 FlavorListener (java.awt.datatransfer.FlavorListener)2 WeakReference (java.lang.ref.WeakReference)2 Map (java.util.Map)2 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)2 LookAndFeel (javax.swing.LookAndFeel)2 MetalLookAndFeel (javax.swing.plaf.metal.MetalLookAndFeel)2 MetalTheme (javax.swing.plaf.metal.MetalTheme)2 ValueNamePair (org.compiere.util.ValueNamePair)2 PeerEvent (sun.awt.PeerEvent)2 AccumulativeRunnable (sun.swing.AccumulativeRunnable)2 Container (java.awt.Container)1 EventQueue (java.awt.EventQueue)1 Font (java.awt.Font)1 Rectangle (java.awt.Rectangle)1