Path: blob/master/test/jdk/java/awt/Multiscreen/WindowGCChangeTest/WindowGCChangeTest.java
41153 views
/*1* Copyright (c) 2005, 2018, 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 486827827@summary Tests that GraphicsConfig for invisible (peerless) windows is28updated after showing the window29@library ../../regtesthelpers30@build Util31@run main WindowGCChangeTest32*/3334import java.awt.*;35import java.awt.event.*;3637import test.java.awt.regtesthelpers.Util;3839public class WindowGCChangeTest {4041public static void main(final String[] args) {42Robot robot = null;43try44{45robot = new Robot();46}47catch (Exception z)48{49z.printStackTrace(System.err);50throw new RuntimeException("Test FAILED: couldn't create Robot instance", z);51}52Util.waitForIdle(robot);5354GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();55GraphicsDevice[] gds = ge.getScreenDevices();56// check 2-screens systems only57if (gds.length != 2)58{59return;60}6162int defGDNo = 0;63int nondefGDNo = 0;64boolean isVirtualScreen = false;65GraphicsDevice defgd = ge.getDefaultScreenDevice();66for (int i = 0; i < gds.length; i++)67{68Rectangle r = gds[i].getDefaultConfiguration().getBounds();69if ((r.x != 0) || (r.y != 0))70{71isVirtualScreen = true;72}73if (gds[i] == defgd)74{75defGDNo = i;76}77else78{79nondefGDNo = i;80}81}8283// doesn't test separate screens84if (!isVirtualScreen)85{86return;87}8889GraphicsDevice defGD = gds[defGDNo];90GraphicsDevice nondefGD = gds[nondefGDNo];9192final GraphicsConfiguration defGC = defGD.getDefaultConfiguration();93final GraphicsConfiguration nondefGC = nondefGD.getDefaultConfiguration();9495final Frame f = new Frame(defGC);96f.setBounds(nondefGC.getBounds().x + 100, nondefGC.getBounds().y + 100, 100, 100);97f.addWindowListener(new WindowAdapter()98{99public void windowActivated(WindowEvent ev)100{101GraphicsConfiguration gcf = f.getGraphicsConfiguration();102if (gcf != nondefGC)103{104throw new RuntimeException("Test FAILED: graphics config is not updated");105}106f.dispose();107}108});109f.setVisible(true);110Util.waitForIdle(robot);111112// paranoia - change def to nondef and vice versa113final Frame g = new Frame(nondefGC);114g.setBounds(defGC.getBounds().x + 100, defGC.getBounds().y + 100, 100, 100);115g.addWindowListener(new WindowAdapter()116{117public void windowActivated(WindowEvent ev)118{119GraphicsConfiguration gcg = g.getGraphicsConfiguration();120if (gcg != defGC)121{122throw new RuntimeException("Test FAILED: graphics config is not updated");123}124g.dispose();125}126});127g.setVisible(true);128Util.waitForIdle(robot);129130// test fullscreen changes131final Frame h = new Frame(defGC);132h.setBounds(defGC.getBounds().x + 100, defGC.getBounds().y + 100, 100, 100);133h.addWindowListener(new WindowAdapter()134{135public void windowActivated(WindowEvent ev)136{137GraphicsConfiguration gch = h.getGraphicsConfiguration();138if (gch != nondefGC)139{140throw new RuntimeException("Test FAILED: graphics config is not updated");141}142h.dispose();143}144});145h.setUndecorated(true);146nondefGD.setFullScreenWindow(h);147Util.waitForIdle(robot);148}149}150151152