Skip to content

Commit e391c81

Browse files
author
Satyen Subramaniam
committed
8354493: Opensource Several MultiScreen and Insets related tests
Backport-of: e9c8986a65df534ee2a396cb3b49fe3dbcaf6a44
1 parent e915df8 commit e391c81

File tree

3 files changed

+480
-0
lines changed

3 files changed

+480
-0
lines changed
Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
/*
2+
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. 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 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.
22+
*/
23+
24+
import java.awt.Button;
25+
import java.awt.Color;
26+
import java.awt.Dialog;
27+
import java.awt.Dimension;
28+
import java.awt.Frame;
29+
import java.awt.GraphicsConfiguration;
30+
import java.awt.GraphicsDevice;
31+
import java.awt.GraphicsEnvironment;
32+
import java.awt.GridLayout;
33+
import java.awt.Label;
34+
import java.awt.Panel;
35+
import java.awt.Point;
36+
import java.awt.ScrollPane;
37+
38+
import java.awt.event.ActionEvent;
39+
import java.awt.event.ActionListener;
40+
import java.awt.event.WindowAdapter;
41+
import java.awt.event.WindowEvent;
42+
43+
import javax.swing.JDialog;
44+
import javax.swing.JLabel;
45+
import javax.swing.WindowConstants;
46+
47+
import jtreg.SkippedException;
48+
49+
/*
50+
* @test
51+
* @bug 4368500
52+
* @key multimon
53+
* @summary Dialog needs a constructor with GraphicsConfiguration
54+
* @library /java/awt/regtesthelpers /test/lib
55+
* @build PassFailJFrame
56+
* @run main/manual DialogTest
57+
*/
58+
59+
public class DialogTest {
60+
static GraphicsDevice[] gds;
61+
62+
private static Frame f;
63+
private static Frame dummyFrame = new Frame();
64+
private static Dialog dummyDialog = new Dialog(dummyFrame);
65+
66+
public static void main(String[] args) throws Exception {
67+
gds = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
68+
if (gds.length < 2) {
69+
throw new SkippedException("You have only one monitor in your system" +
70+
" - test skipped");
71+
}
72+
73+
String INSTRUCTIONS = """
74+
This test tests the multiscreen functionality of Dialogs and JDialogs.
75+
You should see the message "X screens detected", where X
76+
is the number of screens on your system. If X is incorrect, press Fail.
77+
78+
In the test window, there are a list of buttons representing each
79+
type of dialog for each screen.
80+
If there aren't buttons for every screen in your system, press Fail.
81+
82+
Press each button, and the indicated type of dialog should appear
83+
on the indicated screen.
84+
Modal dialogs should not allow to click on the Instructions or
85+
DialogTest windows.
86+
87+
The buttons turn yellow once they have been pressed, to keep track
88+
of test progress.
89+
90+
If all Dialogs appear correctly, press Pass.
91+
If Dialogs appear on the wrong screen or don't behave in
92+
proper modality, press Fail.""";
93+
94+
PassFailJFrame.builder()
95+
.instructions(INSTRUCTIONS)
96+
.columns(40)
97+
.logArea(5)
98+
.testUI(DialogTest::init)
99+
.build()
100+
.awaitAndCheck();
101+
}
102+
103+
public static Frame init() {
104+
PassFailJFrame.log(gds.length + " screens detected.");
105+
f = new Frame("DialogTest UI");
106+
f.setSize(400, 400);
107+
MyScrollPane sp = new MyScrollPane();
108+
109+
Panel p = new Panel();
110+
p.setLayout(new GridLayout(0, 1));
111+
112+
for (int i = 0; i < gds.length; i++) {
113+
Button btn;
114+
115+
//screen # , modal, frame-owned, swing
116+
btn = new MyButton(new DialogInfo(i, false, false, false));
117+
p.add(btn);
118+
119+
btn = new MyButton(new DialogInfo(i, true, false, false));
120+
p.add(btn);
121+
122+
btn = new MyButton(new DialogInfo(i, false, true, false));
123+
p.add(btn);
124+
125+
btn = new MyButton(new DialogInfo(i, true, true, false));
126+
p.add(btn);
127+
128+
btn = new MyButton(new DialogInfo(i, false, false, true));
129+
p.add(btn);
130+
131+
btn = new MyButton(new DialogInfo(i, true, false, true));
132+
p.add(btn);
133+
134+
btn = new MyButton(new DialogInfo(i, false, true, true));
135+
p.add(btn);
136+
137+
btn = new MyButton(new DialogInfo(i, true, true, true));
138+
p.add(btn);
139+
140+
}
141+
sp.add(p);
142+
f.add(sp);
143+
return f;
144+
}
145+
146+
static class MyScrollPane extends ScrollPane {
147+
@Override
148+
public Dimension getPreferredSize() {
149+
return f.getSize();
150+
}
151+
}
152+
153+
static class MyButton extends Button {
154+
public MyButton(DialogInfo info) {
155+
setLabel(info.toString());
156+
addActionListener(new PutupDialog(info));
157+
}
158+
}
159+
160+
static class PutupDialog implements ActionListener {
161+
DialogInfo info;
162+
163+
public PutupDialog(DialogInfo info) {
164+
this.info = info;
165+
}
166+
167+
@Override
168+
public void actionPerformed(ActionEvent e) {
169+
((Button) (e.getSource())).setBackground(Color.yellow);
170+
Dialog d = info.createDialog();
171+
d.show();
172+
}
173+
}
174+
175+
static class DialogInfo {
176+
int num;
177+
boolean modal;
178+
boolean frameOwned;
179+
boolean swing;
180+
181+
public DialogInfo(int num, boolean modal, boolean frameOwned, boolean swing) {
182+
this.num = num;
183+
this.modal = modal;
184+
this.frameOwned = frameOwned;
185+
this.swing = swing;
186+
}
187+
188+
public Dialog createDialog() {
189+
GraphicsConfiguration gc = gds[num].getDefaultConfiguration();
190+
191+
Dialog d;
192+
193+
if (swing) {
194+
if (frameOwned) {
195+
d = new JDialog(dummyFrame, toString(), modal, gc);
196+
} else {
197+
d = new JDialog(dummyDialog, toString(), modal, gc);
198+
}
199+
200+
((JDialog) d).setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
201+
if (modal) {
202+
((JDialog) d).getContentPane().add(new JLabel("Check that I am modal!"));
203+
}
204+
} else {
205+
if (frameOwned) {
206+
d = new Dialog(dummyFrame, toString(), modal, gc);
207+
} else {
208+
d = new Dialog(dummyDialog, toString(), modal, gc);
209+
}
210+
211+
d.addWindowListener(new WindowAdapter() {
212+
public void windowClosing(WindowEvent e) {
213+
e.getComponent().hide();
214+
}
215+
});
216+
if (modal) {
217+
d.add(new Label("Check that I am modal!"));
218+
}
219+
}
220+
221+
d.setLocation(new Point((int) (gc.getBounds().getX() + 20)
222+
, (int) (gc.getBounds().getY() + 20)));
223+
d.setSize(300, 100);
224+
225+
return d;
226+
}
227+
228+
public String toString() {
229+
return "Screen " + num + (frameOwned ? " Frame-owned" : " Dialog-owned")
230+
+ (modal ? " modal " : " non-modal ")
231+
+ (swing ? "JDialog" : "Dialog");
232+
}
233+
}
234+
}
235+
236+
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. 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 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.
22+
*/
23+
24+
import java.awt.Button;
25+
import java.awt.Frame;
26+
import java.awt.GraphicsConfiguration;
27+
import java.awt.GraphicsDevice;
28+
import java.awt.GraphicsEnvironment;
29+
import java.awt.GridLayout;
30+
import java.awt.Rectangle;
31+
32+
import java.awt.event.ActionEvent;
33+
import java.awt.event.ActionListener;
34+
35+
import jtreg.SkippedException;
36+
37+
/*
38+
* @test
39+
* @bug 4356756
40+
* @key multimon
41+
* @summary Return all screen devices for physical and virtual display devices
42+
* @library /java/awt/regtesthelpers /test/lib
43+
* @build PassFailJFrame
44+
* @run main/manual FillThisScreen
45+
*/
46+
47+
public class FillThisScreen {
48+
private static Frame f;
49+
private static Button b;
50+
private static Rectangle oldSize;
51+
private static boolean fillmode = true;
52+
static GraphicsDevice[] gs;
53+
54+
public static void main(String[] args) throws Exception {
55+
gs = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
56+
if (gs.length < 2) {
57+
throw new SkippedException("You have only one monitor in your system" +
58+
" - test skipped");
59+
}
60+
61+
String INSTRUCTIONS = """
62+
This test is for testing the bounds of a multimonitor system.
63+
You will see a Frame with several buttons: one marked 'Fill
64+
This Screen' and an additional button for each display on your system.
65+
66+
First, drag the Frame onto each display and click the
67+
'Fill This Screen' button.
68+
69+
The Frame should resize to take up the entire display area
70+
of the screen it is on, and the button text changes to say,
71+
'Get Smaller'.
72+
73+
Click the button again to restore the Frame.
74+
75+
Next, use the 'Move to screen' buttons to move the Frame to
76+
each display and again click the 'Fill This Screen' button.
77+
78+
If the number of 'Move to Screen' buttons is not equals to
79+
the number of screens on your system, the test fails.
80+
81+
If the Frame always correctly resizes to take up ONLY the
82+
entire screen it is on (and not a different screen, or all
83+
screens), the test passes else it fails.""";
84+
85+
PassFailJFrame.builder()
86+
.instructions(INSTRUCTIONS)
87+
.columns(40)
88+
.testUI(FillThisScreen::init)
89+
.build()
90+
.awaitAndCheck();
91+
}
92+
93+
public static Frame init() {
94+
Button tempBtn;
95+
96+
f = new Frame("Drag Me Around");
97+
f.setLayout(new GridLayout(0, 1));
98+
99+
b = new Button("Fill This Screen");
100+
b.addActionListener(new ActionListener() {
101+
@Override
102+
public void actionPerformed(ActionEvent e) {
103+
if (fillmode) {
104+
oldSize = f.getBounds();
105+
Rectangle r = f.getGraphicsConfiguration().getBounds();
106+
f.setBounds(r);
107+
b.setLabel("Get Smaller");
108+
} else {
109+
f.setBounds(oldSize);
110+
b.setLabel("Fill This Screen");
111+
}
112+
fillmode = !fillmode;
113+
}
114+
});
115+
f.add(b);
116+
117+
for (int i = 0; i < gs.length; i++) {
118+
tempBtn = new Button("Move to screen:" + i);
119+
tempBtn.addActionListener(new WinMover(i));
120+
f.add(tempBtn);
121+
}
122+
f.setSize(300, 100);
123+
return f;
124+
}
125+
126+
private static class WinMover implements ActionListener {
127+
int scrNum;
128+
129+
public WinMover(int scrNum) {
130+
this.scrNum = scrNum;
131+
}
132+
133+
public void actionPerformed(ActionEvent e) {
134+
Rectangle newBounds = gs[scrNum].getDefaultConfiguration().getBounds();
135+
f.setLocation(newBounds.x + newBounds.width / 2,
136+
newBounds.y + newBounds.height / 2);
137+
}
138+
139+
}
140+
}

0 commit comments

Comments
 (0)