6837004: java.awt.GraphicsDevice.setFullScreenWindow throws NPE for windows with background color not set
authorart
Wed, 06 May 2009 12:39:23 +0400
changeset 1197ba95c9101e50
parent 1196 2007e3d9c195
child 1198 b28b073e72b6
6837004: java.awt.GraphicsDevice.setFullScreenWindow throws NPE for windows with background color not set
Reviewed-by: yan, dcherepanov
src/share/classes/java/awt/GraphicsDevice.java
test/java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java
     1.1 --- a/src/share/classes/java/awt/GraphicsDevice.java	Tue May 05 14:45:56 2009 +0400
     1.2 +++ b/src/share/classes/java/awt/GraphicsDevice.java	Wed May 06 12:39:23 2009 +0400
     1.3 @@ -282,7 +282,7 @@
     1.4                  w.setOpacity(1.0f);
     1.5              }
     1.6              Color bgColor = w.getBackground();
     1.7 -            if (bgColor.getAlpha() < 255) {
     1.8 +            if ((bgColor != null) && (bgColor.getAlpha() < 255)) {
     1.9                  bgColor = new Color(bgColor.getRed(), bgColor.getGreen(),
    1.10                                      bgColor.getBlue(), 255);
    1.11                  w.setBackground(bgColor);
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java	Wed May 06 12:39:23 2009 +0400
     2.3 @@ -0,0 +1,83 @@
     2.4 +/*
     2.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    2.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    2.24 + * have any questions.
    2.25 + */
    2.26 +
    2.27 +/*
    2.28 + * @test
    2.29 + * @bug 6837004
    2.30 + * @summary Checks that non-opaque window can be made a fullscreen window
    2.31 + * @author Artem Ananiev
    2.32 + * @run main TranslucentWindow
    2.33 + */
    2.34 +
    2.35 +import java.awt.*;
    2.36 +import java.awt.geom.*;
    2.37 +
    2.38 +import static java.awt.GraphicsDevice.WindowTranslucency.*;
    2.39 +
    2.40 +import sun.awt.SunToolkit;
    2.41 +
    2.42 +public class TranslucentWindow {
    2.43 +    public static void main(String args[]) {
    2.44 +        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    2.45 +        GraphicsDevice gd = ge.getDefaultScreenDevice();
    2.46 +
    2.47 +        Frame f = new Frame("Test frame");
    2.48 +        f.setBounds(100, 100, 320, 240);
    2.49 +
    2.50 +        // First, check it can be made fullscreen window without any effects applied
    2.51 +        gd.setFullScreenWindow(f);
    2.52 +        ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
    2.53 +
    2.54 +        gd.setFullScreenWindow(null);
    2.55 +        ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
    2.56 +
    2.57 +        // Second, check if it applying any effects doesn't prevent the window
    2.58 +        // from going into the fullscreen mode
    2.59 +        if (gd.isWindowTranslucencySupported(PERPIXEL_TRANSPARENT)) {
    2.60 +            f.setShape(new Ellipse2D.Float(0, 0, f.getWidth(), f.getHeight()));
    2.61 +        }
    2.62 +        if (gd.isWindowTranslucencySupported(TRANSLUCENT)) {
    2.63 +            f.setOpacity(0.5f);
    2.64 +        }
    2.65 +        if (gd.isWindowTranslucencySupported(PERPIXEL_TRANSLUCENT)) {
    2.66 +            f.setBackground(new Color(0, 0, 0, 128));
    2.67 +        }
    2.68 +        gd.setFullScreenWindow(f);
    2.69 +        ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
    2.70 +
    2.71 +        // Third, make sure all the effects are unset when entering the fullscreen mode
    2.72 +        if (f.getShape() != null) {
    2.73 +            throw new RuntimeException("Test FAILED: fullscreen window shape is not null");
    2.74 +        }
    2.75 +        if (Math.abs(f.getOpacity() - 1.0f) > 1e-4) {
    2.76 +            throw new RuntimeException("Test FAILED: fullscreen window opacity is not 1.0f");
    2.77 +        }
    2.78 +        Color bgColor = f.getBackground();
    2.79 +        if ((bgColor != null) && (bgColor.getAlpha() != 255)) {
    2.80 +            throw new RuntimeException("Test FAILED: fullscreen window background color is not opaque");
    2.81 +        }
    2.82 +
    2.83 +        f.dispose();
    2.84 +        System.out.println("Test PASSED");
    2.85 +    }
    2.86 +}