0N/A/*
2362N/A * Copyright (c) 2005, 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 4868278
0N/A @summary Tests that GraphicsConfig for invisible (peerless) window is
0N/A updated after showing the window
0N/A @author artem.ananiev, area=awt.multiscreen
0N/A @library ../../regtesthelpers
0N/A @build Util
0N/A @run applet WindowGCChangeTest.html
0N/A*/
0N/A
0N/Aimport java.applet.Applet;
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 WindowGCChangeTest extends Applet
0N/A{
0N/A public void init()
0N/A {
0N/A }
0N/A
0N/A public void start()
0N/A {
0N/A Robot robot = null;
0N/A try
0N/A {
0N/A robot = new Robot();
0N/A }
0N/A catch (Exception z)
0N/A {
0N/A z.printStackTrace(System.err);
0N/A throw new RuntimeException("Test FAILED: couldn't create Robot instance", z);
0N/A }
0N/A
0N/A setSize(200, 200);
0N/A setVisible(true);
0N/A validate();
0N/A Util.waitForIdle(robot);
0N/A
0N/A GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
0N/A GraphicsDevice[] gds = ge.getScreenDevices();
0N/A // check 2-screens systems only
0N/A if (gds.length != 2)
0N/A {
0N/A return;
0N/A }
0N/A
0N/A int defGDNo = 0;
0N/A int nondefGDNo = 0;
0N/A boolean isVirtualScreen = false;
0N/A GraphicsDevice defgd = ge.getDefaultScreenDevice();
0N/A for (int i = 0; i < gds.length; i++)
0N/A {
0N/A Rectangle r = gds[i].getDefaultConfiguration().getBounds();
0N/A if ((r.x != 0) || (r.y != 0))
0N/A {
0N/A isVirtualScreen = true;
0N/A }
0N/A if (gds[i] == defgd)
0N/A {
0N/A defGDNo = i;
0N/A }
0N/A else
0N/A {
0N/A nondefGDNo = i;
0N/A }
0N/A }
0N/A
0N/A // doesn't test separate screens
0N/A if (!isVirtualScreen)
0N/A {
0N/A return;
0N/A }
0N/A
0N/A GraphicsDevice defGD = gds[defGDNo];
0N/A GraphicsDevice nondefGD = gds[nondefGDNo];
0N/A
0N/A final GraphicsConfiguration defGC = defGD.getDefaultConfiguration();
0N/A final GraphicsConfiguration nondefGC = nondefGD.getDefaultConfiguration();
0N/A
0N/A final Frame f = new Frame(defGC);
0N/A f.setBounds(nondefGC.getBounds().x + 100, nondefGC.getBounds().y + 100, 100, 100);
0N/A f.addWindowListener(new WindowAdapter()
0N/A {
0N/A public void windowActivated(WindowEvent ev)
0N/A {
0N/A GraphicsConfiguration gcf = f.getGraphicsConfiguration();
0N/A if (gcf != nondefGC)
0N/A {
0N/A throw new RuntimeException("Test FAILED: graphics config is not updated");
0N/A }
0N/A f.dispose();
0N/A }
0N/A });
0N/A f.setVisible(true);
0N/A Util.waitForIdle(robot);
0N/A
0N/A // paranoia - change def to nondef and vice versa
0N/A final Frame g = new Frame(nondefGC);
0N/A g.setBounds(defGC.getBounds().x + 100, defGC.getBounds().y + 100, 100, 100);
0N/A g.addWindowListener(new WindowAdapter()
0N/A {
0N/A public void windowActivated(WindowEvent ev)
0N/A {
0N/A GraphicsConfiguration gcg = g.getGraphicsConfiguration();
0N/A if (gcg != defGC)
0N/A {
0N/A throw new RuntimeException("Test FAILED: graphics config is not updated");
0N/A }
0N/A g.dispose();
0N/A }
0N/A });
0N/A g.setVisible(true);
0N/A Util.waitForIdle(robot);
0N/A
0N/A // test fullscreen changes
0N/A final Frame h = new Frame(defGC);
0N/A h.setBounds(defGC.getBounds().x + 100, defGC.getBounds().y + 100, 100, 100);
0N/A h.addWindowListener(new WindowAdapter()
0N/A {
0N/A public void windowActivated(WindowEvent ev)
0N/A {
0N/A GraphicsConfiguration gch = h.getGraphicsConfiguration();
0N/A if (gch != nondefGC)
0N/A {
0N/A throw new RuntimeException("Test FAILED: graphics config is not updated");
0N/A }
0N/A h.dispose();
0N/A }
0N/A });
0N/A h.setUndecorated(true);
0N/A nondefGD.setFullScreenWindow(h);
0N/A Util.waitForIdle(robot);
0N/A }
0N/A}