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); } } }
/** 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); } } })); } }
// 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(); }
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(); 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(); 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(); 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)); } } }
/* * 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); } } }
/* * 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; } }
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 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; }
/** 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); }
public void run() { final EventQueue eq = (EventQueue) appContext.get(EVENT_QUEUE_KEY); if (eq != null) { eq.postEvent(AWTAutoShutdown.getShutdownEvent()); } }