887
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
887
|
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 |
*
|
5506
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
887
|
22 |
*/
|
|
23 |
/**
|
|
24 |
* @test
|
|
25 |
* @bug 6614214
|
|
26 |
* @summary Verifies that we enter the fs mode on the correct screen.
|
|
27 |
* Here is how to test: start the test on on a multi-screen system.
|
|
28 |
* Verify that the display is correctly tracked by dragging the frame back
|
|
29 |
* and forth between screens. Then verify that the correct device enters
|
|
30 |
* the full-screen mode - when "Enter FS mode" is pressed it should enter on
|
|
31 |
* the device where the frame is.
|
|
32 |
*
|
|
33 |
* Then change the order of the monitors in the DisplayProperties dialog,
|
|
34 |
* (while the app is running) and see that it still works.
|
|
35 |
* Restart the app, verify again.
|
|
36 |
*
|
|
37 |
* Now change the primary monitor on the system and verify with the
|
|
38 |
* app running, as well as after restarting it that we still enter the
|
|
39 |
* fs mode on the right device.
|
|
40 |
*
|
|
41 |
* @run main/manual/othervm DeviceIdentificationTest
|
|
42 |
* @run main/manual/othervm -Dsun.java2d.noddraw=true DeviceIdentificationTest
|
|
43 |
* @run main/manual/othervm -Dsun.java2d.opengl=True DeviceIdentificationTest
|
|
44 |
*/
|
|
45 |
|
|
46 |
import java.awt.Button;
|
|
47 |
import java.awt.Color;
|
|
48 |
import java.awt.Frame;
|
|
49 |
import java.awt.Graphics;
|
|
50 |
import java.awt.GraphicsConfiguration;
|
|
51 |
import java.awt.GraphicsDevice;
|
|
52 |
import java.awt.GraphicsEnvironment;
|
|
53 |
import java.awt.Panel;
|
|
54 |
import java.awt.event.ActionEvent;
|
|
55 |
import java.awt.event.ActionListener;
|
|
56 |
import java.awt.event.ComponentAdapter;
|
|
57 |
import java.awt.event.ComponentEvent;
|
|
58 |
import java.awt.event.MouseAdapter;
|
|
59 |
import java.awt.event.MouseEvent;
|
|
60 |
import java.awt.event.WindowAdapter;
|
|
61 |
import java.awt.event.WindowEvent;
|
|
62 |
|
|
63 |
public class DeviceIdentificationTest {
|
|
64 |
|
|
65 |
public static void main(String args[]) {
|
|
66 |
final Frame f = new Frame("DeviceIdentificationTest");
|
|
67 |
f.addWindowListener(new WindowAdapter() {
|
|
68 |
public void windowClosing(WindowEvent e) {
|
|
69 |
f.dispose();
|
|
70 |
}
|
|
71 |
});
|
|
72 |
f.addComponentListener(new ComponentAdapter() {
|
|
73 |
public void componentMoved(ComponentEvent e) {
|
|
74 |
f.setTitle("Currently on: "+
|
|
75 |
f.getGraphicsConfiguration().getDevice());
|
|
76 |
}
|
|
77 |
});
|
|
78 |
|
|
79 |
Panel p = new Panel();
|
|
80 |
Button b = new Button("Print Current Devices");
|
|
81 |
b.addActionListener(new ActionListener() {
|
|
82 |
public void actionPerformed(ActionEvent e) {
|
|
83 |
GraphicsDevice gds[] =
|
|
84 |
GraphicsEnvironment.getLocalGraphicsEnvironment().
|
|
85 |
getScreenDevices();
|
|
86 |
int i = 0;
|
|
87 |
System.err.println("--- Devices: ---");
|
|
88 |
for (GraphicsDevice gd : gds) {
|
|
89 |
System.err.println("Device["+i+"]= "+ gd);
|
|
90 |
System.err.println(" bounds = "+
|
|
91 |
gd.getDefaultConfiguration().getBounds());
|
|
92 |
i++;
|
|
93 |
}
|
|
94 |
System.err.println("-------------------");
|
|
95 |
}
|
|
96 |
});
|
|
97 |
p.add(b);
|
|
98 |
|
|
99 |
b = new Button("Print My Device");
|
|
100 |
b.addActionListener(new ActionListener() {
|
|
101 |
public void actionPerformed(ActionEvent e) {
|
|
102 |
GraphicsConfiguration gc = f.getGraphicsConfiguration();
|
|
103 |
GraphicsDevice gd = gc.getDevice();
|
|
104 |
System.err.println("--- My Device ---");
|
|
105 |
System.err.println("Device = "+ gd);
|
|
106 |
System.err.println(" bounds = "+
|
|
107 |
gd.getDefaultConfiguration().getBounds());
|
|
108 |
}
|
|
109 |
});
|
|
110 |
p.add(b);
|
|
111 |
|
|
112 |
b = new Button("Create FS Frame on my Device");
|
|
113 |
b.addActionListener(new ActionListener() {
|
|
114 |
public void actionPerformed(ActionEvent e) {
|
|
115 |
GraphicsConfiguration gc = f.getGraphicsConfiguration();
|
|
116 |
final GraphicsDevice gd = gc.getDevice();
|
|
117 |
System.err.println("--- Creating FS Frame on Device ---");
|
|
118 |
System.err.println("Device = "+ gd);
|
|
119 |
System.err.println(" bounds = "+
|
|
120 |
gd.getDefaultConfiguration().getBounds());
|
|
121 |
final Frame fsf = new Frame("Full-screen Frame on dev"+gd, gc) {
|
|
122 |
public void paint(Graphics g) {
|
|
123 |
g.setColor(Color.green);
|
|
124 |
g.fillRect(0, 0, getWidth(), getHeight());
|
|
125 |
g.setColor(Color.red);
|
|
126 |
g.drawString("FS on device: "+gd, 200, 200);
|
|
127 |
g.drawString("Click to exit Full-screen.", 200, 250);
|
|
128 |
}
|
|
129 |
};
|
|
130 |
fsf.setUndecorated(true);
|
|
131 |
fsf.addMouseListener(new MouseAdapter() {
|
|
132 |
public void mouseClicked(MouseEvent e) {
|
|
133 |
gd.setFullScreenWindow(null);
|
|
134 |
fsf.dispose();
|
|
135 |
}
|
|
136 |
});
|
|
137 |
gd.setFullScreenWindow(fsf);
|
|
138 |
}
|
|
139 |
});
|
|
140 |
p.add(b);
|
|
141 |
f.add("North", p);
|
|
142 |
|
|
143 |
p = new Panel();
|
|
144 |
b = new Button("Test Passed");
|
|
145 |
b.setBackground(Color.green);
|
|
146 |
b.addActionListener(new ActionListener() {
|
|
147 |
public void actionPerformed(ActionEvent e) {
|
|
148 |
System.out.println("Test Passed");
|
|
149 |
f.dispose();
|
|
150 |
}
|
|
151 |
});
|
|
152 |
p.add(b);
|
|
153 |
b = new Button("Test Failed");
|
|
154 |
b.setBackground(Color.red);
|
|
155 |
b.addActionListener(new ActionListener() {
|
|
156 |
public void actionPerformed(ActionEvent e) {
|
|
157 |
System.out.println("Test FAILED");
|
|
158 |
f.dispose();
|
|
159 |
throw new RuntimeException("Test FAILED");
|
|
160 |
}
|
|
161 |
});
|
|
162 |
p.add(b);
|
|
163 |
f.add("South", p);
|
|
164 |
|
|
165 |
f.pack();
|
|
166 |
f.setVisible(true);
|
|
167 |
}
|
|
168 |
}
|