WindowGCChangeTest.java revision 2362
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
2362N/A * published by the Free Software Foundation.
0N/A *
2362N/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 *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
2362N/A */
2362N/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;
}
int defGDNo = 0;
int nondefGDNo = 0;
boolean isVirtualScreen = false;
GraphicsDevice defgd = ge.getDefaultScreenDevice();
for (int i = 0; i < gds.length; i++)
{
Rectangle r = gds[i].getDefaultConfiguration().getBounds();
if ((r.x != 0) || (r.y != 0))
{
isVirtualScreen = true;
}
if (gds[i] == defgd)
{
defGDNo = i;
}
else
{
nondefGDNo = i;
}
}
// doesn't test separate screens
if (!isVirtualScreen)
{
return;
}
GraphicsDevice defGD = gds[defGDNo];
GraphicsDevice nondefGD = gds[nondefGDNo];
final GraphicsConfiguration defGC = defGD.getDefaultConfiguration();
final GraphicsConfiguration nondefGC = nondefGD.getDefaultConfiguration();
final Frame f = new Frame(defGC);
f.setBounds(nondefGC.getBounds().x + 100, nondefGC.getBounds().y + 100, 100, 100);
f.addWindowListener(new WindowAdapter()
{
public void windowActivated(WindowEvent ev)
{
GraphicsConfiguration gcf = f.getGraphicsConfiguration();
if (gcf != nondefGC)
{
throw new RuntimeException("Test FAILED: graphics config is not updated");
}
f.dispose();
}
});
f.setVisible(true);
Util.waitForIdle(robot);
// paranoia - change def to nondef and vice versa
final Frame g = new Frame(nondefGC);
g.setBounds(defGC.getBounds().x + 100, defGC.getBounds().y + 100, 100, 100);
g.addWindowListener(new WindowAdapter()
{
public void windowActivated(WindowEvent ev)
{
GraphicsConfiguration gcg = g.getGraphicsConfiguration();
if (gcg != defGC)
{
throw new RuntimeException("Test FAILED: graphics config is not updated");
}
g.dispose();
}
});
g.setVisible(true);
Util.waitForIdle(robot);
// test fullscreen changes
final Frame h = new Frame(defGC);
h.setBounds(defGC.getBounds().x + 100, defGC.getBounds().y + 100, 100, 100);
h.addWindowListener(new WindowAdapter()
{
public void windowActivated(WindowEvent ev)
{
GraphicsConfiguration gch = h.getGraphicsConfiguration();
if (gch != nondefGC)
{
throw new RuntimeException("Test FAILED: graphics config is not updated");
}
h.dispose();
}
});
h.setUndecorated(true);
nondefGD.setFullScreenWindow(h);
Util.waitForIdle(robot);
}
}