Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Multiscreen/WindowGCChangeTest/WindowGCChangeTest.java
38828 views
/*1* Copyright (c) 2005, 2007, 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/*24test25@bug 486827826@summary Tests that GraphicsConfig for invisible (peerless) window is27updated after showing the window28@author artem.ananiev, area=awt.multiscreen29@library ../../regtesthelpers30@build Util31@run applet WindowGCChangeTest.html32*/3334import java.applet.Applet;3536import java.awt.*;37import java.awt.event.*;3839import test.java.awt.regtesthelpers.Util;4041public class WindowGCChangeTest extends Applet42{43public void init()44{45}4647public void start()48{49Robot robot = null;50try51{52robot = new Robot();53}54catch (Exception z)55{56z.printStackTrace(System.err);57throw new RuntimeException("Test FAILED: couldn't create Robot instance", z);58}5960setSize(200, 200);61setVisible(true);62validate();63Util.waitForIdle(robot);6465GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();66GraphicsDevice[] gds = ge.getScreenDevices();67// check 2-screens systems only68if (gds.length != 2)69{70return;71}7273int defGDNo = 0;74int nondefGDNo = 0;75boolean isVirtualScreen = false;76GraphicsDevice defgd = ge.getDefaultScreenDevice();77for (int i = 0; i < gds.length; i++)78{79Rectangle r = gds[i].getDefaultConfiguration().getBounds();80if ((r.x != 0) || (r.y != 0))81{82isVirtualScreen = true;83}84if (gds[i] == defgd)85{86defGDNo = i;87}88else89{90nondefGDNo = i;91}92}9394// doesn't test separate screens95if (!isVirtualScreen)96{97return;98}99100GraphicsDevice defGD = gds[defGDNo];101GraphicsDevice nondefGD = gds[nondefGDNo];102103final GraphicsConfiguration defGC = defGD.getDefaultConfiguration();104final GraphicsConfiguration nondefGC = nondefGD.getDefaultConfiguration();105106final Frame f = new Frame(defGC);107f.setBounds(nondefGC.getBounds().x + 100, nondefGC.getBounds().y + 100, 100, 100);108f.addWindowListener(new WindowAdapter()109{110public void windowActivated(WindowEvent ev)111{112GraphicsConfiguration gcf = f.getGraphicsConfiguration();113if (gcf != nondefGC)114{115throw new RuntimeException("Test FAILED: graphics config is not updated");116}117f.dispose();118}119});120f.setVisible(true);121Util.waitForIdle(robot);122123// paranoia - change def to nondef and vice versa124final Frame g = new Frame(nondefGC);125g.setBounds(defGC.getBounds().x + 100, defGC.getBounds().y + 100, 100, 100);126g.addWindowListener(new WindowAdapter()127{128public void windowActivated(WindowEvent ev)129{130GraphicsConfiguration gcg = g.getGraphicsConfiguration();131if (gcg != defGC)132{133throw new RuntimeException("Test FAILED: graphics config is not updated");134}135g.dispose();136}137});138g.setVisible(true);139Util.waitForIdle(robot);140141// test fullscreen changes142final Frame h = new Frame(defGC);143h.setBounds(defGC.getBounds().x + 100, defGC.getBounds().y + 100, 100, 100);144h.addWindowListener(new WindowAdapter()145{146public void windowActivated(WindowEvent ev)147{148GraphicsConfiguration gch = h.getGraphicsConfiguration();149if (gch != nondefGC)150{151throw new RuntimeException("Test FAILED: graphics config is not updated");152}153h.dispose();154}155});156h.setUndecorated(true);157nondefGD.setFullScreenWindow(h);158Util.waitForIdle(robot);159}160}161162163