jdk/src/java.desktop/share/classes/java/awt/Window.java
changeset 30469 bac0a7ff7e1e
parent 29886 545c0c3809b8
child 30471 c1568a2416a8
equal deleted inserted replaced
30468:a016d2637922 30469:bac0a7ff7e1e
    27 import java.awt.event.*;
    27 import java.awt.event.*;
    28 import java.awt.geom.Path2D;
    28 import java.awt.geom.Path2D;
    29 import java.awt.geom.Point2D;
    29 import java.awt.geom.Point2D;
    30 import java.awt.im.InputContext;
    30 import java.awt.im.InputContext;
    31 import java.awt.image.BufferStrategy;
    31 import java.awt.image.BufferStrategy;
    32 import java.awt.image.BufferedImage;
       
    33 import java.awt.peer.ComponentPeer;
    32 import java.awt.peer.ComponentPeer;
    34 import java.awt.peer.WindowPeer;
    33 import java.awt.peer.WindowPeer;
    35 import java.beans.PropertyChangeListener;
    34 import java.beans.PropertyChangeListener;
    36 import java.io.IOException;
    35 import java.io.IOException;
    37 import java.io.ObjectInputStream;
    36 import java.io.ObjectInputStream;
    54 import sun.awt.AWTPermissions;
    53 import sun.awt.AWTPermissions;
    55 import sun.awt.AppContext;
    54 import sun.awt.AppContext;
    56 import sun.awt.CausedFocusEvent;
    55 import sun.awt.CausedFocusEvent;
    57 import sun.awt.SunToolkit;
    56 import sun.awt.SunToolkit;
    58 import sun.awt.util.IdentityArrayList;
    57 import sun.awt.util.IdentityArrayList;
    59 import sun.java2d.Disposer;
       
    60 import sun.java2d.pipe.Region;
    58 import sun.java2d.pipe.Region;
    61 import sun.security.action.GetPropertyAction;
    59 import sun.security.action.GetPropertyAction;
    62 import sun.util.logging.PlatformLogger;
    60 import sun.util.logging.PlatformLogger;
    63 
    61 
    64 /**
    62 /**
   753      * not be called directly by programs.
   751      * not be called directly by programs.
   754      * @see Component#isDisplayable
   752      * @see Component#isDisplayable
   755      * @see Container#removeNotify
   753      * @see Container#removeNotify
   756      * @since 1.0
   754      * @since 1.0
   757      */
   755      */
   758     @SuppressWarnings("deprecation")
       
   759     public void addNotify() {
   756     public void addNotify() {
   760         synchronized (getTreeLock()) {
   757         synchronized (getTreeLock()) {
   761             Container parent = this.parent;
   758             Container parent = this.parent;
   762             if (parent != null && parent.getPeer() == null) {
   759             if (parent != null && parent.peer == null) {
   763                 parent.addNotify();
   760                 parent.addNotify();
   764             }
   761             }
   765             if (peer == null) {
   762             if (peer == null) {
   766                 peer = getToolkit().createWindow(this);
   763                 peer = getToolkit().createWindow(this);
   767             }
   764             }
   800      * @see #setMinimumSize
   797      * @see #setMinimumSize
   801      */
   798      */
   802     @SuppressWarnings("deprecation")
   799     @SuppressWarnings("deprecation")
   803     public void pack() {
   800     public void pack() {
   804         Container parent = this.parent;
   801         Container parent = this.parent;
   805         if (parent != null && parent.getPeer() == null) {
   802         if (parent != null && parent.peer == null) {
   806             parent.addNotify();
   803             parent.addNotify();
   807         }
   804         }
   808         if (peer == null) {
   805         if (peer == null) {
   809             addNotify();
   806             addNotify();
   810         }
   807         }
  1070             postWindowEvent(WindowEvent.WINDOW_OPENED);
  1067             postWindowEvent(WindowEvent.WINDOW_OPENED);
  1071             state |= OPENED;
  1068             state |= OPENED;
  1072         }
  1069         }
  1073     }
  1070     }
  1074 
  1071 
  1075     @SuppressWarnings("deprecation")
       
  1076     static void updateChildFocusableWindowState(Window w) {
  1072     static void updateChildFocusableWindowState(Window w) {
  1077         if (w.getPeer() != null && w.isShowing()) {
  1073         if (w.peer != null && w.isShowing()) {
  1078             ((WindowPeer)w.getPeer()).updateFocusableWindowState();
  1074             ((WindowPeer)w.peer).updateFocusableWindowState();
  1079         }
  1075         }
  1080         for (int i = 0; i < w.ownedWindowList.size(); i++) {
  1076         for (int i = 0; i < w.ownedWindowList.size(); i++) {
  1081             Window child = w.ownedWindowList.elementAt(i).get();
  1077             Window child = w.ownedWindowList.elementAt(i).get();
  1082             if (child != null) {
  1078             if (child != null) {
  1083                 updateChildFocusableWindowState(child);
  1079                 updateChildFocusableWindowState(child);
  1158      * Fix for 4872170.
  1154      * Fix for 4872170.
  1159      * If dispose() is called on parent then its children have to be disposed as well
  1155      * If dispose() is called on parent then its children have to be disposed as well
  1160      * as reported in javadoc. So we need to implement this functionality even if a
  1156      * as reported in javadoc. So we need to implement this functionality even if a
  1161      * child overrides dispose() in a wrong way without calling super.dispose().
  1157      * child overrides dispose() in a wrong way without calling super.dispose().
  1162      */
  1158      */
  1163     @SuppressWarnings("deprecation")
       
  1164     void disposeImpl() {
  1159     void disposeImpl() {
  1165         dispose();
  1160         dispose();
  1166         if (getPeer() != null) {
  1161         if (peer != null) {
  1167             doDispose();
  1162             doDispose();
  1168         }
  1163         }
  1169     }
  1164     }
  1170 
  1165 
  1171     void doDispose() {
  1166     void doDispose() {
  3649                     throw new UnsupportedOperationException(
  3644                     throw new UnsupportedOperationException(
  3650                         "TRANSLUCENT translucency is not supported.");
  3645                         "TRANSLUCENT translucency is not supported.");
  3651                 }
  3646                 }
  3652             }
  3647             }
  3653             this.opacity = opacity;
  3648             this.opacity = opacity;
  3654             WindowPeer peer = (WindowPeer)getPeer();
  3649             WindowPeer peer = (WindowPeer) this.peer;
  3655             if (peer != null) {
  3650             if (peer != null) {
  3656                 peer.setOpacity(opacity);
  3651                 peer.setOpacity(opacity);
  3657             }
  3652             }
  3658         }
  3653         }
  3659     }
  3654     }
  3726      * @see GraphicsDevice.WindowTranslucency
  3721      * @see GraphicsDevice.WindowTranslucency
  3727      * @see GraphicsDevice#isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency)
  3722      * @see GraphicsDevice#isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency)
  3728      *
  3723      *
  3729      * @since 1.7
  3724      * @since 1.7
  3730      */
  3725      */
  3731     @SuppressWarnings("deprecation")
       
  3732     public void setShape(Shape shape) {
  3726     public void setShape(Shape shape) {
  3733         synchronized (getTreeLock()) {
  3727         synchronized (getTreeLock()) {
  3734             if (shape != null) {
  3728             if (shape != null) {
  3735                 GraphicsConfiguration gc = getGraphicsConfiguration();
  3729                 GraphicsConfiguration gc = getGraphicsConfiguration();
  3736                 GraphicsDevice gd = gc.getDevice();
  3730                 GraphicsDevice gd = gc.getDevice();
  3744                     throw new UnsupportedOperationException(
  3738                     throw new UnsupportedOperationException(
  3745                         "PERPIXEL_TRANSPARENT translucency is not supported.");
  3739                         "PERPIXEL_TRANSPARENT translucency is not supported.");
  3746                 }
  3740                 }
  3747             }
  3741             }
  3748             this.shape = (shape == null) ? null : new Path2D.Float(shape);
  3742             this.shape = (shape == null) ? null : new Path2D.Float(shape);
  3749             WindowPeer peer = (WindowPeer)getPeer();
  3743             WindowPeer peer = (WindowPeer) this.peer;
  3750             if (peer != null) {
  3744             if (peer != null) {
  3751                 peer.applyShape(shape == null ? null : Region.getInstance(shape, null));
  3745                 peer.applyShape(shape == null ? null : Region.getInstance(shape, null));
  3752             }
  3746             }
  3753         }
  3747         }
  3754     }
  3748     }
  3844      * @see GraphicsDevice.WindowTranslucency
  3838      * @see GraphicsDevice.WindowTranslucency
  3845      * @see GraphicsDevice#isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency)
  3839      * @see GraphicsDevice#isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency)
  3846      * @see GraphicsConfiguration#isTranslucencyCapable()
  3840      * @see GraphicsConfiguration#isTranslucencyCapable()
  3847      */
  3841      */
  3848     @Override
  3842     @Override
  3849     @SuppressWarnings("deprecation")
       
  3850     public void setBackground(Color bgColor) {
  3843     public void setBackground(Color bgColor) {
  3851         Color oldBg = getBackground();
  3844         Color oldBg = getBackground();
  3852         super.setBackground(bgColor);
  3845         super.setBackground(bgColor);
  3853         if (oldBg != null && oldBg.equals(bgColor)) {
  3846         if (oldBg != null && oldBg.equals(bgColor)) {
  3854             return;
  3847             return;
  3872             }
  3865             }
  3873             setLayersOpaque(this, false);
  3866             setLayersOpaque(this, false);
  3874         } else if ((oldAlpha < 255) && (alpha == 255)) {
  3867         } else if ((oldAlpha < 255) && (alpha == 255)) {
  3875             setLayersOpaque(this, true);
  3868             setLayersOpaque(this, true);
  3876         }
  3869         }
  3877         WindowPeer peer = (WindowPeer)getPeer();
  3870         WindowPeer peer = (WindowPeer) this.peer;
  3878         if (peer != null) {
  3871         if (peer != null) {
  3879             peer.setOpaque(alpha == 255);
  3872             peer.setOpaque(alpha == 255);
  3880         }
  3873         }
  3881     }
  3874     }
  3882 
  3875 
  3897     public boolean isOpaque() {
  3890     public boolean isOpaque() {
  3898         Color bg = getBackground();
  3891         Color bg = getBackground();
  3899         return bg != null ? bg.getAlpha() == 255 : true;
  3892         return bg != null ? bg.getAlpha() == 255 : true;
  3900     }
  3893     }
  3901 
  3894 
  3902     @SuppressWarnings("deprecation")
       
  3903     private void updateWindow() {
  3895     private void updateWindow() {
  3904         synchronized (getTreeLock()) {
  3896         synchronized (getTreeLock()) {
  3905             WindowPeer peer = (WindowPeer)getPeer();
  3897             WindowPeer peer = (WindowPeer) this.peer;
  3906             if (peer != null) {
  3898             if (peer != null) {
  3907                 peer.updateWindow();
  3899                 peer.updateWindow();
  3908             }
  3900             }
  3909         }
  3901         }
  3910     }
  3902     }
  4088             {
  4080             {
  4089                 window.securityWarningWidth = width;
  4081                 window.securityWarningWidth = width;
  4090                 window.securityWarningHeight = height;
  4082                 window.securityWarningHeight = height;
  4091             }
  4083             }
  4092 
  4084 
  4093             @SuppressWarnings("deprecation")
       
  4094             public void setSecurityWarningPosition(Window window,
  4085             public void setSecurityWarningPosition(Window window,
  4095                     Point2D point, float alignmentX, float alignmentY)
  4086                     Point2D point, float alignmentX, float alignmentY)
  4096             {
  4087             {
  4097                 window.securityWarningPointX = point.getX();
  4088                 window.securityWarningPointX = point.getX();
  4098                 window.securityWarningPointY = point.getY();
  4089                 window.securityWarningPointY = point.getY();
  4099                 window.securityWarningAlignmentX = alignmentX;
  4090                 window.securityWarningAlignmentX = alignmentX;
  4100                 window.securityWarningAlignmentY = alignmentY;
  4091                 window.securityWarningAlignmentY = alignmentY;
  4101 
  4092 
  4102                 synchronized (window.getTreeLock()) {
  4093                 synchronized (window.getTreeLock()) {
  4103                     WindowPeer peer = (WindowPeer)window.getPeer();
  4094                     WindowPeer peer = (WindowPeer) window.peer;
  4104                     if (peer != null) {
  4095                     if (peer != null) {
  4105                         peer.repositionSecurityWarning();
  4096                         peer.repositionSecurityWarning();
  4106                     }
  4097                     }
  4107                 }
  4098                 }
  4108             }
  4099             }