blob: 82cd0d9d4dc8e19443e069bb984f409164ea7cbd [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2005-2007 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 test
26 @bug 4868278
27 @summary Tests that GraphicsConfig for invisible (peerless) window is
28 updated after showing the window
29 @author artem.ananiev, area=awt.multiscreen
30 @library ../../regtesthelpers
31 @build Util
32 @run applet WindowGCChangeTest.html
33*/
34
35import java.applet.Applet;
36
37import java.awt.*;
38import java.awt.event.*;
39
40import test.java.awt.regtesthelpers.Util;
41
42public class WindowGCChangeTest extends Applet
43{
44 public void init()
45 {
46 }
47
48 public void start()
49 {
50 Robot robot = null;
51 try
52 {
53 robot = new Robot();
54 }
55 catch (Exception z)
56 {
57 z.printStackTrace(System.err);
58 throw new RuntimeException("Test FAILED: couldn't create Robot instance", z);
59 }
60
61 setSize(200, 200);
62 setVisible(true);
63 validate();
64 Util.waitForIdle(robot);
65
66 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
67 GraphicsDevice[] gds = ge.getScreenDevices();
68 // check 2-screens systems only
69 if (gds.length != 2)
70 {
71 return;
72 }
73
74 int defGDNo = 0;
75 int nondefGDNo = 0;
76 boolean isVirtualScreen = false;
77 GraphicsDevice defgd = ge.getDefaultScreenDevice();
78 for (int i = 0; i < gds.length; i++)
79 {
80 Rectangle r = gds[i].getDefaultConfiguration().getBounds();
81 if ((r.x != 0) || (r.y != 0))
82 {
83 isVirtualScreen = true;
84 }
85 if (gds[i] == defgd)
86 {
87 defGDNo = i;
88 }
89 else
90 {
91 nondefGDNo = i;
92 }
93 }
94
95 // doesn't test separate screens
96 if (!isVirtualScreen)
97 {
98 return;
99 }
100
101 GraphicsDevice defGD = gds[defGDNo];
102 GraphicsDevice nondefGD = gds[nondefGDNo];
103
104 final GraphicsConfiguration defGC = defGD.getDefaultConfiguration();
105 final GraphicsConfiguration nondefGC = nondefGD.getDefaultConfiguration();
106
107 final Frame f = new Frame(defGC);
108 f.setBounds(nondefGC.getBounds().x + 100, nondefGC.getBounds().y + 100, 100, 100);
109 f.addWindowListener(new WindowAdapter()
110 {
111 public void windowActivated(WindowEvent ev)
112 {
113 GraphicsConfiguration gcf = f.getGraphicsConfiguration();
114 if (gcf != nondefGC)
115 {
116 throw new RuntimeException("Test FAILED: graphics config is not updated");
117 }
118 f.dispose();
119 }
120 });
121 f.setVisible(true);
122 Util.waitForIdle(robot);
123
124 // paranoia - change def to nondef and vice versa
125 final Frame g = new Frame(nondefGC);
126 g.setBounds(defGC.getBounds().x + 100, defGC.getBounds().y + 100, 100, 100);
127 g.addWindowListener(new WindowAdapter()
128 {
129 public void windowActivated(WindowEvent ev)
130 {
131 GraphicsConfiguration gcg = g.getGraphicsConfiguration();
132 if (gcg != defGC)
133 {
134 throw new RuntimeException("Test FAILED: graphics config is not updated");
135 }
136 g.dispose();
137 }
138 });
139 g.setVisible(true);
140 Util.waitForIdle(robot);
141
142 // test fullscreen changes
143 final Frame h = new Frame(defGC);
144 h.setBounds(defGC.getBounds().x + 100, defGC.getBounds().y + 100, 100, 100);
145 h.addWindowListener(new WindowAdapter()
146 {
147 public void windowActivated(WindowEvent ev)
148 {
149 GraphicsConfiguration gch = h.getGraphicsConfiguration();
150 if (gch != nondefGC)
151 {
152 throw new RuntimeException("Test FAILED: graphics config is not updated");
153 }
154 h.dispose();
155 }
156 });
157 h.setUndecorated(true);
158 nondefGD.setFullScreenWindow(h);
159 Util.waitForIdle(robot);
160 }
161}