jdk/src/share/classes/java/awt/Window.java
changeset 3237 7c6c2d9361d9
parent 3231 10acb97474ff
child 3476 b27b095ea77b
equal deleted inserted replaced
3236:e1c4ad748c0f 3237:7c6c2d9361d9
  3519      * the window is in the non-opaque (per-pixel translucent) mode.
  3519      * the window is in the non-opaque (per-pixel translucent) mode.
  3520      *
  3520      *
  3521      * @return this component's background color
  3521      * @return this component's background color
  3522      *
  3522      *
  3523      * @see Window#setBackground
  3523      * @see Window#setBackground
       
  3524      * @see Window#isOpaque
  3524      * @see GraphicsDevice.WindowTranslucency
  3525      * @see GraphicsDevice.WindowTranslucency
  3525      */
  3526      */
  3526     @Override
  3527     @Override
  3527     public Color getBackground() {
  3528     public Color getBackground() {
  3528         return super.getBackground();
  3529         return super.getBackground();
  3581      *     background color is less than 1.0f and
  3582      *     background color is less than 1.0f and
  3582      *     {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT
  3583      *     {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT
  3583      *     PERPIXEL_TRANSLUCENT} translucency is not supported
  3584      *     PERPIXEL_TRANSLUCENT} translucency is not supported
  3584      *
  3585      *
  3585      * @see Window#getBackground
  3586      * @see Window#getBackground
       
  3587      * @see Window#isOpaque
  3586      * @see Window#setOpacity()
  3588      * @see Window#setOpacity()
  3587      * @see Window#setShape()
  3589      * @see Window#setShape()
  3588      * @see GraphicsDevice.WindowTranslucency
  3590      * @see GraphicsDevice.WindowTranslucency
  3589      * @see GraphicsDevice#isWindowTranslucencySupported()
  3591      * @see GraphicsDevice#isWindowTranslucencySupported()
  3590      * @see GraphicsConfiguration#isTranslucencyCapable()
  3592      * @see GraphicsConfiguration#isTranslucencyCapable()
  3621         if (peer != null) {
  3623         if (peer != null) {
  3622             peer.setOpaque(alpha == 255);
  3624             peer.setOpaque(alpha == 255);
  3623         }
  3625         }
  3624     }
  3626     }
  3625 
  3627 
       
  3628     /**
       
  3629      * Indicates if the window is currently opaque.
       
  3630      * <p>
       
  3631      * The method returns {@code false} if the background color of the window
       
  3632      * is not {@code null} and the alpha component of the color is less than
       
  3633      * 1.0f. The method returns {@code true} otherwise.
       
  3634      *
       
  3635      * @return {@code true} if the window is opaque, {@code false} otherwise
       
  3636      *
       
  3637      * @see Window#getBackground
       
  3638      * @see Window#setBackground
       
  3639      * @since 1.7
       
  3640      */
       
  3641     @Override
       
  3642     public boolean isOpaque() {
       
  3643         Color bg = getBackground();
       
  3644         return bg != null ? bg.getAlpha() == 255 : true;
       
  3645     }
       
  3646 
  3626     private void updateWindow() {
  3647     private void updateWindow() {
  3627         synchronized (getTreeLock()) {
  3648         synchronized (getTreeLock()) {
  3628             WindowPeer peer = (WindowPeer)getPeer();
  3649             WindowPeer peer = (WindowPeer)getPeer();
  3629             if (peer != null) {
  3650             if (peer != null) {
  3630                 peer.updateWindow();
  3651                 peer.updateWindow();
  3637      *
  3658      *
  3638      * @since 1.7
  3659      * @since 1.7
  3639      */
  3660      */
  3640     @Override
  3661     @Override
  3641     public void paint(Graphics g) {
  3662     public void paint(Graphics g) {
  3642         Color bgColor = getBackground();
  3663         if (!isOpaque()) {
  3643         if ((bgColor != null) && (bgColor.getAlpha() < 255)) {
       
  3644             Graphics gg = g.create();
  3664             Graphics gg = g.create();
  3645             try {
  3665             try {
  3646                 if (gg instanceof Graphics2D) {
  3666                 if (gg instanceof Graphics2D) {
  3647                     gg.setColor(bgColor);
  3667                     gg.setColor(getBackground());
  3648                     ((Graphics2D)gg).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC));
  3668                     ((Graphics2D)gg).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC));
  3649                     gg.fillRect(0, 0, getWidth(), getHeight());
  3669                     gg.fillRect(0, 0, getWidth(), getHeight());
  3650                 }
  3670                 }
  3651             } finally {
  3671             } finally {
  3652                 gg.dispose();
  3672                 gg.dispose();
  3747                 return window.getShape();
  3767                 return window.getShape();
  3748             }
  3768             }
  3749             public void setShape(Window window, Shape shape) {
  3769             public void setShape(Window window, Shape shape) {
  3750                 window.setShape(shape);
  3770                 window.setShape(shape);
  3751             }
  3771             }
  3752             public boolean isOpaque(Window window) {
       
  3753                 Color bg = window.getBackground();
       
  3754                 return (bg != null) ? bg.getAlpha() == 255 : true;
       
  3755             }
       
  3756             public void setOpaque(Window window, boolean opaque) {
  3772             public void setOpaque(Window window, boolean opaque) {
  3757                 Color bg = window.getBackground();
  3773                 Color bg = window.getBackground();
  3758                 if (bg == null) {
  3774                 if (bg == null) {
  3759                     bg = new Color(0, 0, 0, 0);
  3775                     bg = new Color(0, 0, 0, 0);
  3760                 }
  3776                 }