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

The following examples show how to use sun.awt.AppContext#getAppContext() . 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: JTextComponent.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
    }
}
 
Example 2
Source File: ImageIcon.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: MenuSelectionManager.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the default menu selection manager.
 *
 * @return a MenuSelectionManager object
 */
public static MenuSelectionManager defaultManager() {
    synchronized (MENU_SELECTION_MANAGER_KEY) {
        AppContext context = AppContext.getAppContext();
        MenuSelectionManager msm = (MenuSelectionManager)context.get(
                                             MENU_SELECTION_MANAGER_KEY);
        if (msm == null) {
            msm = new MenuSelectionManager();
            context.put(MENU_SELECTION_MANAGER_KEY, msm);

            // installing additional listener if found in the AppContext
            Object o = context.get(SwingUtilities2.MENU_SELECTION_MANAGER_LISTENER_KEY);
            if (o != null && o instanceof ChangeListener) {
                msm.addChangeListener((ChangeListener) o);
            }
        }

        return msm;
    }
}
 
Example 4
Source File: MetalButtonUI.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 5
Source File: BasicRadioButtonUI.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an instance of {@code BasicRadioButtonUI}.
 *
 * @param b a component
 * @return an instance of {@code BasicRadioButtonUI}
 */
public static ComponentUI createUI(JComponent b) {
    AppContext appContext = AppContext.getAppContext();
    BasicRadioButtonUI radioButtonUI =
            (BasicRadioButtonUI) appContext.get(BASIC_RADIO_BUTTON_UI_KEY);
    if (radioButtonUI == null) {
        radioButtonUI = new BasicRadioButtonUI();
        appContext.put(BASIC_RADIO_BUTTON_UI_KEY, radioButtonUI);
    }
    return radioButtonUI;
}
 
Example 6
Source File: SwingWorker.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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);
        }
        return (AccumulativeRunnable<Runnable>) doSubmit;
    }
}
 
Example 7
Source File: BasicLookAndFeel.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * {@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;
    }
}
 
Example 8
Source File: MetalButtonUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 9
Source File: SunFontManager.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public synchronized void preferProportionalFonts() {
    if (FontUtilities.isLogging()) {
        FontUtilities.getLogger()
            .info("Entered preferProportionalFonts().");
    }
    /* If no proportional fonts are configured, there's no need
     * to take any action.
     */
    if (!FontConfiguration.hasMonoToPropMap()) {
        return;
    }

    if (!maybeMultiAppContext()) {
        if (gPropPref == true) {
            return;
        }
        gPropPref = true;
        createCompositeFonts(fontNameCache, gLocalePref, gPropPref);
        _usingAlternateComposites = true;
    } else {
        AppContext appContext = AppContext.getAppContext();
        if (appContext.get(proportionalFontKey) == proportionalFontKey) {
            return;
        }
        appContext.put(proportionalFontKey, proportionalFontKey);
        boolean acLocalePref =
            appContext.get(localeFontKey) == localeFontKey;
        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, acLocalePref, true);
    }
}
 
Example 10
Source File: AppletSecurity.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 11
Source File: Region.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static Map<Region, String> getLowerCaseNameMap() {
    AppContext context = AppContext.getAppContext();
    @SuppressWarnings("unchecked")
    Map<Region, String> map = (Map<Region, String>) context.get(LOWER_CASE_NAME_MAP_KEY);
    if (map == null) {
        map = new HashMap<Region, String>();
        context.put(LOWER_CASE_NAME_MAP_KEY, map);
    }
    return map;
}
 
Example 12
Source File: MotifRadioButtonUI.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static ComponentUI createUI(JComponent c) {
    AppContext appContext = AppContext.getAppContext();
    MotifRadioButtonUI motifRadioButtonUI =
            (MotifRadioButtonUI) appContext.get(MOTIF_RADIO_BUTTON_UI_KEY);
    if (motifRadioButtonUI == null) {
        motifRadioButtonUI = new MotifRadioButtonUI();
        appContext.put(MOTIF_RADIO_BUTTON_UI_KEY, motifRadioButtonUI);
    }
    return motifRadioButtonUI;
}
 
Example 13
Source File: BasicRadioButtonUI.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an instance of {@code BasicRadioButtonUI}.
 *
 * @param b a component
 * @return an instance of {@code BasicRadioButtonUI}
 */
public static ComponentUI createUI(JComponent b) {
    AppContext appContext = AppContext.getAppContext();
    BasicRadioButtonUI radioButtonUI =
            (BasicRadioButtonUI) appContext.get(BASIC_RADIO_BUTTON_UI_KEY);
    if (radioButtonUI == null) {
        radioButtonUI = new BasicRadioButtonUI();
        appContext.put(BASIC_RADIO_BUTTON_UI_KEY, radioButtonUI);
    }
    return radioButtonUI;
}
 
Example 14
Source File: MotifCheckBoxUI.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 15
Source File: SunFontManager.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public boolean registerFont(Font font) {
    /* This method should not be called with "null".
     * It is the caller's responsibility to ensure that.
     */
    if (font == null) {
        return false;
    }

    /* Initialise these objects only once we start to use this API */
    synchronized (regFamilyKey) {
        if (createdByFamilyName == null) {
            createdByFamilyName = new Hashtable<String,FontFamily>();
            createdByFullName = new Hashtable<String,Font2D>();
        }
    }

    if (! FontAccess.getFontAccess().isCreatedFont(font)) {
        return false;
    }
    /* We want to ensure that this font cannot override existing
     * installed fonts. Check these conditions :
     * - family name is not that of an installed font
     * - full name is not that of an installed font
     * - family name is not the same as the full name of an installed font
     * - full name is not the same as the family name of an installed font
     * The last two of these may initially look odd but the reason is
     * that (unfortunately) Font constructors do not distinuguish these.
     * An extreme example of such a problem would be a font which has
     * family name "Dialog.Plain" and full name of "Dialog".
     * The one arguably overly stringent restriction here is that if an
     * application wants to supply a new member of an existing family
     * It will get rejected. But since the JRE can perform synthetic
     * styling in many cases its not necessary.
     * We don't apply the same logic to registered fonts. If apps want
     * to do this lets assume they have a reason. It won't cause problems
     * except for themselves.
     */
    HashSet<String> names = getInstalledNames();
    Locale l = getSystemStartupLocale();
    String familyName = font.getFamily(l).toLowerCase();
    String fullName = font.getFontName(l).toLowerCase();
    if (names.contains(familyName) || names.contains(fullName)) {
        return false;
    }

    /* Checks passed, now register the font */
    Hashtable<String,FontFamily> familyTable;
    Hashtable<String,Font2D> fullNameTable;
    if (!maybeMultiAppContext()) {
        familyTable = createdByFamilyName;
        fullNameTable = createdByFullName;
        fontsAreRegistered = true;
    } else {
        AppContext appContext = AppContext.getAppContext();
        @SuppressWarnings("unchecked")
        Hashtable<String,FontFamily> tmp1 =
            (Hashtable<String,FontFamily>)appContext.get(regFamilyKey);
        familyTable = tmp1;
        @SuppressWarnings("unchecked")
        Hashtable<String,Font2D> tmp2 =
            (Hashtable<String,Font2D>)appContext.get(regFullNameKey);
        fullNameTable = tmp2;

        if (familyTable == null) {
            familyTable = new Hashtable<String,FontFamily>();
            fullNameTable = new Hashtable<String,Font2D>();
            appContext.put(regFamilyKey, familyTable);
            appContext.put(regFullNameKey, fullNameTable);
        }
        fontsAreRegisteredPerAppContext = true;
    }
    /* Create the FontFamily and add font to the tables */
    Font2D font2D = FontUtilities.getFont2D(font);
    int style = font2D.getStyle();
    FontFamily family = familyTable.get(familyName);
    if (family == null) {
        family = new FontFamily(font.getFamily(l));
        familyTable.put(familyName, family);
    }
    /* Remove name cache entries if not using app contexts.
     * To accommodate a case where code may have registered first a plain
     * family member and then used it and is now registering a bold family
     * member, we need to remove all members of the family, so that the
     * new style can get picked up rather than continuing to synthesise.
     */
    if (fontsAreRegistered) {
        removeFromCache(family.getFont(Font.PLAIN));
        removeFromCache(family.getFont(Font.BOLD));
        removeFromCache(family.getFont(Font.ITALIC));
        removeFromCache(family.getFont(Font.BOLD|Font.ITALIC));
        removeFromCache(fullNameTable.get(fullName));
    }
    family.setFont(font2D, style);
    fullNameTable.put(fullName, font2D);
    return true;
}
 
Example 16
Source File: Container.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private void startLWModal() {
    // Store the app context on which this component is being shown.
    // Event dispatch thread of this app context will be sleeping until
    // we wake it by any event from hideAndDisposeHandler().
    modalAppContext = AppContext.getAppContext();

    // keep the KeyEvents from being dispatched
    // until the focus has been transfered
    long time = Toolkit.getEventQueue().getMostRecentKeyEventTime();
    Component predictedFocusOwner = (Component.isInstanceOf(this, "javax.swing.JInternalFrame")) ? ((javax.swing.JInternalFrame)(this)).getMostRecentFocusOwner() : null;
    if (predictedFocusOwner != null) {
        KeyboardFocusManager.getCurrentKeyboardFocusManager().
            enqueueKeyEvents(time, predictedFocusOwner);
    }
    // We have two mechanisms for blocking: 1. If we're on the
    // EventDispatchThread, start a new event pump. 2. If we're
    // on any other thread, call wait() on the treelock.
    final Container nativeContainer;
    synchronized (getTreeLock()) {
        nativeContainer = getHeavyweightContainer();
        if (nativeContainer.modalComp != null) {
            this.modalComp =  nativeContainer.modalComp;
            nativeContainer.modalComp = this;
            return;
        }
        else {
            nativeContainer.modalComp = this;
        }
    }

    Runnable pumpEventsForHierarchy = new Runnable() {
        public void run() {
            EventDispatchThread dispatchThread =
                (EventDispatchThread)Thread.currentThread();
            dispatchThread.pumpEventsForHierarchy(
                    new Conditional() {
                    public boolean evaluate() {
                    return ((windowClosingException == null) && (nativeContainer.modalComp != null)) ;
                    }
                    }, Container.this);
        }
    };

    if (EventQueue.isDispatchThread()) {
        SequencedEvent currentSequencedEvent =
            KeyboardFocusManager.getCurrentKeyboardFocusManager().
            getCurrentSequencedEvent();
        if (currentSequencedEvent != null) {
            currentSequencedEvent.dispose();
        }

        pumpEventsForHierarchy.run();
    } else {
        synchronized (getTreeLock()) {
            Toolkit.getEventQueue().
                postEvent(new PeerEvent(this,
                            pumpEventsForHierarchy,
                            PeerEvent.PRIORITY_EVENT));
            while ((windowClosingException == null) &&
                   (nativeContainer.modalComp != null))
            {
                try {
                    getTreeLock().wait();
                } catch (InterruptedException e) {
                    break;
                }
            }
        }
    }
    if (windowClosingException != null) {
        windowClosingException.fillInStackTrace();
        throw windowClosingException;
    }
    if (predictedFocusOwner != null) {
        KeyboardFocusManager.getCurrentKeyboardFocusManager().
            dequeueKeyEvents(time, predictedFocusOwner);
    }
}
 
Example 17
Source File: WindowEvent.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the other Window involved in this focus or activation change.
 * For a WINDOW_ACTIVATED or WINDOW_GAINED_FOCUS event, this is the Window
 * that lost activation or focus. For a WINDOW_DEACTIVATED or
 * WINDOW_LOST_FOCUS event, this is the Window that gained activation or
 * focus. For any other type of WindowEvent, or if the focus or activation
 * change occurs with a native application, with a Java application in a
 * different VM or context, or with no other Window, null is returned.
 *
 * @return the other Window involved in the focus or activation change, or
 *         null
 * @since 1.4
 */
public Window getOppositeWindow() {
    if (opposite == null) {
        return null;
    }

    return (SunToolkit.targetToAppContext(opposite) ==
            AppContext.getAppContext())
        ? opposite
        : null;
}
 
Example 18
Source File: bug6938813.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
private static void validate() throws Exception {
    AppContext appContext = AppContext.getAppContext();

    assertTrue(DTD.getDTD(DTD_KEY).getName().equals(DTD_KEY), "DTD.getDTD() mixed AppContexts");

    // Spoil hash value
    DTD invalidDtd = DTD.getDTD("invalid DTD");

    DTD.putDTDHash(DTD_KEY, invalidDtd);

    assertTrue(DTD.getDTD(DTD_KEY) == invalidDtd, "Something wrong with DTD.getDTD()");

    Object dtdKey = getParserDelegator_DTD_KEY();

    assertTrue(appContext.get(dtdKey) == null, "ParserDelegator mixed AppContexts");

    // Init default DTD
    new ParserDelegator();

    Object dtdValue = appContext.get(dtdKey);

    assertTrue(dtdValue != null, "ParserDelegator.defaultDTD isn't initialized");

    // Try reinit default DTD
    new ParserDelegator();

    assertTrue(dtdValue == appContext.get(dtdKey), "ParserDelegator.defaultDTD created a duplicate");

    HTMLEditorKit htmlEditorKit = new HTMLEditorKit();

    if (styleSheet == null) {
        // First AppContext
        styleSheet = htmlEditorKit.getStyleSheet();

        assertTrue(styleSheet != null, "htmlEditorKit.getStyleSheet() returns null");
        assertTrue(htmlEditorKit.getStyleSheet() == styleSheet, "Something wrong with htmlEditorKit.getStyleSheet()");
    } else {
        assertTrue(htmlEditorKit.getStyleSheet() != styleSheet, "HtmlEditorKit.getStyleSheet() mixed AppContexts");
    }
}
 
Example 19
Source File: WindowEvent.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the other Window involved in this focus or activation change.
 * For a WINDOW_ACTIVATED or WINDOW_GAINED_FOCUS event, this is the Window
 * that lost activation or focus. For a WINDOW_DEACTIVATED or
 * WINDOW_LOST_FOCUS event, this is the Window that gained activation or
 * focus. For any other type of WindowEvent, or if the focus or activation
 * change occurs with a native application, with a Java application in a
 * different VM or context, or with no other Window, null is returned.
 *
 * @return the other Window involved in the focus or activation change, or
 *         null
 * @since 1.4
 */
public Window getOppositeWindow() {
    if (opposite == null) {
        return null;
    }

    return (SunToolkit.targetToAppContext(opposite) ==
            AppContext.getAppContext())
        ? opposite
        : null;
}
 
Example 20
Source File: KeyboardFocusManager.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the active Window, if the active Window is in the same context
 * as the calling thread. Only a Frame or a Dialog can be the active
 * Window. The native windowing system may denote the active Window or its
 * children with special decorations, such as a highlighted title bar.
 * The active Window is always either the focused Window, or the first
 * Frame or Dialog that is an owner of the focused Window.
 *
 * @return the active Window, or null if the active Window is not a member
 *         of the calling thread's context
 * @see #getGlobalActiveWindow
 * @see #setGlobalActiveWindow
 */
public Window getActiveWindow() {
    synchronized (KeyboardFocusManager.class) {
        if (activeWindow == null) {
            return null;
        }

        return (activeWindow.appContext == AppContext.getAppContext())
            ? activeWindow
            : null;
    }
}