Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java
38828 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* @bug 683700426* @summary Checks that non-opaque window can be made a fullscreen window27* @author Artem Ananiev28* @run main TranslucentWindow29*/3031import java.awt.*;32import java.awt.geom.*;3334import static java.awt.GraphicsDevice.WindowTranslucency.*;353637public class TranslucentWindow {38public static void main(String args[]) {39Robot robot;40try {41robot = new Robot();42}catch(Exception ex) {43ex.printStackTrace();44throw new RuntimeException("Unexpected failure");45}4647GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();48GraphicsDevice gd = ge.getDefaultScreenDevice();4950Frame f = new Frame("Test frame");51f.setUndecorated(true);52f.setBounds(100, 100, 320, 240);5354// First, check it can be made fullscreen window without any effects applied55gd.setFullScreenWindow(f);56robot.waitForIdle();5758gd.setFullScreenWindow(null);59robot.waitForIdle();6061// Second, check if it applying any effects doesn't prevent the window62// from going into the fullscreen mode63if (gd.isWindowTranslucencySupported(PERPIXEL_TRANSPARENT)) {64f.setShape(new Ellipse2D.Float(0, 0, f.getWidth(), f.getHeight()));65}66if (gd.isWindowTranslucencySupported(TRANSLUCENT)) {67f.setOpacity(0.5f);68}69if (gd.isWindowTranslucencySupported(PERPIXEL_TRANSLUCENT)) {70f.setBackground(new Color(0, 0, 0, 128));71}72gd.setFullScreenWindow(f);73robot.waitForIdle();7475// Third, make sure all the effects are unset when entering the fullscreen mode76if (f.getShape() != null) {77throw new RuntimeException("Test FAILED: fullscreen window shape is not null");78}79if (Math.abs(f.getOpacity() - 1.0f) > 1e-4) {80throw new RuntimeException("Test FAILED: fullscreen window opacity is not 1.0f");81}82Color bgColor = f.getBackground();83if ((bgColor != null) && (bgColor.getAlpha() != 255)) {84throw new RuntimeException("Test FAILED: fullscreen window background color is not opaque");85}8687f.dispose();88System.out.println("Test PASSED");89}90}919293