Java 类sun.awt.AppContext 实例源码

项目:jdk8u-jdk    文件:AppletClassLoader.java   
/**
 * Release this AppletClassLoader and its ThreadGroup/AppContext.
 * If nothing else has grabbed this AppletClassLoader, its ThreadGroup
 * and AppContext will be destroyed.
 *
 * Because this method may destroy the AppletClassLoader's ThreadGroup,
 * this method should NOT be called from within the AppletClassLoader's
 * ThreadGroup.
 *
 * Changed modifier to protected in order to be able to overwrite this
 * function in PluginClassLoader.java
 */
protected void release() {

    AppContext tempAppContext = null;

    synchronized(grabReleaseSynchronizer) {
        if (usageCount > 1)  {
            --usageCount;
        } else {
            synchronized(threadGroupSynchronizer) {
                tempAppContext = resetAppContext();
            }
        }
    }

    // Dispose appContext outside any sync block to
    // prevent potential deadlock.
    if (tempAppContext != null)  {
        try {
            tempAppContext.dispose(); // nuke the world!
        } catch (IllegalThreadStateException e) { }
    }
}
项目:openjdk-jdk10    文件:DataTransferer.java   
public void processDataConversionRequests() {
    if (EventQueue.isDispatchThread()) {
        AppContext appContext = AppContext.getAppContext();
        getToolkitThreadBlockedHandler().lock();
        try {
            Runnable dataConverter =
                (Runnable)appContext.get(DATA_CONVERTER_KEY);
            if (dataConverter != null) {
                dataConverter.run();
                appContext.remove(DATA_CONVERTER_KEY);
            }
        } finally {
            getToolkitThreadBlockedHandler().unlock();
        }
    }
}
项目:OpenJSharp    文件:SystemTray.java   
/**
 * Removes the specified <code>TrayIcon</code> from the
 * <code>SystemTray</code>.
 *
 * <p> All icons added by the application are automatically
 * removed from the <code>SystemTray</code> upon application exit
 * and also when the desktop system tray becomes unavailable.
 *
 * <p> If <code>trayIcon</code> is <code>null</code> or was not
 * added to the system tray, no exception is thrown and no action
 * is performed.
 *
 * @param trayIcon the <code>TrayIcon</code> to be removed
 * @see #add(TrayIcon)
 * @see TrayIcon
 */
public void remove(TrayIcon trayIcon) {
    if (trayIcon == null) {
        return;
    }
    TrayIcon[] oldArray = null, newArray = null;
    synchronized (this) {
        oldArray = systemTray.getTrayIcons();
        Vector<TrayIcon> icons = (Vector<TrayIcon>)AppContext.getAppContext().get(TrayIcon.class);
        // TrayIcon with no peer is not contained in the array.
        if (icons == null || !icons.remove(trayIcon)) {
            return;
        }
        trayIcon.removeNotify();
        newArray = systemTray.getTrayIcons();
    }
    firePropertyChange("trayIcons", oldArray, newArray);
}
项目:OpenJSharp    文件:RepaintManager.java   
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()));
                }
            }
        }
    }
}
项目:jdk8u-jdk    文件:SunFontManager.java   
public Font[] getCreatedFonts() {

        Hashtable<String,Font2D> nameTable;
        if (fontsAreRegistered) {
            nameTable = createdByFullName;
        } else if (fontsAreRegisteredPerAppContext) {
            AppContext appContext = AppContext.getAppContext();
            nameTable =
                (Hashtable<String,Font2D>)appContext.get(regFullNameKey);
        } else {
            return null;
        }

        Locale l = getSystemStartupLocale();
        synchronized (nameTable) {
            Font[] fonts = new Font[nameTable.size()];
            int i=0;
            for (Font2D font2D : nameTable.values()) {
                fonts[i++] = new Font(font2D.getFontName(l), Font.PLAIN, 1);
            }
            return fonts;
        }
    }
项目:jdk8u-jdk    文件:DataTransferer.java   
public void processDataConversionRequests() {
    if (EventQueue.isDispatchThread()) {
        AppContext appContext = AppContext.getAppContext();
        getToolkitThreadBlockedHandler().lock();
        try {
            Runnable dataConverter =
                (Runnable)appContext.get(DATA_CONVERTER_KEY);
            if (dataConverter != null) {
                dataConverter.run();
                appContext.remove(DATA_CONVERTER_KEY);
            }
        } finally {
            getToolkitThreadBlockedHandler().unlock();
        }
    }
}
项目:openjdk-jdk10    文件:SunClipboard.java   
protected void lostOwnershipNow(final AppContext disposedContext) {
    final SunClipboard sunClipboard = SunClipboard.this;
    ClipboardOwner owner = null;
    Transferable contents = null;

    synchronized (sunClipboard) {
        final AppContext context = sunClipboard.contentsContext;

        if (context == null) {
            return;
        }

        if (disposedContext == null || context == disposedContext) {
            owner = sunClipboard.owner;
            contents = sunClipboard.contents;
            sunClipboard.contentsContext = null;
            sunClipboard.owner = null;
            sunClipboard.contents = null;
            sunClipboard.clearNativeContext();
            context.removePropertyChangeListener
                    (AppContext.DISPOSED_PROPERTY_NAME, sunClipboard);
        } else {
            return;
        }
    }
    if (owner != null) {
        owner.lostOwnership(sunClipboard, contents);
    }
}
项目:openjdk-jdk10    文件:MotifCheckBoxUI.java   
public static ComponentUI createUI(JComponent c) {
    AppContext appContext = AppContext.getAppContext();
    MotifCheckBoxUI motifCheckBoxUI =
            (MotifCheckBoxUI) appContext.get(MOTIF_CHECK_BOX_UI_KEY);
    if (motifCheckBoxUI == null) {
        motifCheckBoxUI = new MotifCheckBoxUI();
        appContext.put(MOTIF_CHECK_BOX_UI_KEY, motifCheckBoxUI);
    }
    return motifCheckBoxUI;
}
项目:openjdk-jdk10    文件:WToolkit.java   
private void windowsSettingChange() {
    // JDK-8039383: Have to update the value of XPSTYLE_THEME_ACTIVE property
    // as soon as possible to prevent NPE and other errors because theme data
    // has become unavailable.
    final Map<String, Object> props = getWProps();
    if (props == null) {
        // props has not been initialized, so we have nothing to update
        return;
    }

    updateXPStyleEnabled(props.get(XPSTYLE_THEME_ACTIVE));

    if (AppContext.getAppContext() == null) {
        // We cannot post the update to any EventQueue. Listeners will
        // be called on EDTs by DesktopPropertyChangeSupport
        updateProperties(props);
    } else {
        // Cannot update on Toolkit thread.
        // DesktopPropertyChangeSupport will call listeners on Toolkit
        // thread if it has AppContext (standalone mode)
        EventQueue.invokeLater(() -> updateProperties(props));
    }
}
项目:jdk8u-jdk    文件:MotifLabelUI.java   
public static ComponentUI createUI(JComponent c) {
    AppContext appContext = AppContext.getAppContext();
    MotifLabelUI motifLabelUI =
            (MotifLabelUI) appContext.get(MOTIF_LABEL_UI_KEY);
    if (motifLabelUI == null) {
        motifLabelUI = new MotifLabelUI();
        appContext.put(MOTIF_LABEL_UI_KEY, motifLabelUI);
    }
    return motifLabelUI;
}
项目:openjdk-jdk10    文件:HTMLEditorKit.java   
/**
 * Get the set of styles currently being used to render the
 * HTML elements.  By default the resource specified by
 * DEFAULT_CSS gets loaded, and is shared by all HTMLEditorKit
 * instances.
 *
 * @return the StyleSheet
 */
public StyleSheet getStyleSheet() {
    AppContext appContext = AppContext.getAppContext();
    StyleSheet defaultStyles = (StyleSheet) appContext.get(DEFAULT_STYLES_KEY);

    if (defaultStyles == null) {
        defaultStyles = new StyleSheet();
        appContext.put(DEFAULT_STYLES_KEY, defaultStyles);
        try {
            InputStream is = HTMLEditorKit.getResourceAsStream(DEFAULT_CSS);
            Reader r = new BufferedReader(
                    new InputStreamReader(is, "ISO-8859-1"));
            defaultStyles.loadRules(r, null);
            r.close();
        } catch (Throwable e) {
            // on error we simply have no styles... the html
            // will look mighty wrong but still function.
        }
    }
    return defaultStyles;
}
项目:OpenJSharp    文件:_AppEventHandler.java   
void dispatch(final _NativeEvent event, final Object... args) {
    // grab a local ref to the listeners and its contexts as an array of the map's entries
    final ArrayList<Map.Entry<L, AppContext>> localEntries;
    synchronized (this) {
        if (listenerToAppContext.size() == 0) {
            return;
        }
        localEntries = new ArrayList<Map.Entry<L, AppContext>>(listenerToAppContext.size());
        localEntries.addAll(listenerToAppContext.entrySet());
    }

    for (final Map.Entry<L, AppContext> e : localEntries) {
        final L listener = e.getKey();
        final AppContext listenerContext = e.getValue();
        SunToolkit.invokeLaterOnAppContext(listenerContext, new Runnable() {
            public void run() {
                performOnListener(listener, event);
            }
        });
    }
}
项目:openjdk-jdk10    文件:bug6495920.java   
public void thirdValidate() throws Exception {
    Field key = BasicPopupMenuUI.class.getDeclaredField("MOUSE_GRABBER_KEY");
    key.setAccessible(true);

    Object grabber = AppContext.getAppContext().get(key.get(null));
    if (grabber == null) {
        throw new Exception("cannot find a mouse grabber in app's context");
    }

    Field field = grabber.getClass().getDeclaredField("grabbedWindow");
    field.setAccessible(true);

    Object window = field.get(grabber);
    if (window != null) {
        throw new Exception("interaction with GNOME is crippled");
    }
}
项目:jdk8u-jdk    文件:bug6495920.java   
public void thirdValidate() throws Exception {
    Field key = BasicPopupMenuUI.class.getDeclaredField("MOUSE_GRABBER_KEY");
    key.setAccessible(true);

    Object grabber = AppContext.getAppContext().get(key.get(null));
    if (grabber == null) {
        throw new Exception("cannot find a mouse grabber in app's context");
    }

    Field field = grabber.getClass().getDeclaredField("grabbedWindow");
    field.setAccessible(true);

    Object window = field.get(grabber);
    if (window != null) {
        throw new Exception("interaction with GNOME is crippled");
    }
}
项目:jdk8u-jdk    文件:ImageFetcher.java   
static FetcherInfo getFetcherInfo() {
    AppContext appContext = AppContext.getAppContext();
    synchronized(appContext) {
        FetcherInfo info = (FetcherInfo)appContext.get(FETCHER_INFO_KEY);
        if (info == null) {
            info = new FetcherInfo();
            appContext.put(FETCHER_INFO_KEY, info);
        }
        return info;
    }
}
项目:openjdk-jdk10    文件:ImageIcon.java   
/**
 * Returns the MediaTracker for the current AppContext, creating a new
 * MediaTracker if necessary.
 */
private MediaTracker getTracker() {
    Object trackerObj;
    AppContext ac = AppContext.getAppContext();
    // Opt: Only synchronize if trackerObj comes back null?
    // If null, synchronize, re-check for null, and put new tracker
    synchronized(ac) {
        trackerObj = ac.get(TRACKER_KEY);
        if (trackerObj == null) {
            Component comp = new Component() {};
            trackerObj = new MediaTracker(comp);
            ac.put(TRACKER_KEY, trackerObj);
        }
    }
    return (MediaTracker) trackerObj;
}
项目:OpenJSharp    文件:SunClipboard.java   
public synchronized void removeFlavorListener(FlavorListener listener) {
    if (listener == null) {
        return;
    }
    AppContext appContext = AppContext.getAppContext();
    EventListenerAggregate contextFlavorListeners = (EventListenerAggregate)
            appContext.get(CLIPBOARD_FLAVOR_LISTENER_KEY);
    if (contextFlavorListeners == null){
        //else we throw NullPointerException, but it is forbidden
        return;
    }
    if (contextFlavorListeners.remove(listener) &&
            --numberOfFlavorListeners == 0) {
        unregisterClipboardViewerChecked();
        currentDataFlavors = null;
    }
}
项目:jdk8u-jdk    文件:JTextComponent.java   
private static HashMap<String,Keymap> getKeymapTable() {
    synchronized (KEYMAP_TABLE) {
        AppContext appContext = AppContext.getAppContext();
        HashMap<String,Keymap> keymapTable =
            (HashMap<String,Keymap>)appContext.get(KEYMAP_TABLE);
        if (keymapTable == null) {
            keymapTable = new HashMap<String,Keymap>(17);
            appContext.put(KEYMAP_TABLE, keymapTable);
            //initialize default keymap
            Keymap binding = addKeymap(DEFAULT_KEYMAP, null);
            binding.setDefaultAction(new
                                     DefaultEditorKit.DefaultKeyTypedAction());
        }
        return keymapTable;
    }
}
项目:jdk8u-jdk    文件:MetalCheckBoxUI.java   
public static ComponentUI createUI(JComponent b) {
    AppContext appContext = AppContext.getAppContext();
    MetalCheckBoxUI checkboxUI =
            (MetalCheckBoxUI) appContext.get(METAL_CHECK_BOX_UI_KEY);
    if (checkboxUI == null) {
        checkboxUI = new MetalCheckBoxUI();
        appContext.put(METAL_CHECK_BOX_UI_KEY, checkboxUI);
    }
    return checkboxUI;
}
项目:openjdk-jdk10    文件:SwingWorker.java   
private static AccumulativeRunnable<Runnable> getDoSubmit() {
    synchronized (DO_SUBMIT_KEY) {
        final AppContext appContext = AppContext.getAppContext();
        Object doSubmit = appContext.get(DO_SUBMIT_KEY);
        if (doSubmit == null) {
            doSubmit = new DoSubmitAccumulativeRunnable();
            appContext.put(DO_SUBMIT_KEY, doSubmit);
        }
        @SuppressWarnings("unchecked")
        AccumulativeRunnable<Runnable> tmp = (AccumulativeRunnable<Runnable>) doSubmit;
        return tmp;
    }
}
项目:OpenJSharp    文件:_AppEventHandler.java   
synchronized void setHandler(final H handler) {
    this._handler = handler;

    setHandlerContext(AppContext.getAppContext());

    // dispatch any events in the queue
    if (queuedEvents != null) {
        // grab a local ref to the queue, so the real one can be nulled out
        final java.util.List<_NativeEvent> localQueuedEvents = queuedEvents;
        queuedEvents = null;
        if (localQueuedEvents.size() != 0) {
            for (final _NativeEvent arg : localQueuedEvents) {
                dispatch(arg);
            }
        }
    }

    // if a new handler is installed, block addition of legacy ApplicationListeners
    if (handler == legacyHandler) return;
    legacyHandler.blockLegacyAPI();
}
项目:OpenJSharp    文件:BasicLookAndFeel.java   
/**
 * {@inheritDoc}
 */
public void uninitialize() {
    AppContext context = AppContext.getAppContext();
    synchronized (BasicPopupMenuUI.MOUSE_GRABBER_KEY) {
        Object grabber = context.get(BasicPopupMenuUI.MOUSE_GRABBER_KEY);
        if (grabber != null) {
            ((BasicPopupMenuUI.MouseGrabber)grabber).uninstall();
        }
    }
    synchronized (BasicPopupMenuUI.MENU_KEYBOARD_HELPER_KEY) {
        Object helper =
                context.get(BasicPopupMenuUI.MENU_KEYBOARD_HELPER_KEY);
        if (helper != null) {
            ((BasicPopupMenuUI.MenuKeyboardHelper)helper).uninstall();
        }
    }

    if(invocator != null) {
        AccessController.doPrivileged(invocator);
        invocator = null;
    }

    if (disposer != null) {
        // Note that we're likely calling removePropertyChangeListener()
        // during the course of AppContext.firePropertyChange().
        // However, EventListenerAggreggate has code to safely modify
        // the list under such circumstances.
        context.removePropertyChangeListener(AppContext.GUI_DISPOSED,
                                             disposer);
        disposer = null;
    }
}
项目:jdk8u-jdk    文件:_AppEventHandler.java   
void dispatch(final _NativeEvent event, final Object... args) {
    // grab a local ref to the listeners and its contexts as an array of the map's entries
    final ArrayList<Map.Entry<L, AppContext>> localEntries;
    synchronized (this) {
        if (listenerToAppContext.size() == 0) {
            return;
        }
        localEntries = new ArrayList<Map.Entry<L, AppContext>>(listenerToAppContext.size());
        localEntries.addAll(listenerToAppContext.entrySet());
    }

    for (final Map.Entry<L, AppContext> e : localEntries) {
        final L listener = e.getKey();
        final AppContext listenerContext = e.getValue();
        SunToolkit.invokeLaterOnAppContext(listenerContext, new Runnable() {
            public void run() {
                performOnListener(listener, event);
            }
        });
    }
}
项目:openjdk-jdk10    文件:SystemTray.java   
/**
 * Removes the specified {@code TrayIcon} from the
 * {@code SystemTray}.
 *
 * <p> All icons added by the application are automatically
 * removed from the {@code SystemTray} upon application exit
 * and also when the desktop system tray becomes unavailable.
 *
 * <p> If {@code trayIcon} is {@code null} or was not
 * added to the system tray, no exception is thrown and no action
 * is performed.
 *
 * @param trayIcon the {@code TrayIcon} to be removed
 * @see #add(TrayIcon)
 * @see TrayIcon
 */
public void remove(TrayIcon trayIcon) {
    if (trayIcon == null) {
        return;
    }
    TrayIcon[] oldArray = null, newArray = null;
    synchronized (this) {
        oldArray = systemTray.getTrayIcons();
        @SuppressWarnings("unchecked")
        Vector<TrayIcon> icons = (Vector<TrayIcon>)AppContext.getAppContext().get(TrayIcon.class);
        // TrayIcon with no peer is not contained in the array.
        if (icons == null || !icons.remove(trayIcon)) {
            return;
        }
        trayIcon.removeNotify();
        newArray = systemTray.getTrayIcons();
    }
    firePropertyChange("trayIcons", oldArray, newArray);
}
项目:jdk8u-jdk    文件:KeyboardFocusManager.java   
/**
 * Sets the current KeyboardFocusManager instance for the calling thread's
 * context. If null is specified, then the current KeyboardFocusManager
 * is replaced with a new instance of DefaultKeyboardFocusManager.
 * <p>
 * If a SecurityManager is installed, the calling thread must be granted
 * the AWTPermission "replaceKeyboardFocusManager" in order to replace the
 * the current KeyboardFocusManager. If this permission is not granted,
 * this method will throw a SecurityException, and the current
 * KeyboardFocusManager will be unchanged.
 *
 * @param newManager the new KeyboardFocusManager for this thread's context
 * @see #getCurrentKeyboardFocusManager
 * @see DefaultKeyboardFocusManager
 * @throws SecurityException if the calling thread does not have permission
 *         to replace the current KeyboardFocusManager
 */
public static void setCurrentKeyboardFocusManager(
    KeyboardFocusManager newManager) throws SecurityException
{
    checkReplaceKFMPermission();

    KeyboardFocusManager oldManager = null;

    synchronized (KeyboardFocusManager.class) {
        AppContext appcontext = AppContext.getAppContext();

        if (newManager != null) {
            oldManager = getCurrentKeyboardFocusManager(appcontext);

            appcontext.put(KeyboardFocusManager.class, newManager);
        } else {
            oldManager = getCurrentKeyboardFocusManager(appcontext);
            appcontext.remove(KeyboardFocusManager.class);
        }
    }

    if (oldManager != null) {
        oldManager.firePropertyChange("managingFocus",
                                      Boolean.TRUE,
                                      Boolean.FALSE);
    }
    if (newManager != null) {
        newManager.firePropertyChange("managingFocus",
                                      Boolean.FALSE,
                                      Boolean.TRUE);
    }
}
项目:openjdk-jdk10    文件:AccessBridge.java   
/**
 * Invokes a {@code Callable} in the {@code AppContext} mapped to the given {@code AccessibleContext}
 * and waits for it to finish blocking the caller thread.
 *
 * @param callable the {@code Callable} to invoke
 * @param accessibleContext the {@code AccessibleContext} which would be used to determine the right
 *                          context for the task execution.
 * @param <T> type parameter for the result value
 *
 * @return the result of the {@code Callable} execution
 */
public static <T> T invokeAndWait(final Callable<T> callable,
                                  final AccessibleContext accessibleContext) {
    AppContext targetContext = AWTAccessor.getAccessibleContextAccessor()
            .getAppContext(accessibleContext);
    if (targetContext != null) {
        return invokeAndWait(callable, targetContext);
    } else {
        // Normally this should not happen, unmapped context provided and
        // the target AppContext is unknown.

        // Try to recover in case the context is a translator.
        if (accessibleContext instanceof Translator) {
            Object source = ((Translator)accessibleContext).getSource();
            if (source instanceof Component) {
                return invokeAndWait(callable, (Component)source);
            }
        }
    }
    throw new RuntimeException("Unmapped AccessibleContext used to dispatch event: " + accessibleContext);
}
项目:jdk8u-jdk    文件:RepaintManager.java   
/**
 * Returns the RepaintManager for the specified AppContext.  If
 * a RepaintManager has not been created for the specified
 * AppContext this will return null.
 */
static RepaintManager currentManager(AppContext appContext) {
    RepaintManager rm = (RepaintManager)appContext.get(repaintManagerKey);
    if (rm == null) {
        rm = new RepaintManager(BUFFER_STRATEGY_TYPE);
        appContext.put(repaintManagerKey, rm);
    }
    return rm;
}
项目:OpenJSharp    文件:MotifCheckBoxUI.java   
public static ComponentUI createUI(JComponent c) {
    AppContext appContext = AppContext.getAppContext();
    MotifCheckBoxUI motifCheckBoxUI =
            (MotifCheckBoxUI) appContext.get(MOTIF_CHECK_BOX_UI_KEY);
    if (motifCheckBoxUI == null) {
        motifCheckBoxUI = new MotifCheckBoxUI();
        appContext.put(MOTIF_CHECK_BOX_UI_KEY, motifCheckBoxUI);
    }
    return motifCheckBoxUI;
}
项目:OpenJSharp    文件:RepaintManager.java   
void nativeAddDirtyRegion(AppContext appContext, Container c,
                          int x, int y, int w, int h) {
    if (w > 0 && h > 0) {
        synchronized(this) {
            Rectangle dirty = hwDirtyComponents.get(c);
            if (dirty == null) {
                hwDirtyComponents.put(c, new Rectangle(x, y, w, h));
            }
            else {
                hwDirtyComponents.put(c, SwingUtilities.computeUnion(
                                          x, y, w, h, dirty));
            }
        }
        scheduleProcessingRunnable(appContext);
    }
}
项目:openjdk-jdk10    文件:AWTKeyStroke.java   
private static synchronized AWTKeyStroke getCachedStroke
    (char keyChar, int keyCode, int modifiers, boolean onKeyRelease)
{
    @SuppressWarnings("unchecked")
    Map<AWTKeyStroke, AWTKeyStroke> cache = (Map)AppContext.getAppContext().get(APP_CONTEXT_CACHE_KEY);
    AWTKeyStroke cacheKey = (AWTKeyStroke)AppContext.getAppContext().get(APP_CONTEXT_KEYSTROKE_KEY);

    if (cache == null) {
        cache = new HashMap<>();
        AppContext.getAppContext().put(APP_CONTEXT_CACHE_KEY, cache);
    }

    if (cacheKey == null) {
        cacheKey = SwingAccessor.getKeyStrokeAccessor().create();
        AppContext.getAppContext().put(APP_CONTEXT_KEYSTROKE_KEY, cacheKey);
    }

    cacheKey.keyChar = keyChar;
    cacheKey.keyCode = keyCode;
    cacheKey.modifiers = mapNewModifiers(mapOldModifiers(modifiers));
    cacheKey.onKeyRelease = onKeyRelease;

    AWTKeyStroke stroke = cache.get(cacheKey);
    if (stroke == null) {
        stroke = cacheKey;
        cache.put(stroke, stroke);
        AppContext.getAppContext().remove(APP_CONTEXT_KEYSTROKE_KEY);
    }
    return stroke;
}
项目:jdk8u-jdk    文件:AquaUtils.java   
final T get() {
    return AppContext.getSoftReferenceValue(this, () -> getInstance());
}
项目:openjdk-jdk10    文件:SunFontManager.java   
public synchronized void preferLocaleFonts() {
    if (FontUtilities.isLogging()) {
        FontUtilities.getLogger().info("Entered preferLocaleFonts().");
    }
    /* Test if re-ordering will have any effect */
    if (!FontConfiguration.willReorderForStartupLocale()) {
        return;
    }

    if (!maybeMultiAppContext()) {
        if (gLocalePref == true) {
            return;
        }
        gLocalePref = true;
        createCompositeFonts(fontNameCache, gLocalePref, gPropPref);
        _usingAlternateComposites = true;
    } else {
        AppContext appContext = AppContext.getAppContext();
        if (appContext.get(localeFontKey) == localeFontKey) {
            return;
        }
        appContext.put(localeFontKey, localeFontKey);
        boolean acPropPref =
            appContext.get(proportionalFontKey) == proportionalFontKey;
        ConcurrentHashMap<String, Font2D>
            altNameCache = new ConcurrentHashMap<String, Font2D> ();
        /* If there is an existing hashtable, we can drop it. */
        appContext.put(CompositeFont.class, altNameCache);
        _usingPerAppContextComposites = true;
        createCompositeFonts(altNameCache, true, acPropPref);
    }
}
项目:openjdk-jdk10    文件:MetalRadioButtonUI.java   
/**
 * Returns an instance of {@code MetalRadioButtonUI}.
 *
 * @param c a component
 * @return an instance of {@code MetalRadioButtonUI}
 */
public static ComponentUI createUI(JComponent c) {
    AppContext appContext = AppContext.getAppContext();
    MetalRadioButtonUI metalRadioButtonUI =
            (MetalRadioButtonUI) appContext.get(METAL_RADIO_BUTTON_UI_KEY);
    if (metalRadioButtonUI == null) {
        metalRadioButtonUI = new MetalRadioButtonUI();
        appContext.put(METAL_RADIO_BUTTON_UI_KEY, metalRadioButtonUI);
    }
    return metalRadioButtonUI;
}
项目:OpenJSharp    文件:Element.java   
/**
 * Create a new element.
 */
Element(String name, int index) {
    this.name = name;
    this.index = index;
    if (index > getMaxIndex()) {
        AppContext.getAppContext().put(MAX_INDEX_KEY, index);
    }
}
项目:jdk8u-jdk    文件:MetalButtonUI.java   
public static ComponentUI createUI(JComponent c) {
    AppContext appContext = AppContext.getAppContext();
    MetalButtonUI metalButtonUI =
            (MetalButtonUI) appContext.get(METAL_BUTTON_UI_KEY);
    if (metalButtonUI == null) {
        metalButtonUI = new MetalButtonUI();
        appContext.put(METAL_BUTTON_UI_KEY, metalButtonUI);
    }
    return metalButtonUI;
}
项目:openjdk-jdk10    文件:SystemTray.java   
/**
 * Adds a {@code TrayIcon} to the {@code SystemTray}.
 * The tray icon becomes visible in the system tray once it is
 * added.  The order in which icons are displayed in a tray is not
 * specified - it is platform and implementation-dependent.
 *
 * <p> All icons added by the application are automatically
 * removed from the {@code SystemTray} upon application exit
 * and also when the desktop system tray becomes unavailable.
 *
 * @param trayIcon the {@code TrayIcon} to be added
 * @throws NullPointerException if {@code trayIcon} is
 * {@code null}
 * @throws IllegalArgumentException if the same instance of
 * a {@code TrayIcon} is added more than once
 * @throws AWTException if the desktop system tray is missing
 * @see #remove(TrayIcon)
 * @see #getSystemTray
 * @see TrayIcon
 * @see java.awt.Image
 */
public void add(TrayIcon trayIcon) throws AWTException {
    if (trayIcon == null) {
        throw new NullPointerException("adding null TrayIcon");
    }
    TrayIcon[] oldArray = null, newArray = null;
    Vector<TrayIcon> icons = null;
    synchronized (this) {
        oldArray = systemTray.getTrayIcons();
        @SuppressWarnings("unchecked")
        Vector<TrayIcon> tmp = (Vector<TrayIcon>)AppContext.getAppContext().get(TrayIcon.class);
        icons = tmp;
        if (icons == null) {
            icons = new Vector<TrayIcon>(3);
            AppContext.getAppContext().put(TrayIcon.class, icons);

        } else if (icons.contains(trayIcon)) {
            throw new IllegalArgumentException("adding TrayIcon that is already added");
        }
        icons.add(trayIcon);
        newArray = systemTray.getTrayIcons();

        trayIcon.setID(++currentIconID);
    }
    try {
        trayIcon.addNotify();
    } catch (AWTException e) {
        icons.remove(trayIcon);
        throw e;
    }
    firePropertyChange("trayIcons", oldArray, newArray);
}
项目:openjdk-jdk10    文件:MetalToggleButtonUI.java   
/**
 * Constructs the {@code MetalToogleButtonUI}.
 *
 * @param b a component
 * @return the {@code MetalToogleButtonUI}.
 */
public static ComponentUI createUI(JComponent b) {
    AppContext appContext = AppContext.getAppContext();
    MetalToggleButtonUI metalToggleButtonUI =
            (MetalToggleButtonUI) appContext.get(METAL_TOGGLE_BUTTON_UI_KEY);
    if (metalToggleButtonUI == null) {
        metalToggleButtonUI = new MetalToggleButtonUI();
        appContext.put(METAL_TOGGLE_BUTTON_UI_KEY, metalToggleButtonUI);
    }
    return metalToggleButtonUI;
}
项目:OpenJSharp    文件:Window.java   
private static Window[] getWindows(AppContext appContext) {
    synchronized (Window.class) {
        Window realCopy[];
        @SuppressWarnings("unchecked")
        Vector<WeakReference<Window>> windowList =
            (Vector<WeakReference<Window>>)appContext.get(Window.class);
        if (windowList != null) {
            int fullSize = windowList.size();
            int realSize = 0;
            Window fullCopy[] = new Window[fullSize];
            for (int i = 0; i < fullSize; i++) {
                Window w = windowList.get(i).get();
                if (w != null) {
                    fullCopy[realSize++] = w;
                }
            }
            if (fullSize != realSize) {
                realCopy = Arrays.copyOf(fullCopy, realSize);
            } else {
                realCopy = fullCopy;
            }
        } else {
            realCopy = new Window[0];
        }
        return realCopy;
    }
}
项目:openjdk-jdk10    文件:Toolkit.java   
@Override
public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
    PropertyChangeSupport pcs = (PropertyChangeSupport)
            AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
    if (null != pcs) {
        pcs.removePropertyChangeListener(listener);
    }
}
项目:jdk8u-jdk    文件:AccessBridge.java   
public void mousePressed(MouseEvent e) {
    if (e != null && (javaEventMask & MOUSE_PRESSED_EVENTS) != 0) {
        Accessible a = Translator.getAccessible(e.getSource());
        if (a != null) {
            AccessibleContext context = a.getAccessibleContext();
            InvocationUtils.registerAccessibleContext(context, AppContext.getAppContext());
            accessBridge.mousePressed(e, context);
        }
    }
}