private static Services getServicesForContext() { Services services = (Services) AppContext.getAppContext().get(Services.class); if (services == null) { services = new Services(); AppContext.getAppContext().put(Services.class, services); } return services; }
private synchronized void dispose() { timer.stop(); UIManager.removePropertyChangeListener(this); synchronized (AnimationController.class) { AppContext.getAppContext().put(ANIMATION_CONTROLLER_KEY, null); } }
public static void main(String[] args) { for (int i = 0; i < 100; i++) { Frame f = new Frame(); f.pack(); f.dispose(); } Vector garbage = new Vector(); while (true) { try { garbage.add(new byte[1000]); } catch (OutOfMemoryError e) { break; } } garbage = null; Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>) AppContext.getAppContext().get(Window.class); if (windowList != null && !windowList.isEmpty()) { throw new RuntimeException("Test FAILED: Window list is not empty: " + windowList.size()); } System.out.println("Test PASSED"); }
// ******************************** // Create PLAF // ******************************** 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; }
// ******************************** // Create PLAF // ******************************** public static ComponentUI createUI(JComponent c) { AppContext appContext = AppContext.getAppContext(); BasicButtonUI buttonUI = (BasicButtonUI) appContext.get(BASIC_BUTTON_UI_KEY); if (buttonUI == null) { buttonUI = new BasicButtonUI(); appContext.put(BASIC_BUTTON_UI_KEY, buttonUI); } return buttonUI; }
/** * 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; }
private static synchronized AnimationController getAnimationController() { AppContext appContext = AppContext.getAppContext(); Object obj = appContext.get(ANIMATION_CONTROLLER_KEY); if (obj == null) { obj = new AnimationController(); appContext.put(ANIMATION_CONTROLLER_KEY, obj); } return (AnimationController) obj; }
// ******************************** // Create PLAF // ******************************** public static ComponentUI createUI(JComponent c) { AppContext appContext = AppContext.getAppContext(); WindowsCheckBoxUI windowsCheckBoxUI = (WindowsCheckBoxUI) appContext.get(WINDOWS_CHECK_BOX_UI_KEY); if (windowsCheckBoxUI == null) { windowsCheckBoxUI = new WindowsCheckBoxUI(); appContext.put(WINDOWS_CHECK_BOX_UI_KEY, windowsCheckBoxUI); } return windowsCheckBoxUI; }
/** * Fetch the default layout queue. * * @return the default layout queue */ public static LayoutQueue getDefaultQueue() { AppContext ac = AppContext.getAppContext(); synchronized (DEFAULT_QUEUE) { LayoutQueue defaultQueue = (LayoutQueue) ac.get(DEFAULT_QUEUE); if (defaultQueue == null) { defaultQueue = new LayoutQueue(); ac.put(DEFAULT_QUEUE, defaultQueue); } return defaultQueue; } }
/** * Returns the <code>Window</code> object representing the full-screen window if the device is in * full-screen mode. * * @return the full-screen window, or <code>null</code> if the device is not in full-screen mode. * @see #setFullScreenWindow(Window) * @since 1.4 */ public Window getFullScreenWindow() { Window returnWindow = null; synchronized (fsAppContextLock) { // Only return a handle to the current fs window if we are in the // same AppContext that set the fs window if (fullScreenAppContext == AppContext.getAppContext()) { returnWindow = fullScreenWindow; } } return returnWindow; }
/** * 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); } return msm; } }
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed") private void patchStyledEditorKit(UIDefaults defaults) { URL url = getClass().getResource(getPrefix() + (JBUI.isHiDPI() ? "@2x.css" : ".css")); StyleSheet styleSheet = UIUtil.loadStyleSheet(url); defaults.put("StyledEditorKit.JBDefaultStyle", styleSheet); try { Field keyField = HTMLEditorKit.class.getDeclaredField("DEFAULT_STYLES_KEY"); keyField.setAccessible(true); AppContext.getAppContext().put(keyField.get(null), UIUtil.loadStyleSheet(url)); } catch (Exception e) { log(e); } }
/* * Returns all the ever active windows from the current AppContext. * The list is sorted by the time of activation, so the latest * active window is always at the end. */ @SuppressWarnings("unchecked") public static long[] getActiveWindowHandles() { AppContext appContext = AppContext.getAppContext(); synchronized (appContext) { List<WWindowPeer> l = (List<WWindowPeer>) appContext.get(ACTIVE_WINDOWS_KEY); if (l == null) { return null; } long[] result = new long[l.size()]; for (int j = 0; j < l.size(); j++) { result[j] = l.get(j).getHWnd(); } return result; } }
/* * The method maps the list of the active windows to the window's AppContext, * then the method registers ActiveWindowListener, GuiDisposedListener listeners; * it executes the initilialization only once per AppContext. */ @SuppressWarnings("unchecked") private static void initActiveWindowsTracking(Window w) { AppContext appContext = AppContext.getAppContext(); synchronized (appContext) { List<WWindowPeer> l = (List<WWindowPeer>) appContext.get(ACTIVE_WINDOWS_KEY); if (l == null) { l = new LinkedList<WWindowPeer>(); appContext.put(ACTIVE_WINDOWS_KEY, l); appContext.addPropertyChangeListener(AppContext.GUI_DISPOSED, guiDisposedListener); KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); kfm.addPropertyChangeListener("activeWindow", activeWindowListener); } } }
public void propertyChange(PropertyChangeEvent e) { boolean isDisposed = (Boolean) e.getNewValue(); if (isDisposed != true) { if (log.isLoggable(PlatformLogger.Level.FINE)) { log.fine(" Assertion (newValue != true) failed for AppContext.GUI_DISPOSED "); } } AppContext appContext = AppContext.getAppContext(); synchronized (appContext) { appContext.remove(ACTIVE_WINDOWS_KEY); appContext.removePropertyChangeListener(AppContext.GUI_DISPOSED, this); KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); kfm.removePropertyChangeListener("activeWindow", activeWindowListener); } }
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; }
/** * Enter full-screen mode, or return to windowed mode. The entered full-screen mode may be either * exclusive or simulated. Exclusive mode is only available if <code>isFullScreenSupported</code> * returns <code>true</code>. * * <p>Exclusive mode implies: * * <ul> * <li>Windows cannot overlap the full-screen window. All other application windows will always * appear beneath the full-screen window in the Z-order. * <li>There can be only one full-screen window on a device at any time, so calling this method * while there is an existing full-screen Window will cause the existing full-screen window * to return to windowed mode. * <li>Input method windows are disabled. It is advisable to call <code> * Component.enableInputMethods(false)</code> to make a component a non-client of the input * method framework. * </ul> * * <p>Simulated full-screen mode resizes the window to the size of the screen and positions it at * (0,0). * * <p>When entering full-screen mode, if the window to be used as a full-screen window is not * visible, this method will make it visible. It will remain visible when returning to windowed * mode. * * <p>When entering full-screen mode, all the translucency effects are reset for the window. Its * shape is set to {@code null}, the opacity value is set to 1.0f, and the background color alpha * is set to 255 (completely opaque). These values are not restored when returning to windowed * mode. * * <p>When returning to windowed mode from an exclusive full-screen window, any display changes * made by calling {@code setDisplayMode} are automatically restored to their original state. * * @param w a window to use as the full-screen window; {@code null} if returning to windowed mode. * Some platforms expect the fullscreen window to be a top-level component (i.e., a {@code * Frame}); therefore it is preferable to use a {@code Frame} here rather than a {@code * Window}. * @see #isFullScreenSupported * @see #getFullScreenWindow * @see #setDisplayMode * @see Component#enableInputMethods * @see Component#setVisible * @since 1.4 */ public void setFullScreenWindow(Window w) { if (w != null) { if (w.getShape() != null) { w.setShape(null); } if (w.getOpacity() < 1.0f) { w.setOpacity(1.0f); } if (!w.isOpaque()) { Color bgColor = w.getBackground(); bgColor = new Color(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), 255); w.setBackground(bgColor); } } if (fullScreenWindow != null && windowedModeBounds != null) { // if the window went into fs mode before it was realized it may // have (0,0) dimensions if (windowedModeBounds.width == 0) windowedModeBounds.width = 1; if (windowedModeBounds.height == 0) windowedModeBounds.height = 1; fullScreenWindow.setBounds(windowedModeBounds); } // Set the full screen window synchronized (fsAppContextLock) { // Associate fullscreen window with current AppContext if (w == null) { fullScreenAppContext = null; } else { fullScreenAppContext = AppContext.getAppContext(); } fullScreenWindow = w; } if (fullScreenWindow != null) { windowedModeBounds = fullScreenWindow.getBounds(); // Note that we use the graphics configuration of the device, // not the window's, because we're setting the fs window for // this device. Rectangle screenBounds = getDefaultConfiguration().getBounds(); fullScreenWindow.setBounds( screenBounds.x, screenBounds.y, screenBounds.width, screenBounds.height); fullScreenWindow.setVisible(true); fullScreenWindow.toFront(); } }
static void stopEventDispatchThreads() { for (AppContext appContext : getAppContexts()) { if (appContext.isDisposed()) { continue; } Runnable r = new PostShutdownEventRunnable(appContext); // For security reasons EventQueue.postEvent should only be called // on a thread that belongs to the corresponding thread group. if (appContext != AppContext.getAppContext()) { // Create a thread that belongs to the thread group associated // with the AppContext and invokes EventQueue.postEvent. PrivilegedAction action = new CreateThreadAction(appContext, r); Thread thread = (Thread) AccessController.doPrivileged(action); thread.start(); } else { r.run(); } } }
/** Free all resources allocated by this object */ public void dispose() { // Close all running jobs final AppContext appContext = AppContext.getAppContext(); ExecutorService executorService = (ExecutorService) appContext.get(SwingWorker.class); if (executorService != null) { executorService.shutdown(); } // Free UI resources if (editors != null) { editors.dispose(); } if (geoCatalog != null) { geoCatalog.dispose(); } if (mainFrame != null) { mainFrame.dispose(); } if (singleFrameTracker != null) { singleFrameTracker.close(); } if (editorFactoryTracker != null) { editorFactoryTracker.close(); } if (editorTracker != null) { editorTracker.close(); } if (toolBarTracker != null) { toolBarTracker.close(); } dockManager.dispose(); loggerCollection.dispose(); // Free libraries resources mainContext.dispose(); UIFactory.setMainFrame(null); }
/** Constructor for MenuComponent. */ public MenuComponent() { appContext = AppContext.getAppContext(); SunToolkit.insertTargetMapping(this, appContext); }
private static void putAppContext(Object key, Object value) { AppContext.getAppContext().put(key, value); }
private static Object getAppContext(Object key) { return AppContext.getAppContext().get(key); }
/** * Set the default layout queue. * * @param q the new queue. */ public static void setDefaultQueue(LayoutQueue q) { synchronized (DEFAULT_QUEUE) { AppContext.getAppContext().put(DEFAULT_QUEUE, q); } }
void reset() { AppContext.getAppContext().remove(this); }