Skip to content

Commit 49900d8

Browse files
committed
8341162: Open source some of the AWT window test
Backport-of: c8e70df37ebc90faaffae469244cefa10e8274c1
1 parent 7384b0f commit 49900d8

File tree

4 files changed

+327
-0
lines changed

4 files changed

+327
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright (c) 2005, 2024, 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+
/*
25+
* @test
26+
* @bug 6318630
27+
* @summary Test that location by platform works
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual TestLocationByPlatform
31+
*/
32+
33+
import java.awt.BorderLayout;
34+
import java.awt.Canvas;
35+
import java.awt.Color;
36+
import java.awt.Dimension;
37+
import java.awt.EventQueue;
38+
import java.awt.Frame;
39+
import java.awt.Graphics;
40+
41+
public class TestLocationByPlatform {
42+
public static void main(String[] args) throws Exception {
43+
String INSTRUCTIONS = """
44+
You should see two frames. One has locationByPlatform set, it
45+
should be displayed somewhere on the screen most probably without
46+
intersecting other Frames or stacked over normal frame with some
47+
offset. Another has its location explicitly set to (0, 450).
48+
Please verify that the frames are located correctly on the screen.
49+
50+
Also verify that the picture inside of frames looks the same
51+
and consists of red descending triangle occupying exactly the bottom
52+
half of the frame. Make sure that there is a blue rectangle exactly
53+
surrounding the client area of frame with no pixels between it and
54+
the frame's decorations. Press Pass if this all is true,
55+
otherwise press Fail.
56+
""";
57+
58+
PassFailJFrame passFailJFrame = PassFailJFrame.builder()
59+
.title("Test Instructions")
60+
.instructions(INSTRUCTIONS)
61+
.rows(13)
62+
.columns(40)
63+
.build();
64+
EventQueue.invokeAndWait(TestLocationByPlatform::createUI);
65+
passFailJFrame.awaitAndCheck();
66+
}
67+
private static void createUI() {
68+
Frame frame = new Frame("Normal");
69+
frame.setLocation(0, 450);
70+
Canvas c = new MyCanvas();
71+
frame.add(c, BorderLayout.CENTER);
72+
frame.pack();
73+
PassFailJFrame.addTestWindow(frame);
74+
frame.setVisible(true);
75+
76+
frame = new Frame("Location by platform");
77+
frame.setLocationByPlatform(true);
78+
c = new MyCanvas();
79+
frame.add(c, BorderLayout.CENTER);
80+
frame.pack();
81+
PassFailJFrame.addTestWindow(frame);
82+
frame.setVisible(true);
83+
}
84+
85+
static class MyCanvas extends Canvas {
86+
@Override
87+
public Dimension getPreferredSize() {
88+
return new Dimension(400, 400);
89+
}
90+
91+
@Override
92+
public void paint(Graphics g) {
93+
g.setColor(Color.red);
94+
for (int i = 399; i >= 0; i--) {
95+
g.drawLine(400 - i - 1, 400 - i - 1,
96+
400 - i - 1, 399);
97+
}
98+
g.setColor(Color.blue);
99+
g.drawLine(0, 0, 399, 0);
100+
g.drawLine(0, 0, 0, 399);
101+
g.drawLine(0, 399, 399, 399);
102+
g.drawLine(399, 0, 399, 399);
103+
}
104+
}
105+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 1998, 2024, 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+
/*
25+
* @test
26+
* @bug 4177156
27+
* @key headful
28+
* @summary Tests that multiple level of window ownership doesn't cause
29+
* NullPointerException when showing a Window
30+
* @run main OwnedWindowShowTest
31+
*/
32+
33+
import java.awt.EventQueue;
34+
import java.awt.Frame;
35+
import java.awt.Window;
36+
37+
public class OwnedWindowShowTest {
38+
public static void main(String[] args) throws Exception {
39+
EventQueue.invokeAndWait(OwnedWindowShowTest::runTest);
40+
}
41+
42+
static void runTest() {
43+
Frame parent = new Frame("OwnedWindowShowTest");
44+
try {
45+
Window owner = new Window(parent);
46+
Window window = new Window(owner);
47+
// Showing a window with multiple levels of ownership
48+
// should not throw NullPointerException
49+
window.setVisible(true);
50+
} finally {
51+
parent.dispose();
52+
}
53+
}
54+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (c) 1999, 2024, 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+
/*
25+
* @test
26+
* @bug 4225955
27+
* @summary Tests that focus lost is delivered to a lightweight component
28+
* in a disposed window
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual ResizeTest
32+
*/
33+
34+
import java.awt.BorderLayout;
35+
import java.awt.Button;
36+
import java.awt.Dialog;
37+
import java.awt.Frame;
38+
39+
public class ResizeTest
40+
{
41+
public static void main(String[] args) throws Exception {
42+
String INSTRUCTIONS = """
43+
1) Push button A to create modal dialog 2.
44+
2) Resize dialog 2, then click button B to hide it.
45+
3) Push button A again. Dialog B should be packed to its original
46+
size.
47+
4) Push button B again to hide, and A to reshow.
48+
Dialog B should still be the same size, then test is passed,
49+
otherwise failed.
50+
5) Push button B to hide the modal dialog and then select pass/fail.
51+
""";
52+
53+
PassFailJFrame.builder()
54+
.title("Test Instructions")
55+
.instructions(INSTRUCTIONS)
56+
.columns(40)
57+
.testUI(ResizeTest::createUI)
58+
.build()
59+
.awaitAndCheck();
60+
}
61+
62+
private static Frame createUI() {
63+
Frame f = new Frame("1");
64+
Dialog d = new Dialog(f, "2", true);
65+
d.setLocationRelativeTo(null);
66+
Button b2 = new Button("B");
67+
b2.addActionListener(e -> d.setVisible(false));
68+
d.setLayout(new BorderLayout());
69+
d.add(b2, BorderLayout.CENTER);
70+
71+
Button b = new Button("A");
72+
f.add(b, BorderLayout.CENTER);
73+
b.addActionListener(e -> {
74+
d.pack();
75+
d.setVisible(true);
76+
});
77+
f.pack();
78+
return f;
79+
}
80+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright (c) 1998, 2024, 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+
/*
25+
* @test
26+
* @bug 4084997
27+
* @summary See if Window can be created without its size explicitly set
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual ShowWindowTest
31+
*/
32+
33+
import java.awt.Button;
34+
import java.awt.FlowLayout;
35+
import java.awt.Frame;
36+
import java.awt.Label;
37+
import java.awt.Window;
38+
import java.awt.event.ActionEvent;
39+
import java.awt.event.ActionListener;
40+
41+
public class ShowWindowTest implements ActionListener
42+
{
43+
private static Window window;
44+
private static Button showButton;
45+
private static Button hideButton;
46+
47+
public static void main(String[] args) throws Exception {
48+
String INSTRUCTIONS = """
49+
1. You should see a Frame with a "Show" and a "Hide" button in it.
50+
2. Click on the "Show" button. A window with a "Hello World" Label
51+
should appear
52+
3. If the window does not appear, the test failed, otherwise passed.
53+
""";
54+
55+
PassFailJFrame.builder()
56+
.title("Test Instructions")
57+
.instructions(INSTRUCTIONS)
58+
.columns(40)
59+
.testUI(ShowWindowTest::createUI)
60+
.build()
61+
.awaitAndCheck();
62+
}
63+
64+
private static Frame createUI() {
65+
Frame frame = new Frame("ShowWindowTest");
66+
frame.setLayout(new FlowLayout());
67+
frame.setSize(100,100);
68+
frame.add(showButton = new Button("Show"));
69+
frame.add(hideButton = new Button("Hide"));
70+
71+
ActionListener handler = new ShowWindowTest();
72+
showButton.addActionListener(handler);
73+
hideButton.addActionListener(handler);
74+
75+
window = new Window(frame);
76+
window.add("Center", new Label("Hello World"));
77+
window.setLocationRelativeTo(null);
78+
return frame;
79+
}
80+
81+
public void actionPerformed(ActionEvent e) {
82+
if (e.getSource() == showButton) {
83+
window.pack();
84+
window.setVisible(true);
85+
} else if (e.getSource() == hideButton)
86+
window.setVisible(false);
87+
}
88+
}

0 commit comments

Comments
 (0)