TranslucentWindow.java revision 11017:beec47aecf5a
1/*
2 * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/*
25 * @test
26 * @bug 6837004
27 * @summary Checks that non-opaque window can be made a fullscreen window
28 * @author Artem Ananiev
29 * @run main TranslucentWindow
30 */
31
32import java.awt.*;
33import java.awt.geom.*;
34
35import static java.awt.GraphicsDevice.WindowTranslucency.*;
36
37
38public class TranslucentWindow {
39    public static void main(String args[]) {
40        Robot robot;
41        try {
42            robot = new Robot();
43        }catch(Exception ex) {
44            ex.printStackTrace();
45            throw new RuntimeException("Unexpected failure");
46        }
47
48        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
49        GraphicsDevice gd = ge.getDefaultScreenDevice();
50
51        Frame f = new Frame("Test frame");
52        f.setUndecorated(true);
53        f.setBounds(100, 100, 320, 240);
54
55        // First, check it can be made fullscreen window without any effects applied
56        gd.setFullScreenWindow(f);
57        robot.waitForIdle();
58
59        gd.setFullScreenWindow(null);
60        robot.waitForIdle();
61
62        // Second, check if it applying any effects doesn't prevent the window
63        // from going into the fullscreen mode
64        if (gd.isWindowTranslucencySupported(PERPIXEL_TRANSPARENT)) {
65            f.setShape(new Ellipse2D.Float(0, 0, f.getWidth(), f.getHeight()));
66        }
67        if (gd.isWindowTranslucencySupported(TRANSLUCENT)) {
68            f.setOpacity(0.5f);
69        }
70        if (gd.isWindowTranslucencySupported(PERPIXEL_TRANSLUCENT)) {
71            f.setBackground(new Color(0, 0, 0, 128));
72        }
73        gd.setFullScreenWindow(f);
74        robot.waitForIdle();
75
76        // Third, make sure all the effects are unset when entering the fullscreen mode
77        if (f.getShape() != null) {
78            throw new RuntimeException("Test FAILED: fullscreen window shape is not null");
79        }
80        if (Math.abs(f.getOpacity() - 1.0f) > 1e-4) {
81            throw new RuntimeException("Test FAILED: fullscreen window opacity is not 1.0f");
82        }
83        Color bgColor = f.getBackground();
84        if ((bgColor != null) && (bgColor.getAlpha() != 255)) {
85            throw new RuntimeException("Test FAILED: fullscreen window background color is not opaque");
86        }
87
88        f.dispose();
89        System.out.println("Test PASSED");
90    }
91}
92