public Object run() { Thread t = new Thread(appContext.getThreadGroup(), runnable); t.setContextClassLoader(appContext.getContextClassLoader()); t.setPriority(Thread.NORM_PRIORITY + 1); t.setDaemon(true); return t; }
// WComponentPeer overrides @SuppressWarnings("unchecked") protected void disposeImpl() { AppContext appContext = SunToolkit.targetToAppContext(target); synchronized (appContext) { List<WWindowPeer> l = (List<WWindowPeer>) appContext.get(ACTIVE_WINDOWS_KEY); if (l != null) { l.remove(this); } } // Remove ourself from the Map of DisplayChangeListeners GraphicsConfiguration gc = getGraphicsConfiguration(); ((Win32GraphicsDevice) gc.getDevice()).removeDisplayChangedListener(this); synchronized (getStateLock()) { TranslucentWindowPainter currentPainter = painter; if (currentPainter != null) { currentPainter.flush(); // don't set the current one to null here; reduces the chances of // MT issues (like NPEs) } } super.disposeImpl(); }
/** 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); } } })); } }
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; // Synchronization on Window.class is needed for locking the // critical section of the window list in AppContext. synchronized (Window.class) { WeakReference<Window> weakRef = null; // Remove frame from the Window list in wrong AppContext { // Lookup current frame's AppContext @SuppressWarnings("unchecked") Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>) oldAppContext.get(Window.class); if (windowList != null) { for (WeakReference<Window> 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 { @SuppressWarnings("unchecked") Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>) 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); } } }
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 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(); 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; }
// ******************************** // 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 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; } }
/** * Pass an event onto the AWT component. * * @see java.awt.Component#processEvent(java.awt.AWTEvent) */ protected final void processEvent(AWTEvent event) { AppContext ac = SunToolkit.targetToAppContext(target); if (ac == null) { target.dispatchEvent(SwingToolkit.convertEvent(event, target)); } else { EventQueue eq = (EventQueue) ac.get(AppContext.EVENT_QUEUE_KEY); if (eq == null) { target.dispatchEvent(SwingToolkit.convertEvent(event, target)); } else { eq.postEvent(SwingToolkit.convertEvent(event, target)); } } }
/* * 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); } }
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"); }
public void propertyChange(PropertyChangeEvent e) { Window w = (Window) e.getNewValue(); if (w == null) { return; } AppContext appContext = SunToolkit.targetToAppContext(w); synchronized (appContext) { WWindowPeer wp = (WWindowPeer) w.getPeer(); // add/move wp to the end of the list List<WWindowPeer> l = (List<WWindowPeer>) appContext.get(ACTIVE_WINDOWS_KEY); if (l != null) { l.remove(wp); l.add(wp); } } }
private synchronized void dispose() { timer.stop(); UIManager.removePropertyChangeListener(this); synchronized (AnimationController.class) { AppContext.getAppContext().put(ANIMATION_CONTROLLER_KEY, null); } }
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; }
/** * 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; }
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(); } } }
/** * 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; }
@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); } }
/** 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); }
/** * 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(); } }
private static void putAppContext(Object key, Object value) { AppContext.getAppContext().put(key, value); }
public void run() { final EventQueue eq = (EventQueue) appContext.get(EVENT_QUEUE_KEY); if (eq != null) { eq.postEvent(AWTAutoShutdown.getShutdownEvent()); } }
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); } }
/** Constructor for MenuComponent. */ public MenuComponent() { appContext = AppContext.getAppContext(); SunToolkit.insertTargetMapping(this, appContext); }