Path: blob/master/test/jdk/java/awt/Multiscreen/UpdateGCTest/UpdateGCTest.java
41153 views
/*1* Copyright (c) 2007, 2016, 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 4452373 656756427@summary Tests that all the child and toplevel components have28their GraphicsConfiguration updated when the window moves from29one screen to another, on Windows or Linux/Solaris + Xinerama30@author artem.ananiev: area=awt.multiscreen31@library ../../regtesthelpers32@build Util33@run main UpdateGCTest34*/3536import java.awt.*;37import java.awt.event.*;3839import test.java.awt.regtesthelpers.Util;4041public class UpdateGCTest42{43public static void main(String[] args)44{45GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();46GraphicsDevice[] gds = ge.getScreenDevices();47if (gds.length < 2)48{49System.out.println("The test should be run in multi-screen configuration. Test PASSED/skipped");50return;51}52boolean virtualConfig = false;53for (GraphicsDevice gd : gds)54{55GraphicsConfiguration gc = gd.getDefaultConfiguration();56if ((gc.getBounds().x != 0) || (gc.getBounds().y != 0))57{58virtualConfig = true;59break;60}61}62if (!virtualConfig)63{64System.out.println("The test should be run in virtual multi-screen mode. Test PASSED/skipped");65return;66}6768try69{70Robot robot = new Robot();71Util.waitForIdle(robot);7273for (GraphicsDevice gdOrig : gds)74{75GraphicsConfiguration gcOrig = gdOrig.getDefaultConfiguration();7677// test Frame78Frame f = new Frame("F", gcOrig);79f.setSize(200, 200);80f.setLayout(new BorderLayout());81// test Canvas82f.add(new Canvas(gcOrig), BorderLayout.NORTH);83// test lightweight84Container c = new Container() {};85c.setLayout(new BorderLayout());86// test hw inside lw87c.add(new Panel());88c.add(new Canvas(gcOrig));89f.add(c, BorderLayout.SOUTH);90// test Panel91Panel p = new Panel();92p.setLayout(new BorderLayout());93// test nested Canvas94p.add(new Canvas(gcOrig), BorderLayout.NORTH);95// test nested lightweight96p.add(new Component() {}, BorderLayout.SOUTH);97// test nested panel98p.add(new Panel(), BorderLayout.CENTER);99f.add(p, BorderLayout.CENTER);100101f.setVisible(true);102Util.waitForIdle(robot);103104for (GraphicsDevice gd : gds)105{106GraphicsConfiguration gc = gd.getDefaultConfiguration();107108f.setLocation(gc.getBounds().x + 100, gc.getBounds().y + 100);109Util.waitForIdle(robot);110111checkGC(f, gc);112}113}114}115catch (Exception z)116{117System.err.println("Unknown exception caught");118z.printStackTrace(System.err);119throw new RuntimeException("Test FAILED: " + z.getMessage());120}121122System.out.println("Test PASSED");123}124125private static void checkGC(Component c, GraphicsConfiguration gc)126{127if (c.getGraphicsConfiguration() != gc)128{129System.err.println("GC for component (" + c + ") is not updated");130System.err.println("Right GC: " + gc);131System.err.println("Component GC: " + c.getGraphicsConfiguration());132throw new RuntimeException("Test FAILED: component GC is not updated");133}134System.out.println("Checked GC for component (" + c + "): OK");135136if (c instanceof Container)137{138Container cc = (Container)c;139Component[] children = cc.getComponents();140for (Component child : children)141{142checkGC(child, gc);143}144}145}146}147148149