Java Code Examples for sun.awt.AppContext

The following examples show how to use sun.awt.AppContext. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: openjdk-8-source   Source File: GTKStyle.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static Dimension[] getIconSizesMap() {
    AppContext appContext = AppContext.getAppContext();
    Dimension[] iconSizes = (Dimension[])appContext.get(ICON_SIZE_KEY);

    if (iconSizes == null) {
        iconSizes = new Dimension[7];
        iconSizes[0] = null;                  // GTK_ICON_SIZE_INVALID
        iconSizes[1] = new Dimension(16, 16); // GTK_ICON_SIZE_MENU
        iconSizes[2] = new Dimension(18, 18); // GTK_ICON_SIZE_SMALL_TOOLBAR
        iconSizes[3] = new Dimension(24, 24); // GTK_ICON_SIZE_LARGE_TOOLBAR
        iconSizes[4] = new Dimension(20, 20); // GTK_ICON_SIZE_BUTTON
        iconSizes[5] = new Dimension(32, 32); // GTK_ICON_SIZE_DND
        iconSizes[6] = new Dimension(48, 48); // GTK_ICON_SIZE_DIALOG
        appContext.put(ICON_SIZE_KEY, iconSizes);
    }
    return iconSizes;
}
 
Example 2
Source Project: jdk8u_jdk   Source File: _AppEventHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
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);
            }
        });
    }
}
 
Example 3
Source Project: jdk8u-jdk   Source File: SunClipboard.java    License: 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 Project: TencentKona-8   Source File: SunClipboard.java    License: GNU General Public License v2.0 6 votes vote down vote up
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();
        currentFormats = null;
    }
}
 
Example 5
/**
 * 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);
}
 
Example 6
Source Project: jdk1.8-source-analysis   Source File: GTKStyle.java    License: Apache License 2.0 6 votes vote down vote up
private static Dimension[] getIconSizesMap() {
    AppContext appContext = AppContext.getAppContext();
    Dimension[] iconSizes = (Dimension[])appContext.get(ICON_SIZE_KEY);

    if (iconSizes == null) {
        iconSizes = new Dimension[7];
        iconSizes[0] = null;                  // GTK_ICON_SIZE_INVALID
        iconSizes[1] = new Dimension(16, 16); // GTK_ICON_SIZE_MENU
        iconSizes[2] = new Dimension(18, 18); // GTK_ICON_SIZE_SMALL_TOOLBAR
        iconSizes[3] = new Dimension(24, 24); // GTK_ICON_SIZE_LARGE_TOOLBAR
        iconSizes[4] = new Dimension(20, 20); // GTK_ICON_SIZE_BUTTON
        iconSizes[5] = new Dimension(32, 32); // GTK_ICON_SIZE_DND
        iconSizes[6] = new Dimension(48, 48); // GTK_ICON_SIZE_DIALOG
        appContext.put(ICON_SIZE_KEY, iconSizes);
    }
    return iconSizes;
}
 
Example 7
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);
            }
        });
    }
}
 
Example 8
/**
 * Returns the ideal font style for the font identified by key.
 */
static int getDefaultFontStyle(int key) {
    if (key != WINDOW_TITLE_FONT) {
        Object boldMetal = null;
        if (AppContext.getAppContext().get(
                SwingUtilities2.LAF_STATE_KEY) != null) {
            // Only access the boldMetal key if a look and feel has
            // been loaded, otherwise we'll trigger loading the look
            // and feel.
            boldMetal = UIManager.get("swing.boldMetal");
        }
        if (boldMetal != null) {
            if (Boolean.FALSE.equals(boldMetal)) {
                return Font.PLAIN;
            }
        }
        else if (PLAIN_FONTS) {
            return Font.PLAIN;
        }
    }
    return fontStyles[key];
}
 
Example 9
/**
 * 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 10
Source Project: JDKSourceCode1.8   Source File: SystemTray.java    License: MIT License 6 votes vote down vote up
/**
 * 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);
}
 
Example 11
Source Project: openjdk-jdk9   Source File: RepaintManager.java    License: 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 12
Source Project: jdk8u-jdk   Source File: DefaultMetalTheme.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the ideal font style for the font identified by key.
 */
static int getDefaultFontStyle(int key) {
    if (key != WINDOW_TITLE_FONT) {
        Object boldMetal = null;
        if (AppContext.getAppContext().get(
                SwingUtilities2.LAF_STATE_KEY) != null) {
            // Only access the boldMetal key if a look and feel has
            // been loaded, otherwise we'll trigger loading the look
            // and feel.
            boldMetal = UIManager.get("swing.boldMetal");
        }
        if (boldMetal != null) {
            if (Boolean.FALSE.equals(boldMetal)) {
                return Font.PLAIN;
            }
        }
        else if (PLAIN_FONTS) {
            return Font.PLAIN;
        }
    }
    return fontStyles[key];
}
 
Example 13
Source Project: jdk8u60   Source File: JTextComponent.java    License: 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 14
Source Project: openjdk-jdk9   Source File: SunClipboard.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks change of the {@code DataFlavor}s and, if necessary,
 * posts notifications on {@code FlavorEvent}s to the
 * AppContexts' EDTs.
 * The parameter {@code formats} is null iff we have just
 * failed to get formats available on the clipboard.
 *
 * @param formats data formats that have just been retrieved from
 *        this clipboard
 */
protected final void checkChange(final long[] formats) {
    if (Arrays.equals(formats, currentFormats)) {
        // we've been able to successfully get available on the clipboard
        // DataFlavors this and previous time and they are coincident;
        // don't notify
        return;
    }
    currentFormats = formats;

    for (final AppContext appContext : AppContext.getAppContexts()) {
        if (appContext == null || appContext.isDisposed()) {
            continue;
        }
        Set<FlavorListener> flavorListeners = getFlavorListeners(appContext);
        if (flavorListeners != null) {
            for (FlavorListener listener : flavorListeners) {
                if (listener != null) {
                    PeerEvent peerEvent = new PeerEvent(this,
                            () -> listener.flavorsChanged(new FlavorEvent(SunClipboard.this)),
                            PeerEvent.PRIORITY_EVENT);
                    SunToolkit.postEvent(appContext, peerEvent);
                }
            }
        }
    }
}
 
Example 15
Source Project: Java8CN   Source File: BasicToggleButtonUI.java    License: Apache License 2.0 5 votes vote down vote up
public static ComponentUI createUI(JComponent b) {
    AppContext appContext = AppContext.getAppContext();
    BasicToggleButtonUI toggleButtonUI =
            (BasicToggleButtonUI) appContext.get(BASIC_TOGGLE_BUTTON_UI_KEY);
    if (toggleButtonUI == null) {
        toggleButtonUI = new BasicToggleButtonUI();
        appContext.put(BASIC_TOGGLE_BUTTON_UI_KEY, toggleButtonUI);
    }
    return toggleButtonUI;
}
 
Example 16
Source Project: openjdk-8   Source File: AppletSecurity.java    License: 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 17
Source Project: jdk8u-dev-jdk   Source File: SentEvent.java    License: GNU General Public License v2.0 5 votes vote down vote up
SentEvent(AWTEvent nested, AppContext toNotify) {
    super((nested != null)
              ? nested.getSource()
              : Toolkit.getDefaultToolkit(),
          ID);
    this.nested = nested;
    this.toNotify = toNotify;
}
 
Example 18
Source Project: openjdk-8   Source File: BasicTextUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static DragListener getDragListener() {
    synchronized(DragListener.class) {
        DragListener listener =
            (DragListener)AppContext.getAppContext().
                get(DragListener.class);

        if (listener == null) {
            listener = new DragListener();
            AppContext.getAppContext().put(DragListener.class, listener);
        }

        return listener;
    }
}
 
Example 19
Source Project: openjdk-jdk9   Source File: ImageFetcher.java    License: GNU General Public License v2.0 5 votes vote down vote up
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;
    }
}
 
Example 20
Source Project: dragonwell8_jdk   Source File: TrayIcon.java    License: GNU General Public License v2.0 5 votes vote down vote up
private TrayIcon()
  throws UnsupportedOperationException, HeadlessException, SecurityException
{
    SystemTray.checkSystemTrayAllowed();
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }
    if (!SystemTray.isSupported()) {
        throw new UnsupportedOperationException();
    }
    SunToolkit.insertTargetMapping(this, AppContext.getAppContext());
}
 
Example 21
Source Project: hottub   Source File: WindowsLabelUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static ComponentUI createUI(JComponent c) {
    AppContext appContext = AppContext.getAppContext();
    WindowsLabelUI windowsLabelUI =
            (WindowsLabelUI) appContext.get(WINDOWS_LABEL_UI_KEY);
    if (windowsLabelUI == null) {
        windowsLabelUI = new WindowsLabelUI();
        appContext.put(WINDOWS_LABEL_UI_KEY, windowsLabelUI);
    }
    return windowsLabelUI;
}
 
Example 22
Source Project: jdk8u-jdk   Source File: Toolkit.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized void removePropertyChangeListener(
        String propertyName,
        PropertyChangeListener listener)
{
    PropertyChangeSupport pcs = (PropertyChangeSupport)
            AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
    if (null != pcs) {
        pcs.removePropertyChangeListener(propertyName, listener);
    }
}
 
Example 23
Source Project: jdk8u_jdk   Source File: MetalLabelUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static ComponentUI createUI(JComponent c) {
    if (System.getSecurityManager() != null) {
        AppContext appContext = AppContext.getAppContext();
        MetalLabelUI safeMetalLabelUI =
                (MetalLabelUI) appContext.get(METAL_LABEL_UI_KEY);
        if (safeMetalLabelUI == null) {
            safeMetalLabelUI = new MetalLabelUI();
            appContext.put(METAL_LABEL_UI_KEY, safeMetalLabelUI);
        }
        return safeMetalLabelUI;
    }
    return metalLabelUI;
}
 
Example 24
Source Project: jdk1.8-source-analysis   Source File: SystemFlavorMap.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the default FlavorMap for this thread's ClassLoader.
 */
public static FlavorMap getDefaultFlavorMap() {
    AppContext context = AppContext.getAppContext();
    FlavorMap fm = (FlavorMap) context.get(FLAVOR_MAP_KEY);
    if (fm == null) {
        fm = new SystemFlavorMap();
        context.put(FLAVOR_MAP_KEY, fm);
    }
    return fm;
}
 
Example 25
void uninstall() {
    synchronized (MOUSE_GRABBER_KEY) {
        MenuSelectionManager.defaultManager().removeChangeListener(this);
        ungrabWindow();
        AppContext.getAppContext().remove(MOUSE_GRABBER_KEY);
    }
}
 
Example 26
Source Project: jdk8u_jdk   Source File: Toolkit.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized void removePropertyChangeListener(
        String propertyName,
        PropertyChangeListener listener)
{
    PropertyChangeSupport pcs = (PropertyChangeSupport)
            AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
    if (null != pcs) {
        pcs.removePropertyChangeListener(propertyName, listener);
    }
}
 
Example 27
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 28
Source Project: jdk8u-jdk   Source File: Effect.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected static ArrayCache getArrayCache() {
    ArrayCache cache = (ArrayCache)AppContext.getAppContext().get(ArrayCache.class);
    if (cache == null){
        cache = new ArrayCache();
        AppContext.getAppContext().put(ArrayCache.class,cache);
    }
    return cache;
}
 
Example 29
Source Project: TencentKona-8   Source File: Toolkit.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized PropertyChangeListener[] getPropertyChangeListeners()
{
    PropertyChangeSupport pcs = (PropertyChangeSupport)
            AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY);
    if (null != pcs) {
        return pcs.getPropertyChangeListeners();
    } else {
        return new PropertyChangeListener[0];
    }
}
 
Example 30
Source Project: jdk8u-jdk   Source File: InputMethodEvent.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the most recent event time in the {@code EventQueue} which the {@code source}
 * belongs to.
 *
 * @param source the source of the event
 * @exception  IllegalArgumentException  if source is null.
 * @return most recent event time in the {@code EventQueue}
 */
private static long getMostRecentEventTimeForSource(Object source) {
    if (source == null) {
        // throw the IllegalArgumentException to conform to EventObject spec
        throw new IllegalArgumentException("null source");
    }
    AppContext appContext = SunToolkit.targetToAppContext(source);
    EventQueue eventQueue = SunToolkit.getSystemEventQueueImplPP(appContext);
    return AWTAccessor.getEventQueueAccessor().getMostRecentEventTime(eventQueue);
}