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();


 741     public void setIconImage(Image image) {
 742         ArrayList<Image> imageList = new ArrayList<Image>();
 743         if (image != null) {
 744             imageList.add(image);
 745         }
 746         setIconImages(imageList);
 747     }
 748 
 749     /**
 750      * Makes this Window displayable by creating the connection to its
 751      * native screen resource.
 752      * This method is called internally by the toolkit and should
 753      * not be called directly by programs.
 754      * @see Component#isDisplayable
 755      * @see Container#removeNotify
 756      * @since JDK1.0
 757      */
 758     public void addNotify() {
 759         synchronized (getTreeLock()) {
 760             Container parent = this.parent;
 761             if (parent != null && parent.getPeer() == null) {
 762                 parent.addNotify();
 763             }
 764             if (peer == null) {
 765                 peer = getToolkit().createWindow(this);
 766             }
 767             synchronized (allWindows) {
 768                 allWindows.add(this);
 769             }
 770             super.addNotify();
 771         }
 772     }
 773 
 774     /**
 775      * {@inheritDoc}
 776      */
 777     public void removeNotify() {
 778         synchronized (getTreeLock()) {
 779             synchronized (allWindows) {
 780                 allWindows.remove(this);
 781             }


 783         }
 784     }
 785 
 786     /**
 787      * Causes this Window to be sized to fit the preferred size
 788      * and layouts of its subcomponents. The resulting width and
 789      * height of the window are automatically enlarged if either
 790      * of dimensions is less than the minimum size as specified
 791      * by the previous call to the {@code setMinimumSize} method.
 792      * <p>
 793      * If the window and/or its owner are not displayable yet,
 794      * both of them are made displayable before calculating
 795      * the preferred size. The Window is validated after its
 796      * size is being calculated.
 797      *
 798      * @see Component#isDisplayable
 799      * @see #setMinimumSize
 800      */
 801     public void pack() {
 802         Container parent = this.parent;
 803         if (parent != null && parent.getPeer() == null) {
 804             parent.addNotify();
 805         }
 806         if (peer == null) {
 807             addNotify();
 808         }
 809         Dimension newSize = getPreferredSize();
 810         if (peer != null) {
 811             setClientSize(newSize.width, newSize.height);
 812         }
 813 
 814         if(beforeFirstShow) {
 815             isPacked = true;
 816         }
 817 
 818         validateUnconditionally();
 819     }
 820 
 821     /**
 822      * Sets the minimum size of this window to a constant
 823      * value.  Subsequent calls to {@code getMinimumSize}


1052                 updateChildrenBlocking();
1053             } else {
1054                 // fix for 6532736: after this window is shown, its blocker
1055                 // should be raised to front
1056                 modalBlocker.toFront_NoClientCode();
1057             }
1058             if (this instanceof Frame || this instanceof Dialog) {
1059                 updateChildFocusableWindowState(this);
1060             }
1061         }
1062         isInShow = false;
1063 
1064         // If first time shown, generate WindowOpened event
1065         if ((state & OPENED) == 0) {
1066             postWindowEvent(WindowEvent.WINDOW_OPENED);
1067             state |= OPENED;
1068         }
1069     }
1070 
1071     static void updateChildFocusableWindowState(Window w) {
1072         if (w.getPeer() != null && w.isShowing()) {
1073             ((WindowPeer)w.getPeer()).updateFocusableWindowState();
1074         }
1075         for (int i = 0; i < w.ownedWindowList.size(); i++) {
1076             Window child = w.ownedWindowList.elementAt(i).get();
1077             if (child != null) {
1078                 updateChildFocusableWindowState(child);
1079             }
1080         }
1081     }
1082 
1083     synchronized void postWindowEvent(int id) {
1084         if (windowListener != null
1085             || (eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0
1086             ||  Toolkit.enabledOnToolkit(AWTEvent.WINDOW_EVENT_MASK)) {
1087             WindowEvent e = new WindowEvent(this, id);
1088             Toolkit.getEventQueue().postEvent(e);
1089         }
1090     }
1091 
1092     /**
1093      * Hide this Window, its subcomponents, and all of its owned children.


1138      * <b>Note</b>: When the last displayable window
1139      * within the Java virtual machine (VM) is disposed of, the VM may
1140      * terminate.  See <a href="doc-files/AWTThreadIssues.html#Autoshutdown">
1141      * AWT Threading Issues</a> for more information.
1142      * @see Component#isDisplayable
1143      * @see #pack
1144      * @see #show
1145      */
1146     public void dispose() {
1147         doDispose();
1148     }
1149 
1150     /*
1151      * Fix for 4872170.
1152      * If dispose() is called on parent then its children have to be disposed as well
1153      * as reported in javadoc. So we need to implement this functionality even if a
1154      * child overrides dispose() in a wrong way without calling super.dispose().
1155      */
1156     void disposeImpl() {
1157         dispose();
1158         if (getPeer() != null) {
1159             doDispose();
1160         }
1161     }
1162 
1163     void doDispose() {
1164     class DisposeAction implements Runnable {
1165         public void run() {
1166             disposing = true;
1167             try {
1168                 // Check if this window is the fullscreen window for the
1169                 // device. Exit the fullscreen mode prior to disposing
1170                 // of the window if that's the case.
1171                 GraphicsDevice gd = getGraphicsConfiguration().getDevice();
1172                 if (gd.getFullScreenWindow() == Window.this) {
1173                     gd.setFullScreenWindow(null);
1174                 }
1175 
1176                 Object[] ownedWindowArray;
1177                 synchronized(ownedWindowList) {
1178                     ownedWindowArray = new Object[ownedWindowList.size()];


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 


3583         synchronized (getTreeLock()) {
3584             if (opacity < 0.0f || opacity > 1.0f) {
3585                 throw new IllegalArgumentException(
3586                     "The value of opacity should be in the range [0.0f .. 1.0f].");
3587             }
3588             if (opacity < 1.0f) {
3589                 GraphicsConfiguration gc = getGraphicsConfiguration();
3590                 GraphicsDevice gd = gc.getDevice();
3591                 if (gc.getDevice().getFullScreenWindow() == this) {
3592                     throw new IllegalComponentStateException(
3593                         "Setting opacity for full-screen window is not supported.");
3594                 }
3595                 if (!gd.isWindowTranslucencySupported(
3596                     GraphicsDevice.WindowTranslucency.TRANSLUCENT))
3597                 {
3598                     throw new UnsupportedOperationException(
3599                         "TRANSLUCENT translucency is not supported.");
3600                 }
3601             }
3602             this.opacity = opacity;
3603             WindowPeer peer = (WindowPeer)getPeer();
3604             if (peer != null) {
3605                 peer.setOpacity(opacity);
3606             }
3607         }
3608     }
3609 
3610     /**
3611      * Returns the shape of the window.
3612      *
3613      * The value returned by this method may not be the same as
3614      * previously set with {@code setShape(shape)}, but it is guaranteed
3615      * to represent the same shape.
3616      *
3617      * @return the shape of the window or {@code null} if no
3618      *     shape is specified for the window
3619      *
3620      * @see Window#setShape(Shape)
3621      * @see GraphicsDevice.WindowTranslucency
3622      *
3623      * @since 1.7
3624      */
3625     public Shape getShape() {


3677      *
3678      * @since 1.7
3679      */
3680     public void setShape(Shape shape) {
3681         synchronized (getTreeLock()) {
3682             if (shape != null) {
3683                 GraphicsConfiguration gc = getGraphicsConfiguration();
3684                 GraphicsDevice gd = gc.getDevice();
3685                 if (gc.getDevice().getFullScreenWindow() == this) {
3686                     throw new IllegalComponentStateException(
3687                         "Setting shape for full-screen window is not supported.");
3688                 }
3689                 if (!gd.isWindowTranslucencySupported(
3690                         GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT))
3691                 {
3692                     throw new UnsupportedOperationException(
3693                         "PERPIXEL_TRANSPARENT translucency is not supported.");
3694                 }
3695             }
3696             this.shape = (shape == null) ? null : new Path2D.Float(shape);
3697             WindowPeer peer = (WindowPeer)getPeer();
3698             if (peer != null) {
3699                 peer.applyShape(shape == null ? null : Region.getInstance(shape, null));
3700             }
3701         }
3702     }
3703 
3704     /**
3705      * Gets the background color of this window.
3706      * <p>
3707      * Note that the alpha component of the returned color indicates whether
3708      * the window is in the non-opaque (per-pixel translucent) mode.
3709      *
3710      * @return this component's background color
3711      *
3712      * @see Window#setBackground(Color)
3713      * @see Window#isOpaque
3714      * @see GraphicsDevice.WindowTranslucency
3715      */
3716     @Override
3717     public Color getBackground() {
3718         return super.getBackground();
3719     }


3804         int alpha = bgColor != null ? bgColor.getAlpha() : 255;
3805         if ((oldAlpha == 255) && (alpha < 255)) { // non-opaque window
3806             GraphicsConfiguration gc = getGraphicsConfiguration();
3807             GraphicsDevice gd = gc.getDevice();
3808             if (gc.getDevice().getFullScreenWindow() == this) {
3809                 throw new IllegalComponentStateException(
3810                     "Making full-screen window non opaque is not supported.");
3811             }
3812             if (!gc.isTranslucencyCapable()) {
3813                 GraphicsConfiguration capableGC = gd.getTranslucencyCapableGC();
3814                 if (capableGC == null) {
3815                     throw new UnsupportedOperationException(
3816                         "PERPIXEL_TRANSLUCENT translucency is not supported");
3817                 }
3818                 setGraphicsConfiguration(capableGC);
3819             }
3820             setLayersOpaque(this, false);
3821         } else if ((oldAlpha < 255) && (alpha == 255)) {
3822             setLayersOpaque(this, true);
3823         }
3824         WindowPeer peer = (WindowPeer)getPeer();
3825         if (peer != null) {
3826             peer.setOpaque(alpha == 255);
3827         }
3828     }
3829 
3830     /**
3831      * Indicates if the window is currently opaque.
3832      * <p>
3833      * The method returns {@code false} if the background color of the window
3834      * is not {@code null} and the alpha component of the color is less than
3835      * {@code 1.0f}. The method returns {@code true} otherwise.
3836      *
3837      * @return {@code true} if the window is opaque, {@code false} otherwise
3838      *
3839      * @see Window#getBackground
3840      * @see Window#setBackground(Color)
3841      * @since 1.7
3842      */
3843     @Override
3844     public boolean isOpaque() {
3845         Color bg = getBackground();
3846         return bg != null ? bg.getAlpha() == 255 : true;
3847     }
3848 
3849     private void updateWindow() {
3850         synchronized (getTreeLock()) {
3851             WindowPeer peer = (WindowPeer)getPeer();
3852             if (peer != null) {
3853                 peer.updateWindow();
3854             }
3855         }
3856     }
3857 
3858     /**
3859      * {@inheritDoc}
3860      *
3861      * @since 1.7
3862      */
3863     @Override
3864     public void paint(Graphics g) {
3865         if (!isOpaque()) {
3866             Graphics gg = g.create();
3867             try {
3868                 if (gg instanceof Graphics2D) {
3869                     gg.setColor(getBackground());
3870                     ((Graphics2D)gg).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC));
3871                     gg.fillRect(0, 0, getWidth(), getHeight());
3872                 }
3873             } finally {


4028             public Dimension getSecurityWarningSize(Window window) {
4029                 return new Dimension(window.securityWarningWidth,
4030                         window.securityWarningHeight);
4031             }
4032 
4033             public void setSecurityWarningSize(Window window, int width, int height)
4034             {
4035                 window.securityWarningWidth = width;
4036                 window.securityWarningHeight = height;
4037             }
4038 
4039             public void setSecurityWarningPosition(Window window,
4040                     Point2D point, float alignmentX, float alignmentY)
4041             {
4042                 window.securityWarningPointX = point.getX();
4043                 window.securityWarningPointY = point.getY();
4044                 window.securityWarningAlignmentX = alignmentX;
4045                 window.securityWarningAlignmentY = alignmentY;
4046 
4047                 synchronized (window.getTreeLock()) {
4048                     WindowPeer peer = (WindowPeer)window.getPeer();
4049                     if (peer != null) {
4050                         peer.repositionSecurityWarning();
4051                     }
4052                 }
4053             }
4054 
4055             public Point2D calculateSecurityWarningPosition(Window window,
4056                     double x, double y, double w, double h)
4057             {
4058                 return window.calculateSecurityWarningPosition(x, y, w, h);
4059             }
4060 
4061             public void setLWRequestStatus(Window changed, boolean status) {
4062                 changed.syncLWRequests = status;
4063             }
4064 
4065             public boolean isAutoRequestFocus(Window w) {
4066                 return w.autoRequestFocus;
4067             }
4068 
4069             public boolean isTrayIconWindow(Window w) {
4070                 return w.isTrayIconWindow;




 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();


 741     public void setIconImage(Image image) {
 742         ArrayList<Image> imageList = new ArrayList<Image>();
 743         if (image != null) {
 744             imageList.add(image);
 745         }
 746         setIconImages(imageList);
 747     }
 748 
 749     /**
 750      * Makes this Window displayable by creating the connection to its
 751      * native screen resource.
 752      * This method is called internally by the toolkit and should
 753      * not be called directly by programs.
 754      * @see Component#isDisplayable
 755      * @see Container#removeNotify
 756      * @since JDK1.0
 757      */
 758     public void addNotify() {
 759         synchronized (getTreeLock()) {
 760             Container parent = this.parent;
 761             if (parent != null && parent.peer == null) {
 762                 parent.addNotify();
 763             }
 764             if (peer == null) {
 765                 peer = getToolkit().createWindow(this);
 766             }
 767             synchronized (allWindows) {
 768                 allWindows.add(this);
 769             }
 770             super.addNotify();
 771         }
 772     }
 773 
 774     /**
 775      * {@inheritDoc}
 776      */
 777     public void removeNotify() {
 778         synchronized (getTreeLock()) {
 779             synchronized (allWindows) {
 780                 allWindows.remove(this);
 781             }


 783         }
 784     }
 785 
 786     /**
 787      * Causes this Window to be sized to fit the preferred size
 788      * and layouts of its subcomponents. The resulting width and
 789      * height of the window are automatically enlarged if either
 790      * of dimensions is less than the minimum size as specified
 791      * by the previous call to the {@code setMinimumSize} method.
 792      * <p>
 793      * If the window and/or its owner are not displayable yet,
 794      * both of them are made displayable before calculating
 795      * the preferred size. The Window is validated after its
 796      * size is being calculated.
 797      *
 798      * @see Component#isDisplayable
 799      * @see #setMinimumSize
 800      */
 801     public void pack() {
 802         Container parent = this.parent;
 803         if (parent != null && parent.peer == null) {
 804             parent.addNotify();
 805         }
 806         if (peer == null) {
 807             addNotify();
 808         }
 809         Dimension newSize = getPreferredSize();
 810         if (peer != null) {
 811             setClientSize(newSize.width, newSize.height);
 812         }
 813 
 814         if(beforeFirstShow) {
 815             isPacked = true;
 816         }
 817 
 818         validateUnconditionally();
 819     }
 820 
 821     /**
 822      * Sets the minimum size of this window to a constant
 823      * value.  Subsequent calls to {@code getMinimumSize}


1052                 updateChildrenBlocking();
1053             } else {
1054                 // fix for 6532736: after this window is shown, its blocker
1055                 // should be raised to front
1056                 modalBlocker.toFront_NoClientCode();
1057             }
1058             if (this instanceof Frame || this instanceof Dialog) {
1059                 updateChildFocusableWindowState(this);
1060             }
1061         }
1062         isInShow = false;
1063 
1064         // If first time shown, generate WindowOpened event
1065         if ((state & OPENED) == 0) {
1066             postWindowEvent(WindowEvent.WINDOW_OPENED);
1067             state |= OPENED;
1068         }
1069     }
1070 
1071     static void updateChildFocusableWindowState(Window w) {
1072         if (w.peer != null && w.isShowing()) {
1073             ((WindowPeer)w.peer).updateFocusableWindowState();
1074         }
1075         for (int i = 0; i < w.ownedWindowList.size(); i++) {
1076             Window child = w.ownedWindowList.elementAt(i).get();
1077             if (child != null) {
1078                 updateChildFocusableWindowState(child);
1079             }
1080         }
1081     }
1082 
1083     synchronized void postWindowEvent(int id) {
1084         if (windowListener != null
1085             || (eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0
1086             ||  Toolkit.enabledOnToolkit(AWTEvent.WINDOW_EVENT_MASK)) {
1087             WindowEvent e = new WindowEvent(this, id);
1088             Toolkit.getEventQueue().postEvent(e);
1089         }
1090     }
1091 
1092     /**
1093      * Hide this Window, its subcomponents, and all of its owned children.


1138      * <b>Note</b>: When the last displayable window
1139      * within the Java virtual machine (VM) is disposed of, the VM may
1140      * terminate.  See <a href="doc-files/AWTThreadIssues.html#Autoshutdown">
1141      * AWT Threading Issues</a> for more information.
1142      * @see Component#isDisplayable
1143      * @see #pack
1144      * @see #show
1145      */
1146     public void dispose() {
1147         doDispose();
1148     }
1149 
1150     /*
1151      * Fix for 4872170.
1152      * If dispose() is called on parent then its children have to be disposed as well
1153      * as reported in javadoc. So we need to implement this functionality even if a
1154      * child overrides dispose() in a wrong way without calling super.dispose().
1155      */
1156     void disposeImpl() {
1157         dispose();
1158         if (peer != null) {
1159             doDispose();
1160         }
1161     }
1162 
1163     void doDispose() {
1164     class DisposeAction implements Runnable {
1165         public void run() {
1166             disposing = true;
1167             try {
1168                 // Check if this window is the fullscreen window for the
1169                 // device. Exit the fullscreen mode prior to disposing
1170                 // of the window if that's the case.
1171                 GraphicsDevice gd = getGraphicsConfiguration().getDevice();
1172                 if (gd.getFullScreenWindow() == Window.this) {
1173                     gd.setFullScreenWindow(null);
1174                 }
1175 
1176                 Object[] ownedWindowArray;
1177                 synchronized(ownedWindowList) {
1178                     ownedWindowArray = new Object[ownedWindowList.size()];


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 


3587         synchronized (getTreeLock()) {
3588             if (opacity < 0.0f || opacity > 1.0f) {
3589                 throw new IllegalArgumentException(
3590                     "The value of opacity should be in the range [0.0f .. 1.0f].");
3591             }
3592             if (opacity < 1.0f) {
3593                 GraphicsConfiguration gc = getGraphicsConfiguration();
3594                 GraphicsDevice gd = gc.getDevice();
3595                 if (gc.getDevice().getFullScreenWindow() == this) {
3596                     throw new IllegalComponentStateException(
3597                         "Setting opacity for full-screen window is not supported.");
3598                 }
3599                 if (!gd.isWindowTranslucencySupported(
3600                     GraphicsDevice.WindowTranslucency.TRANSLUCENT))
3601                 {
3602                     throw new UnsupportedOperationException(
3603                         "TRANSLUCENT translucency is not supported.");
3604                 }
3605             }
3606             this.opacity = opacity;
3607             WindowPeer windowPeer = (WindowPeer)peer;
3608             if (windowPeer != null) {
3609                 windowPeer.setOpacity(opacity);
3610             }
3611         }
3612     }
3613 
3614     /**
3615      * Returns the shape of the window.
3616      *
3617      * The value returned by this method may not be the same as
3618      * previously set with {@code setShape(shape)}, but it is guaranteed
3619      * to represent the same shape.
3620      *
3621      * @return the shape of the window or {@code null} if no
3622      *     shape is specified for the window
3623      *
3624      * @see Window#setShape(Shape)
3625      * @see GraphicsDevice.WindowTranslucency
3626      *
3627      * @since 1.7
3628      */
3629     public Shape getShape() {


3681      *
3682      * @since 1.7
3683      */
3684     public void setShape(Shape shape) {
3685         synchronized (getTreeLock()) {
3686             if (shape != null) {
3687                 GraphicsConfiguration gc = getGraphicsConfiguration();
3688                 GraphicsDevice gd = gc.getDevice();
3689                 if (gc.getDevice().getFullScreenWindow() == this) {
3690                     throw new IllegalComponentStateException(
3691                         "Setting shape for full-screen window is not supported.");
3692                 }
3693                 if (!gd.isWindowTranslucencySupported(
3694                         GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT))
3695                 {
3696                     throw new UnsupportedOperationException(
3697                         "PERPIXEL_TRANSPARENT translucency is not supported.");
3698                 }
3699             }
3700             this.shape = (shape == null) ? null : new Path2D.Float(shape);
3701             WindowPeer windowPeer = (WindowPeer)peer;
3702             if (windowPeer != null) {
3703                 windowPeer.applyShape(shape == null ? null : Region.getInstance(shape, null));
3704             }
3705         }
3706     }
3707 
3708     /**
3709      * Gets the background color of this window.
3710      * <p>
3711      * Note that the alpha component of the returned color indicates whether
3712      * the window is in the non-opaque (per-pixel translucent) mode.
3713      *
3714      * @return this component's background color
3715      *
3716      * @see Window#setBackground(Color)
3717      * @see Window#isOpaque
3718      * @see GraphicsDevice.WindowTranslucency
3719      */
3720     @Override
3721     public Color getBackground() {
3722         return super.getBackground();
3723     }


3808         int alpha = bgColor != null ? bgColor.getAlpha() : 255;
3809         if ((oldAlpha == 255) && (alpha < 255)) { // non-opaque window
3810             GraphicsConfiguration gc = getGraphicsConfiguration();
3811             GraphicsDevice gd = gc.getDevice();
3812             if (gc.getDevice().getFullScreenWindow() == this) {
3813                 throw new IllegalComponentStateException(
3814                     "Making full-screen window non opaque is not supported.");
3815             }
3816             if (!gc.isTranslucencyCapable()) {
3817                 GraphicsConfiguration capableGC = gd.getTranslucencyCapableGC();
3818                 if (capableGC == null) {
3819                     throw new UnsupportedOperationException(
3820                         "PERPIXEL_TRANSLUCENT translucency is not supported");
3821                 }
3822                 setGraphicsConfiguration(capableGC);
3823             }
3824             setLayersOpaque(this, false);
3825         } else if ((oldAlpha < 255) && (alpha == 255)) {
3826             setLayersOpaque(this, true);
3827         }
3828         WindowPeer windowPeer = (WindowPeer)peer;
3829         if (windowPeer != null) {
3830             windowPeer.setOpaque(alpha == 255);
3831         }
3832     }
3833 
3834     /**
3835      * Indicates if the window is currently opaque.
3836      * <p>
3837      * The method returns {@code false} if the background color of the window
3838      * is not {@code null} and the alpha component of the color is less than
3839      * {@code 1.0f}. The method returns {@code true} otherwise.
3840      *
3841      * @return {@code true} if the window is opaque, {@code false} otherwise
3842      *
3843      * @see Window#getBackground
3844      * @see Window#setBackground(Color)
3845      * @since 1.7
3846      */
3847     @Override
3848     public boolean isOpaque() {
3849         Color bg = getBackground();
3850         return bg != null ? bg.getAlpha() == 255 : true;
3851     }
3852 
3853     private void updateWindow() {
3854         synchronized (getTreeLock()) {
3855             WindowPeer windowPeer = (WindowPeer)peer;
3856             if (windowPeer != null) {
3857                 windowPeer.updateWindow();
3858             }
3859         }
3860     }
3861 
3862     /**
3863      * {@inheritDoc}
3864      *
3865      * @since 1.7
3866      */
3867     @Override
3868     public void paint(Graphics g) {
3869         if (!isOpaque()) {
3870             Graphics gg = g.create();
3871             try {
3872                 if (gg instanceof Graphics2D) {
3873                     gg.setColor(getBackground());
3874                     ((Graphics2D)gg).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC));
3875                     gg.fillRect(0, 0, getWidth(), getHeight());
3876                 }
3877             } finally {


4032             public Dimension getSecurityWarningSize(Window window) {
4033                 return new Dimension(window.securityWarningWidth,
4034                         window.securityWarningHeight);
4035             }
4036 
4037             public void setSecurityWarningSize(Window window, int width, int height)
4038             {
4039                 window.securityWarningWidth = width;
4040                 window.securityWarningHeight = height;
4041             }
4042 
4043             public void setSecurityWarningPosition(Window window,
4044                     Point2D point, float alignmentX, float alignmentY)
4045             {
4046                 window.securityWarningPointX = point.getX();
4047                 window.securityWarningPointY = point.getY();
4048                 window.securityWarningAlignmentX = alignmentX;
4049                 window.securityWarningAlignmentY = alignmentY;
4050 
4051                 synchronized (window.getTreeLock()) {
4052                     WindowPeer windowPeer = (WindowPeer)window.peer;
4053                     if (windowPeer != null) {
4054                         windowPeer.repositionSecurityWarning();
4055                     }
4056                 }
4057             }
4058 
4059             public Point2D calculateSecurityWarningPosition(Window window,
4060                     double x, double y, double w, double h)
4061             {
4062                 return window.calculateSecurityWarningPosition(x, y, w, h);
4063             }
4064 
4065             public void setLWRequestStatus(Window changed, boolean status) {
4066                 changed.syncLWRequests = status;
4067             }
4068 
4069             public boolean isAutoRequestFocus(Window w) {
4070                 return w.autoRequestFocus;
4071             }
4072 
4073             public boolean isTrayIconWindow(Window w) {
4074                 return w.isTrayIconWindow;