jdk/src/share/classes/java/awt/Window.java

Print this page




 424      * must be displayed with a warning banner.
 425      *
 426      * @param gc the <code>GraphicsConfiguration</code> of the target screen
 427      *     device. If <code>gc</code> is <code>null</code>, the system default
 428      *     <code>GraphicsConfiguration</code> is assumed
 429      * @exception IllegalArgumentException if <code>gc</code>
 430      *    is not from a screen device
 431      * @exception HeadlessException when
 432      *     <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
 433      *
 434      * @see java.awt.GraphicsEnvironment#isHeadless
 435      * @see java.lang.SecurityManager#checkTopLevelWindow
 436      */
 437     Window(GraphicsConfiguration gc) {
 438         init(gc);
 439     }
 440 
 441     transient Object anchor = new Object();
 442     static class WindowDisposerRecord implements sun.java2d.DisposerRecord {
 443         final WeakReference<Window> owner;
 444         final WeakReference weakThis;
 445         final WeakReference<AppContext> context;
 446         WindowDisposerRecord(AppContext context, Window victim) {
 447             owner = new WeakReference<Window>(victim.getOwner());
 448             weakThis = victim.weakThis;
 449             this.context = new WeakReference<AppContext>(context);
 450         }
 451         public void dispose() {
 452             Window parent = owner.get();
 453             if (parent != null) {
 454                 parent.removeOwnedWindow(weakThis);
 455             }
 456             AppContext ac = context.get();
 457             if (null != ac) {
 458                 Window.removeFromWindowList(ac, weakThis);
 459             }
 460         }
 461     }
 462 
 463     private GraphicsConfiguration initGC(GraphicsConfiguration gc) {
 464         GraphicsEnvironment.checkHeadless();


1525             return v;
1526         }
1527     }
1528 
1529     static IdentityArrayList<Window> getAllUnblockedWindows() {
1530         synchronized (allWindows) {
1531             IdentityArrayList<Window> unblocked = new IdentityArrayList<Window>();
1532             for (int i = 0; i < allWindows.size(); i++) {
1533                 Window w = allWindows.get(i);
1534                 if (!w.isModalBlocked()) {
1535                     unblocked.add(w);
1536                 }
1537             }
1538             return unblocked;
1539         }
1540     }
1541 
1542     private static Window[] getWindows(AppContext appContext) {
1543         synchronized (Window.class) {
1544             Window realCopy[];

1545             Vector<WeakReference<Window>> windowList =
1546                 (Vector<WeakReference<Window>>)appContext.get(Window.class);
1547             if (windowList != null) {
1548                 int fullSize = windowList.size();
1549                 int realSize = 0;
1550                 Window fullCopy[] = new Window[fullSize];
1551                 for (int i = 0; i < fullSize; i++) {
1552                     Window w = windowList.get(i).get();
1553                     if (w != null) {
1554                         fullCopy[realSize++] = w;
1555                     }
1556                 }
1557                 if (fullSize != realSize) {
1558                     realCopy = Arrays.copyOf(fullCopy, realSize);
1559                 } else {
1560                     realCopy = fullCopy;
1561                 }
1562             } else {
1563                 realCopy = new Window[0];
1564             }


1849     public synchronized void removeWindowFocusListener(WindowFocusListener l) {
1850         if (l == null) {
1851             return;
1852         }
1853         windowFocusListener = AWTEventMulticaster.remove(windowFocusListener, l);
1854     }
1855 
1856     /**
1857      * Returns an array of all the window listeners
1858      * registered on this window.
1859      *
1860      * @return all of this window's <code>WindowListener</code>s
1861      *         or an empty array if no window
1862      *         listeners are currently registered
1863      *
1864      * @see #addWindowListener
1865      * @see #removeWindowListener
1866      * @since 1.4
1867      */
1868     public synchronized WindowListener[] getWindowListeners() {
1869         return (WindowListener[])(getListeners(WindowListener.class));
1870     }
1871 
1872     /**
1873      * Returns an array of all the window focus listeners
1874      * registered on this window.
1875      *
1876      * @return all of this window's <code>WindowFocusListener</code>s
1877      *         or an empty array if no window focus
1878      *         listeners are currently registered
1879      *
1880      * @see #addWindowFocusListener
1881      * @see #removeWindowFocusListener
1882      * @since 1.4
1883      */
1884     public synchronized WindowFocusListener[] getWindowFocusListeners() {
1885         return (WindowFocusListener[])(getListeners(WindowFocusListener.class));
1886     }
1887 
1888     /**
1889      * Returns an array of all the window state listeners
1890      * registered on this window.
1891      *
1892      * @return all of this window's <code>WindowStateListener</code>s
1893      *         or an empty array if no window state
1894      *         listeners are currently registered
1895      *
1896      * @see #addWindowStateListener
1897      * @see #removeWindowStateListener
1898      * @since 1.4
1899      */
1900     public synchronized WindowStateListener[] getWindowStateListeners() {
1901         return (WindowStateListener[])(getListeners(WindowStateListener.class));
1902     }
1903 
1904 
1905     /**
1906      * Returns an array of all the objects currently registered
1907      * as <code><em>Foo</em>Listener</code>s
1908      * upon this <code>Window</code>.
1909      * <code><em>Foo</em>Listener</code>s are registered using the
1910      * <code>add<em>Foo</em>Listener</code> method.
1911      *
1912      * <p>
1913      *
1914      * You can specify the <code>listenerType</code> argument
1915      * with a class literal, such as
1916      * <code><em>Foo</em>Listener.class</code>.
1917      * For example, you can query a
1918      * <code>Window</code> <code>w</code>
1919      * for its window listeners with the following code:
1920      *
1921      * <pre>WindowListener[] wls = (WindowListener[])(w.getListeners(WindowListener.class));</pre>


1997      * @param e the event
1998      */
1999     protected void processEvent(AWTEvent e) {
2000         if (e instanceof WindowEvent) {
2001             switch (e.getID()) {
2002                 case WindowEvent.WINDOW_OPENED:
2003                 case WindowEvent.WINDOW_CLOSING:
2004                 case WindowEvent.WINDOW_CLOSED:
2005                 case WindowEvent.WINDOW_ICONIFIED:
2006                 case WindowEvent.WINDOW_DEICONIFIED:
2007                 case WindowEvent.WINDOW_ACTIVATED:
2008                 case WindowEvent.WINDOW_DEACTIVATED:
2009                     processWindowEvent((WindowEvent)e);
2010                     break;
2011                 case WindowEvent.WINDOW_GAINED_FOCUS:
2012                 case WindowEvent.WINDOW_LOST_FOCUS:
2013                     processWindowFocusEvent((WindowEvent)e);
2014                     break;
2015                 case WindowEvent.WINDOW_STATE_CHANGED:
2016                     processWindowStateEvent((WindowEvent)e);
2017                 default:
2018                     break;
2019             }
2020             return;
2021         }
2022         super.processEvent(e);
2023     }
2024 
2025     /**
2026      * Processes window events occurring on this window by
2027      * dispatching them to any registered WindowListener objects.
2028      * NOTE: This method will not be called unless window events
2029      * are enabled for this component; this happens when one of the
2030      * following occurs:
2031      * <ul>
2032      * <li>A WindowListener object is registered via
2033      *     <code>addWindowListener</code>
2034      * <li>Window events are enabled via <code>enableEvents</code>
2035      * </ul>
2036      * <p>Note that if the event parameter is <code>null</code>
2037      * the behavior is unspecified and may result in an


2365      * ancestors, then the current KeyboardFocusManager's default traversal key
2366      * is returned.
2367      *
2368      * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
2369      *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
2370      *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
2371      *         KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
2372      * @return the AWTKeyStroke for the specified key
2373      * @see Container#setFocusTraversalKeys
2374      * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
2375      * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
2376      * @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS
2377      * @see KeyboardFocusManager#DOWN_CYCLE_TRAVERSAL_KEYS
2378      * @throws IllegalArgumentException if id is not one of
2379      *         KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
2380      *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
2381      *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
2382      *         KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
2383      * @since 1.4
2384      */

2385     public Set<AWTKeyStroke> getFocusTraversalKeys(int id) {
2386         if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH) {
2387             throw new IllegalArgumentException("invalid focus traversal key identifier");
2388         }
2389 
2390         // Okay to return Set directly because it is an unmodifiable view

2391         Set keystrokes = (focusTraversalKeys != null)
2392             ? focusTraversalKeys[id]
2393             : null;
2394 
2395         if (keystrokes != null) {
2396             return keystrokes;
2397         } else {
2398             return KeyboardFocusManager.getCurrentKeyboardFocusManager().
2399                 getDefaultFocusTraversalKeys(id);
2400         }
2401     }
2402 
2403     /**
2404      * Does nothing because Windows must always be roots of a focus traversal
2405      * cycle. The passed-in value is ignored.
2406      *
2407      * @param focusCycleRoot this value is ignored
2408      * @see #isFocusCycleRoot
2409      * @see Container#setFocusTraversalPolicy
2410      * @see Container#getFocusTraversalPolicy


2748      * @deprecated As of J2SE 1.4, replaced by
2749      * {@link Component#applyComponentOrientation Component.applyComponentOrientation}.
2750      */
2751     @Deprecated
2752     public void applyResourceBundle(ResourceBundle rb) {
2753         applyComponentOrientation(ComponentOrientation.getOrientation(rb));
2754     }
2755 
2756     /**
2757      * @deprecated As of J2SE 1.4, replaced by
2758      * {@link Component#applyComponentOrientation Component.applyComponentOrientation}.
2759      */
2760     @Deprecated
2761     public void applyResourceBundle(String rbName) {
2762         applyResourceBundle(ResourceBundle.getBundle(rbName));
2763     }
2764 
2765    /*
2766     * Support for tracking all windows owned by this window
2767     */
2768     void addOwnedWindow(WeakReference weakWindow) {
2769         if (weakWindow != null) {
2770             synchronized(ownedWindowList) {
2771                 // this if statement should really be an assert, but we don't
2772                 // have asserts...
2773                 if (!ownedWindowList.contains(weakWindow)) {
2774                     ownedWindowList.addElement(weakWindow);
2775                 }
2776             }
2777         }
2778     }
2779 
2780     void removeOwnedWindow(WeakReference weakWindow) {
2781         if (weakWindow != null) {
2782             // synchronized block not required since removeElement is
2783             // already synchronized
2784             ownedWindowList.removeElement(weakWindow);
2785         }
2786     }
2787 
2788     void connectOwnedWindow(Window child) {
2789         child.parent = this;
2790         addOwnedWindow(child.weakThis);
2791     }
2792 
2793     private void addToWindowList() {
2794         synchronized (Window.class) {

2795             Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>)appContext.get(Window.class);
2796             if (windowList == null) {
2797                 windowList = new Vector<WeakReference<Window>>();
2798                 appContext.put(Window.class, windowList);
2799             }
2800             windowList.add(weakThis);
2801         }
2802     }
2803 
2804     private static void removeFromWindowList(AppContext context, WeakReference weakThis) {
2805         synchronized (Window.class) {

2806             Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>)context.get(Window.class);
2807             if (windowList != null) {
2808                 windowList.remove(weakThis);
2809             }
2810         }
2811     }
2812 
2813     private void removeFromWindowList() {
2814         removeFromWindowList(appContext, weakThis);
2815     }
2816 
2817     /**
2818      * Window type.
2819      *
2820      * Synchronization: ObjectLock
2821      */
2822     private Type type = Type.NORMAL;
2823 
2824     /**
2825      * Sets the type of the window.


2928             for (Image i : icons) {
2929                 if (i instanceof Serializable) {
2930                     s.writeObject(i);
2931                 }
2932             }
2933         }
2934         s.writeObject(null);
2935     }
2936 
2937     //
2938     // Part of deserialization procedure to be called before
2939     // user's code.
2940     //
2941     private void initDeserializedWindow() {
2942         setWarningString();
2943         inputContextLock = new Object();
2944 
2945         // Deserialized Windows are not yet visible.
2946         visible = false;
2947 
2948         weakThis = new WeakReference(this);
2949 
2950         anchor = new Object();
2951         sun.java2d.Disposer.addRecord(anchor, new WindowDisposerRecord(appContext, this));
2952 
2953         addToWindowList();
2954         initGC(null);
2955     }
2956 
2957     private void deserializeResources(ObjectInputStream s)
2958         throws ClassNotFoundException, IOException, HeadlessException {
2959             ownedWindowList = new Vector();
2960 
2961             if (windowSerializedDataVersion < 2) {
2962                 // Translate old-style focus tracking to new model. For 1.4 and
2963                 // later releases, we'll rely on the Window's initial focusable
2964                 // Component.
2965                 if (focusMgr != null) {
2966                     if (focusMgr.focusOwner != null) {
2967                         KeyboardFocusManager.
2968                             setMostRecentFocusOwner(this, focusMgr.focusOwner);
2969                     }
2970                 }
2971 
2972                 // This field is non-transient and relies on default serialization.
2973                 // However, the default value is insufficient, so we need to set
2974                 // it explicitly for object data streams prior to 1.4.
2975                 focusableWindowState = true;
2976 
2977 
2978             }
2979 




 424      * must be displayed with a warning banner.
 425      *
 426      * @param gc the <code>GraphicsConfiguration</code> of the target screen
 427      *     device. If <code>gc</code> is <code>null</code>, the system default
 428      *     <code>GraphicsConfiguration</code> is assumed
 429      * @exception IllegalArgumentException if <code>gc</code>
 430      *    is not from a screen device
 431      * @exception HeadlessException when
 432      *     <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
 433      *
 434      * @see java.awt.GraphicsEnvironment#isHeadless
 435      * @see java.lang.SecurityManager#checkTopLevelWindow
 436      */
 437     Window(GraphicsConfiguration gc) {
 438         init(gc);
 439     }
 440 
 441     transient Object anchor = new Object();
 442     static class WindowDisposerRecord implements sun.java2d.DisposerRecord {
 443         final WeakReference<Window> owner;
 444         final WeakReference<Window> weakThis;
 445         final WeakReference<AppContext> context;
 446         WindowDisposerRecord(AppContext context, Window victim) {
 447             owner = new WeakReference<Window>(victim.getOwner());
 448             weakThis = victim.weakThis;
 449             this.context = new WeakReference<AppContext>(context);
 450         }
 451         public void dispose() {
 452             Window parent = owner.get();
 453             if (parent != null) {
 454                 parent.removeOwnedWindow(weakThis);
 455             }
 456             AppContext ac = context.get();
 457             if (null != ac) {
 458                 Window.removeFromWindowList(ac, weakThis);
 459             }
 460         }
 461     }
 462 
 463     private GraphicsConfiguration initGC(GraphicsConfiguration gc) {
 464         GraphicsEnvironment.checkHeadless();


1525             return v;
1526         }
1527     }
1528 
1529     static IdentityArrayList<Window> getAllUnblockedWindows() {
1530         synchronized (allWindows) {
1531             IdentityArrayList<Window> unblocked = new IdentityArrayList<Window>();
1532             for (int i = 0; i < allWindows.size(); i++) {
1533                 Window w = allWindows.get(i);
1534                 if (!w.isModalBlocked()) {
1535                     unblocked.add(w);
1536                 }
1537             }
1538             return unblocked;
1539         }
1540     }
1541 
1542     private static Window[] getWindows(AppContext appContext) {
1543         synchronized (Window.class) {
1544             Window realCopy[];
1545             @SuppressWarnings("unchecked")
1546             Vector<WeakReference<Window>> windowList =
1547                 (Vector<WeakReference<Window>>)appContext.get(Window.class);
1548             if (windowList != null) {
1549                 int fullSize = windowList.size();
1550                 int realSize = 0;
1551                 Window fullCopy[] = new Window[fullSize];
1552                 for (int i = 0; i < fullSize; i++) {
1553                     Window w = windowList.get(i).get();
1554                     if (w != null) {
1555                         fullCopy[realSize++] = w;
1556                     }
1557                 }
1558                 if (fullSize != realSize) {
1559                     realCopy = Arrays.copyOf(fullCopy, realSize);
1560                 } else {
1561                     realCopy = fullCopy;
1562                 }
1563             } else {
1564                 realCopy = new Window[0];
1565             }


1850     public synchronized void removeWindowFocusListener(WindowFocusListener l) {
1851         if (l == null) {
1852             return;
1853         }
1854         windowFocusListener = AWTEventMulticaster.remove(windowFocusListener, l);
1855     }
1856 
1857     /**
1858      * Returns an array of all the window listeners
1859      * registered on this window.
1860      *
1861      * @return all of this window's <code>WindowListener</code>s
1862      *         or an empty array if no window
1863      *         listeners are currently registered
1864      *
1865      * @see #addWindowListener
1866      * @see #removeWindowListener
1867      * @since 1.4
1868      */
1869     public synchronized WindowListener[] getWindowListeners() {
1870         return getListeners(WindowListener.class);
1871     }
1872 
1873     /**
1874      * Returns an array of all the window focus listeners
1875      * registered on this window.
1876      *
1877      * @return all of this window's <code>WindowFocusListener</code>s
1878      *         or an empty array if no window focus
1879      *         listeners are currently registered
1880      *
1881      * @see #addWindowFocusListener
1882      * @see #removeWindowFocusListener
1883      * @since 1.4
1884      */
1885     public synchronized WindowFocusListener[] getWindowFocusListeners() {
1886         return getListeners(WindowFocusListener.class);
1887     }
1888 
1889     /**
1890      * Returns an array of all the window state listeners
1891      * registered on this window.
1892      *
1893      * @return all of this window's <code>WindowStateListener</code>s
1894      *         or an empty array if no window state
1895      *         listeners are currently registered
1896      *
1897      * @see #addWindowStateListener
1898      * @see #removeWindowStateListener
1899      * @since 1.4
1900      */
1901     public synchronized WindowStateListener[] getWindowStateListeners() {
1902         return getListeners(WindowStateListener.class);
1903     }
1904 
1905 
1906     /**
1907      * Returns an array of all the objects currently registered
1908      * as <code><em>Foo</em>Listener</code>s
1909      * upon this <code>Window</code>.
1910      * <code><em>Foo</em>Listener</code>s are registered using the
1911      * <code>add<em>Foo</em>Listener</code> method.
1912      *
1913      * <p>
1914      *
1915      * You can specify the <code>listenerType</code> argument
1916      * with a class literal, such as
1917      * <code><em>Foo</em>Listener.class</code>.
1918      * For example, you can query a
1919      * <code>Window</code> <code>w</code>
1920      * for its window listeners with the following code:
1921      *
1922      * <pre>WindowListener[] wls = (WindowListener[])(w.getListeners(WindowListener.class));</pre>


1998      * @param e the event
1999      */
2000     protected void processEvent(AWTEvent e) {
2001         if (e instanceof WindowEvent) {
2002             switch (e.getID()) {
2003                 case WindowEvent.WINDOW_OPENED:
2004                 case WindowEvent.WINDOW_CLOSING:
2005                 case WindowEvent.WINDOW_CLOSED:
2006                 case WindowEvent.WINDOW_ICONIFIED:
2007                 case WindowEvent.WINDOW_DEICONIFIED:
2008                 case WindowEvent.WINDOW_ACTIVATED:
2009                 case WindowEvent.WINDOW_DEACTIVATED:
2010                     processWindowEvent((WindowEvent)e);
2011                     break;
2012                 case WindowEvent.WINDOW_GAINED_FOCUS:
2013                 case WindowEvent.WINDOW_LOST_FOCUS:
2014                     processWindowFocusEvent((WindowEvent)e);
2015                     break;
2016                 case WindowEvent.WINDOW_STATE_CHANGED:
2017                     processWindowStateEvent((WindowEvent)e);

2018                     break;
2019             }
2020             return;
2021         }
2022         super.processEvent(e);
2023     }
2024 
2025     /**
2026      * Processes window events occurring on this window by
2027      * dispatching them to any registered WindowListener objects.
2028      * NOTE: This method will not be called unless window events
2029      * are enabled for this component; this happens when one of the
2030      * following occurs:
2031      * <ul>
2032      * <li>A WindowListener object is registered via
2033      *     <code>addWindowListener</code>
2034      * <li>Window events are enabled via <code>enableEvents</code>
2035      * </ul>
2036      * <p>Note that if the event parameter is <code>null</code>
2037      * the behavior is unspecified and may result in an


2365      * ancestors, then the current KeyboardFocusManager's default traversal key
2366      * is returned.
2367      *
2368      * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
2369      *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
2370      *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
2371      *         KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
2372      * @return the AWTKeyStroke for the specified key
2373      * @see Container#setFocusTraversalKeys
2374      * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
2375      * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
2376      * @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS
2377      * @see KeyboardFocusManager#DOWN_CYCLE_TRAVERSAL_KEYS
2378      * @throws IllegalArgumentException if id is not one of
2379      *         KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
2380      *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
2381      *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
2382      *         KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
2383      * @since 1.4
2384      */
2385     @SuppressWarnings("unchecked")
2386     public Set<AWTKeyStroke> getFocusTraversalKeys(int id) {
2387         if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH) {
2388             throw new IllegalArgumentException("invalid focus traversal key identifier");
2389         }
2390 
2391         // Okay to return Set directly because it is an unmodifiable view
2392         @SuppressWarnings("rawtypes")
2393         Set keystrokes = (focusTraversalKeys != null)
2394             ? focusTraversalKeys[id]
2395             : null;
2396 
2397         if (keystrokes != null) {
2398             return keystrokes;
2399         } else {
2400             return KeyboardFocusManager.getCurrentKeyboardFocusManager().
2401                 getDefaultFocusTraversalKeys(id);
2402         }
2403     }
2404 
2405     /**
2406      * Does nothing because Windows must always be roots of a focus traversal
2407      * cycle. The passed-in value is ignored.
2408      *
2409      * @param focusCycleRoot this value is ignored
2410      * @see #isFocusCycleRoot
2411      * @see Container#setFocusTraversalPolicy
2412      * @see Container#getFocusTraversalPolicy


2750      * @deprecated As of J2SE 1.4, replaced by
2751      * {@link Component#applyComponentOrientation Component.applyComponentOrientation}.
2752      */
2753     @Deprecated
2754     public void applyResourceBundle(ResourceBundle rb) {
2755         applyComponentOrientation(ComponentOrientation.getOrientation(rb));
2756     }
2757 
2758     /**
2759      * @deprecated As of J2SE 1.4, replaced by
2760      * {@link Component#applyComponentOrientation Component.applyComponentOrientation}.
2761      */
2762     @Deprecated
2763     public void applyResourceBundle(String rbName) {
2764         applyResourceBundle(ResourceBundle.getBundle(rbName));
2765     }
2766 
2767    /*
2768     * Support for tracking all windows owned by this window
2769     */
2770     void addOwnedWindow(WeakReference<Window> weakWindow) {
2771         if (weakWindow != null) {
2772             synchronized(ownedWindowList) {
2773                 // this if statement should really be an assert, but we don't
2774                 // have asserts...
2775                 if (!ownedWindowList.contains(weakWindow)) {
2776                     ownedWindowList.addElement(weakWindow);
2777                 }
2778             }
2779         }
2780     }
2781 
2782     void removeOwnedWindow(WeakReference<Window> weakWindow) {
2783         if (weakWindow != null) {
2784             // synchronized block not required since removeElement is
2785             // already synchronized
2786             ownedWindowList.removeElement(weakWindow);
2787         }
2788     }
2789 
2790     void connectOwnedWindow(Window child) {
2791         child.parent = this;
2792         addOwnedWindow(child.weakThis);
2793     }
2794 
2795     private void addToWindowList() {
2796         synchronized (Window.class) {
2797             @SuppressWarnings("unchecked")
2798             Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>)appContext.get(Window.class);
2799             if (windowList == null) {
2800                 windowList = new Vector<WeakReference<Window>>();
2801                 appContext.put(Window.class, windowList);
2802             }
2803             windowList.add(weakThis);
2804         }
2805     }
2806 
2807     private static void removeFromWindowList(AppContext context, WeakReference<Window> weakThis) {
2808         synchronized (Window.class) {
2809             @SuppressWarnings("unchecked")
2810             Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>)context.get(Window.class);
2811             if (windowList != null) {
2812                 windowList.remove(weakThis);
2813             }
2814         }
2815     }
2816 
2817     private void removeFromWindowList() {
2818         removeFromWindowList(appContext, weakThis);
2819     }
2820 
2821     /**
2822      * Window type.
2823      *
2824      * Synchronization: ObjectLock
2825      */
2826     private Type type = Type.NORMAL;
2827 
2828     /**
2829      * Sets the type of the window.


2932             for (Image i : icons) {
2933                 if (i instanceof Serializable) {
2934                     s.writeObject(i);
2935                 }
2936             }
2937         }
2938         s.writeObject(null);
2939     }
2940 
2941     //
2942     // Part of deserialization procedure to be called before
2943     // user's code.
2944     //
2945     private void initDeserializedWindow() {
2946         setWarningString();
2947         inputContextLock = new Object();
2948 
2949         // Deserialized Windows are not yet visible.
2950         visible = false;
2951 
2952         weakThis = new WeakReference<>(this);
2953 
2954         anchor = new Object();
2955         sun.java2d.Disposer.addRecord(anchor, new WindowDisposerRecord(appContext, this));
2956 
2957         addToWindowList();
2958         initGC(null);
2959     }
2960 
2961     private void deserializeResources(ObjectInputStream s)
2962         throws ClassNotFoundException, IOException, HeadlessException {
2963             ownedWindowList = new Vector<>();
2964 
2965             if (windowSerializedDataVersion < 2) {
2966                 // Translate old-style focus tracking to new model. For 1.4 and
2967                 // later releases, we'll rely on the Window's initial focusable
2968                 // Component.
2969                 if (focusMgr != null) {
2970                     if (focusMgr.focusOwner != null) {
2971                         KeyboardFocusManager.
2972                             setMostRecentFocusOwner(this, focusMgr.focusOwner);
2973                     }
2974                 }
2975 
2976                 // This field is non-transient and relies on default serialization.
2977                 // However, the default value is insufficient, so we need to set
2978                 // it explicitly for object data streams prior to 1.4.
2979                 focusableWindowState = true;
2980 
2981 
2982             }
2983