Path: blob/master/test/jdk/java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java
41154 views
/*1* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @key headful26* @bug 683700427* @summary Checks that non-opaque window can be made a fullscreen window28* @author Artem Ananiev29* @run main TranslucentWindow30*/3132import java.awt.*;33import java.awt.geom.*;3435import static java.awt.GraphicsDevice.WindowTranslucency.*;363738public class TranslucentWindow {39public static void main(String args[]) {40Robot robot;41try {42robot = new Robot();43}catch(Exception ex) {44ex.printStackTrace();45throw new RuntimeException("Unexpected failure");46}4748GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();49GraphicsDevice gd = ge.getDefaultScreenDevice();5051Frame f = new Frame("Test frame");52f.setUndecorated(true);53f.setBounds(100, 100, 320, 240);5455// First, check it can be made fullscreen window without any effects applied56gd.setFullScreenWindow(f);57robot.waitForIdle();5859gd.setFullScreenWindow(null);60robot.waitForIdle();6162// Second, check if it applying any effects doesn't prevent the window63// from going into the fullscreen mode64if (gd.isWindowTranslucencySupported(PERPIXEL_TRANSPARENT)) {65f.setShape(new Ellipse2D.Float(0, 0, f.getWidth(), f.getHeight()));66}67if (gd.isWindowTranslucencySupported(TRANSLUCENT)) {68f.setOpacity(0.5f);69}70if (gd.isWindowTranslucencySupported(PERPIXEL_TRANSLUCENT)) {71f.setBackground(new Color(0, 0, 0, 128));72}73gd.setFullScreenWindow(f);74robot.waitForIdle();7576// Third, make sure all the effects are unset when entering the fullscreen mode77if (f.getShape() != null) {78throw new RuntimeException("Test FAILED: fullscreen window shape is not null");79}80if (Math.abs(f.getOpacity() - 1.0f) > 1e-4) {81throw new RuntimeException("Test FAILED: fullscreen window opacity is not 1.0f");82}83Color bgColor = f.getBackground();84if ((bgColor != null) && (bgColor.getAlpha() != 255)) {85throw new RuntimeException("Test FAILED: fullscreen window background color is not opaque");86}8788f.dispose();89System.out.println("Test PASSED");90}91}929394