Skip to content

Commit d5e87b4

Browse files
committed
8340193: Open source several AWT Dialog tests - Batch 1
Backport-of: 2d8fcc4271802b211c4718c6abae3ce9c99eafbd
1 parent c395a99 commit d5e87b4

File tree

11 files changed

+668
-0
lines changed

11 files changed

+668
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright (c) 2002, 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+
import java.awt.Dialog;
25+
import java.awt.Frame;
26+
import java.awt.Image;
27+
import java.awt.Label;
28+
import java.awt.MediaTracker;
29+
import java.awt.Toolkit;
30+
import java.awt.Window;
31+
import java.util.List;
32+
33+
/*
34+
* @test
35+
* @bug 4779641
36+
* @summary Test to verify that Non-resizable dialogs should not show icons
37+
* @requires (os.family == "windows")
38+
* @library /java/awt/regtesthelpers
39+
* @build PassFailJFrame
40+
* @run main/manual DialogIconTest
41+
*/
42+
43+
public class DialogIconTest {
44+
public static void main(String[] args) throws Exception {
45+
String INSTRUCTIONS = """
46+
1. This is a Windows-only test of Dialog icons
47+
2. You can see a frame with a swing icon and two dialogs that it
48+
owns. The resizable dialog should have the same icon as the
49+
frame. The non-resizable dialog should have no icon at all
50+
3. Press PASS if this is true, press FAIL otherwise
51+
""";
52+
PassFailJFrame.builder()
53+
.title("Test Instructions")
54+
.instructions(INSTRUCTIONS)
55+
.rows((int) INSTRUCTIONS.lines().count() + 2)
56+
.columns(35)
57+
.testUI(initialize())
58+
.build()
59+
.awaitAndCheck();
60+
}
61+
62+
public static List<Window> initialize() {
63+
Frame f = new Frame("Parent frame");
64+
f.setBounds(50, 50, 200, 200);
65+
66+
Dialog dr = new Dialog(f, "Resizable Dialog");
67+
dr.setLocation(100, 100);
68+
dr.add(new Label("Should inherit icon from parent"));
69+
dr.pack();
70+
71+
Dialog dn = new Dialog(f, "NON Resizable Dialog");
72+
dn.setLocation(150, 150);
73+
dn.add(new Label("Should have no icon"));
74+
dn.pack();
75+
dn.setResizable(false);
76+
77+
String fileName = System.getProperty("test.src") +
78+
System.getProperty("file.separator") + "swing.small.gif";
79+
80+
Image icon = Toolkit.getDefaultToolkit().createImage(fileName);
81+
MediaTracker tracker = new MediaTracker(f);
82+
tracker.addImage(icon, 0);
83+
try {
84+
tracker.waitForAll();
85+
} catch (InterruptedException ie) {
86+
throw new RuntimeException("MediaTracker addImage Interrupted!");
87+
}
88+
f.setIconImage(icon);
89+
return List.of(f, dn, dr);
90+
}
91+
}
Loading
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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+
import java.awt.Checkbox;
25+
import java.awt.Dialog;
26+
import java.awt.FlowLayout;
27+
import java.awt.Frame;
28+
import java.awt.Panel;
29+
import java.awt.TextArea;
30+
import java.awt.event.ComponentEvent;
31+
import java.awt.event.ComponentListener;
32+
import java.awt.event.ItemEvent;
33+
import java.awt.event.ItemListener;
34+
import java.lang.Exception;
35+
import java.lang.String;
36+
import java.lang.System;
37+
38+
/*
39+
* @test
40+
* @bug 4115213
41+
* @summary Test to verify Checks that with resizable set to false,
42+
* dialog can not be resized
43+
* @library /java/awt/regtesthelpers
44+
* @build PassFailJFrame
45+
* @run main/manual DialogResizeTest
46+
*/
47+
48+
public class DialogResizeTest {
49+
public static void main(String[] args) throws Exception {
50+
String INSTRUCTIONS = """
51+
1. When this test is run a dialog will display (setResizable Test)
52+
Click on the checkbox to change the dialog resizable state
53+
2. For both dialog resizable states (resizable, non-resizable) try to
54+
change the size of the dialog. When isResizable is true the dialog
55+
is resizable. When isResizable is false the dialog is non-resizable
56+
3. If this is the behavior that you observe, the test has passed, Press
57+
the Pass button. Otherwise the test has failed, Press the Fail button
58+
""";
59+
PassFailJFrame.builder()
60+
.title("Test Instructions")
61+
.instructions(INSTRUCTIONS)
62+
.rows((int) INSTRUCTIONS.lines().count() + 2)
63+
.columns(40)
64+
.testUI(initialize())
65+
.logArea(8)
66+
.build()
67+
.awaitAndCheck();
68+
}
69+
70+
public static Dialog initialize() {
71+
Frame f = new Frame("Owner Frame");
72+
MyDialog ld = new MyDialog(f);
73+
ld.setBounds(100, 100, 400, 150);
74+
ld.setResizable(false);
75+
System.out.println("isResizable is set to: " + ld.isResizable());
76+
return ld;
77+
}
78+
}
79+
80+
class MyDialog extends Dialog implements ItemListener {
81+
String sText = "Tests java.awt.Dialog.setResizable method";
82+
TextArea ta = new TextArea(sText, 2, 40, TextArea.SCROLLBARS_NONE);
83+
84+
public MyDialog(Frame f) {
85+
86+
super(f, "setResizable test", false);
87+
88+
Panel cbPanel = new Panel();
89+
cbPanel.setLayout(new FlowLayout());
90+
91+
Panel taPanel = new Panel();
92+
taPanel.setLayout(new FlowLayout());
93+
taPanel.add(ta);
94+
95+
Checkbox cb = new Checkbox("Check this box to change the dialog's " +
96+
"resizable state", null, isResizable());
97+
cb.setState(false);
98+
cb.addItemListener(this);
99+
cbPanel.add(cb);
100+
101+
add("North", taPanel);
102+
add("South", cbPanel);
103+
pack();
104+
}
105+
106+
public void itemStateChanged(ItemEvent evt) {
107+
setResizable(evt.getStateChange() == ItemEvent.SELECTED);
108+
109+
boolean bResizeState = isResizable();
110+
PassFailJFrame.log("isResizable is set to: " + bResizeState);
111+
112+
if (isResizable()) {
113+
ta.setText("dialog is resizable (isResizable = " + bResizeState + ")");
114+
} else {
115+
ta.setText("dialog is NOT resizable (isResizable = " + bResizeState + ")");
116+
}
117+
}
118+
}

0 commit comments

Comments
 (0)