/* * 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) { 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); } }