0N/A/*
2362N/A * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A @test
0N/A @bug 4452373 6567564
0N/A @summary Tests that all the child and toplevel components have
0N/Atheir GraphicsConfiguration updated when the window moves from
0N/Aone screen to another, on Windows or Linux/Solaris + Xinerama
0N/A @author artem.ananiev: area=awt.multiscreen
0N/A @library ../../regtesthelpers
0N/A @build Util
0N/A @run main UpdateGCTest
0N/A*/
0N/A
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.*;
0N/A
0N/Aimport test.java.awt.regtesthelpers.Util;
0N/A
0N/Apublic class UpdateGCTest
0N/A{
0N/A public static void main(String[] args)
0N/A {
0N/A GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
0N/A GraphicsDevice[] gds = ge.getScreenDevices();
0N/A if (gds.length < 2)
0N/A {
0N/A System.out.println("The test should be run in multi-screen configuration. Test PASSED/skipped");
0N/A return;
0N/A }
0N/A boolean virtualConfig = false;
0N/A for (GraphicsDevice gd : gds)
0N/A {
0N/A GraphicsConfiguration gc = gd.getDefaultConfiguration();
0N/A if ((gc.getBounds().x != 0) || (gc.getBounds().y != 0))
0N/A {
0N/A virtualConfig = true;
0N/A break;
0N/A }
0N/A }
0N/A if (!virtualConfig)
0N/A {
0N/A System.out.println("The test should be run in virtual multi-screen mode. Test PASSED/skipped");
0N/A return;
0N/A }
0N/A
0N/A try
0N/A {
0N/A Robot robot = new Robot();
0N/A Util.waitForIdle(robot);
0N/A
0N/A for (GraphicsDevice gdOrig : gds)
0N/A {
0N/A GraphicsConfiguration gcOrig = gdOrig.getDefaultConfiguration();
0N/A
0N/A // test Frame
0N/A Frame f = new Frame("F", gcOrig);
0N/A f.setSize(200, 200);
0N/A f.setLayout(new BorderLayout());
0N/A // test Canvas
0N/A f.add(new Canvas(gcOrig), BorderLayout.NORTH);
0N/A // test lightweight
0N/A Container c = new Container() {};
0N/A c.setLayout(new BorderLayout());
0N/A // test hw inside lw
0N/A c.add(new Panel());
0N/A c.add(new Canvas(gcOrig));
0N/A f.add(c, BorderLayout.SOUTH);
0N/A // test Panel
0N/A Panel p = new Panel();
0N/A p.setLayout(new BorderLayout());
0N/A // test nested Canvas
0N/A p.add(new Canvas(gcOrig), BorderLayout.NORTH);
0N/A // test nested lightweight
0N/A p.add(new Component() {}, BorderLayout.SOUTH);
0N/A // test nested panel
0N/A p.add(new Panel(), BorderLayout.CENTER);
0N/A f.add(p, BorderLayout.CENTER);
0N/A
0N/A f.setVisible(true);
0N/A Util.waitForIdle(robot);
0N/A
0N/A for (GraphicsDevice gd : gds)
0N/A {
0N/A GraphicsConfiguration gc = gd.getDefaultConfiguration();
0N/A
0N/A f.setLocation(gc.getBounds().x + 100, gc.getBounds().y + 100);
0N/A Util.waitForIdle(robot);
0N/A
0N/A checkGC(f, gc);
0N/A }
0N/A }
0N/A }
0N/A catch (Exception z)
0N/A {
0N/A System.err.println("Unknown exception caught");
0N/A z.printStackTrace(System.err);
0N/A throw new RuntimeException("Test FAILED: " + z.getMessage());
0N/A }
0N/A
0N/A System.out.println("Test PASSED");
0N/A }
0N/A
0N/A private static void checkGC(Component c, GraphicsConfiguration gc)
0N/A {
0N/A if (c.getGraphicsConfiguration() != gc)
0N/A {
0N/A System.err.println("GC for component (" + c + ") is not updated");
0N/A System.err.println("Right GC: " + gc);
0N/A System.err.println("Component GC: " + c.getGraphicsConfiguration());
0N/A throw new RuntimeException("Test FAILED: component GC is not updated");
0N/A }
0N/A System.out.println("Checked GC for component (" + c + "): OK");
0N/A
0N/A if (c instanceof Container)
0N/A {
0N/A Container cc = (Container)c;
0N/A Component[] children = cc.getComponents();
0N/A for (Component child : children)
0N/A {
0N/A checkGC(child, gc);
0N/A }
0N/A }
0N/A }
0N/A}