Skip to content

Commit 3d38cd9

Browse files
author
Damon Nguyen
committedOct 4, 2024
8340966: Open source few Checkbox and Cursor tests - Set1
Reviewed-by: psadhukhan, jdv
1 parent 7e3978e commit 3d38cd9

File tree

5 files changed

+477
-0
lines changed

5 files changed

+477
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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 6225679
27+
* @summary Tests that checkbox changes into radiobutton dynamically
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual DynamicChangeTest
31+
*/
32+
33+
import java.awt.Checkbox;
34+
import java.awt.CheckboxGroup;
35+
import java.awt.Frame;
36+
import java.awt.GridLayout;
37+
38+
public class DynamicChangeTest {
39+
public static void main(String[] args) throws Exception {
40+
String INSTRUCTIONS = """
41+
This test is primarily for Windows platform, but should pass
42+
on other platforms as well. Ensure that 'This is checkbox' is
43+
checkbox, and 'This is radiobutton' is radiobutton.
44+
If it is so, press pass else fail.
45+
""";
46+
47+
PassFailJFrame.builder()
48+
.title("Test Instructions")
49+
.instructions(INSTRUCTIONS)
50+
.rows((int) INSTRUCTIONS.lines().count() + 2)
51+
.columns(35)
52+
.testUI(DynamicChangeTest::createUI)
53+
.build()
54+
.awaitAndCheck();
55+
}
56+
57+
public static Frame createUI() {
58+
Frame f = new Frame("Dynamic Change Checkbox Test");
59+
f.setSize(200, 200);
60+
61+
f.setLayout(new GridLayout(2, 1));
62+
Checkbox ch1 = new Checkbox("This is checkbox",
63+
new CheckboxGroup(), true);
64+
f.add(ch1);
65+
Checkbox ch2 = new Checkbox("This is radiobutton", null, true);
66+
f.add(ch2);
67+
68+
ch1.setCheckboxGroup(null);
69+
ch2.setCheckboxGroup(new CheckboxGroup());
70+
return f;
71+
}
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (c) 2000, 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 4313052
27+
* @summary Test cursor changes after mouse dragging ends
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual ListDragCursor
31+
*/
32+
33+
import java.awt.Cursor;
34+
import java.awt.Frame;
35+
import java.awt.List;
36+
import java.awt.Panel;
37+
import java.awt.TextArea;
38+
39+
public class ListDragCursor {
40+
public static void main(String[] args) throws Exception {
41+
String INSTRUCTIONS = """
42+
1. Move mouse to the TextArea.
43+
2. Press the left mouse button.
44+
3. Drag mouse to the list.
45+
4. Release the left mouse button.
46+
47+
If the mouse cursor starts as a Text Line Cursor and changes
48+
to a regular Pointer Cursor, then Hand Cursor when hovering
49+
the list, pass the test. This test fails if the cursor does
50+
not update at all when pointing over the different components.
51+
""";
52+
53+
PassFailJFrame.builder()
54+
.title("Test Instructions")
55+
.instructions(INSTRUCTIONS)
56+
.rows((int) INSTRUCTIONS.lines().count() + 2)
57+
.columns(35)
58+
.testUI(ListDragCursor::createUI)
59+
.build()
60+
.awaitAndCheck();
61+
}
62+
63+
public static Frame createUI() {
64+
Frame frame = new Frame("Cursor change after drag");
65+
Panel panel = new Panel();
66+
67+
List list = new List(2);
68+
list.add("List1");
69+
list.add("List2");
70+
list.add("List3");
71+
list.add("List4");
72+
list.setCursor(new Cursor(Cursor.HAND_CURSOR));
73+
74+
TextArea textArea = new TextArea(3, 5);
75+
textArea.setCursor(new Cursor(Cursor.TEXT_CURSOR));
76+
77+
panel.add(textArea);
78+
panel.add(list);
79+
80+
frame.add(panel);
81+
frame.setBounds(300, 100, 300, 150);
82+
return frame;
83+
}
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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 5079694
27+
* @summary Test if JDialog respects setCursor
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual HiddenDialogParentTest
31+
*/
32+
33+
import java.awt.BorderLayout;
34+
import java.awt.Color;
35+
import java.awt.Cursor;
36+
37+
import javax.swing.JDialog;
38+
import javax.swing.JLabel;
39+
import javax.swing.border.LineBorder;
40+
41+
public class HiddenDialogParentTest {
42+
public static void main(String[] args) throws Exception {
43+
String INSTRUCTIONS = """
44+
You can see a label area in the center of JDialog.
45+
Verify that the cursor is a hand cursor in this area.
46+
If so, press pass, else press fail.
47+
""";
48+
49+
PassFailJFrame.builder()
50+
.title("Test Instructions")
51+
.instructions(INSTRUCTIONS)
52+
.rows((int) INSTRUCTIONS.lines().count() + 2)
53+
.columns(35)
54+
.testUI(HiddenDialogParentTest::createUI)
55+
.build()
56+
.awaitAndCheck();
57+
}
58+
59+
public static JDialog createUI() {
60+
JDialog dialog = new JDialog();
61+
dialog.setTitle("JDialog Cursor Test");
62+
dialog.setLayout(new BorderLayout());
63+
JLabel centerLabel = new JLabel("Cursor should be a hand in this " +
64+
"label area");
65+
centerLabel.setBorder(new LineBorder(Color.BLACK));
66+
centerLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
67+
dialog.add(centerLabel, BorderLayout.CENTER);
68+
dialog.setSize(300, 200);
69+
70+
return dialog;
71+
}
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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 4212593
27+
* @summary The Toolkit.createCustomCursor does not check absence of the
28+
* image of cursor
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual InvalidImageCustomCursorTest
32+
*/
33+
34+
import java.awt.BorderLayout;
35+
import java.awt.Button;
36+
import java.awt.Color;
37+
import java.awt.Cursor;
38+
import java.awt.Frame;
39+
import java.awt.Image;
40+
import java.awt.Panel;
41+
import java.awt.Point;
42+
import java.awt.Toolkit;
43+
44+
public class InvalidImageCustomCursorTest {
45+
static Cursor cursor;
46+
47+
public static void main(String[] args) throws Exception {
48+
String INSTRUCTIONS = """
49+
Press 'Hide' button to hide (set transparent) cursor for the
50+
green panel. Move the pointer over the green panel - pointer
51+
should disappear. Press 'Default' button to set default cursor
52+
for the green panel.
53+
54+
If you see any exceptions or cursor is not transparent,
55+
test failed, otherwise it passed.
56+
""";
57+
58+
Toolkit tk = Toolkit.getDefaultToolkit();
59+
Image image = tk.getImage("NON_EXISTING_FILE.gif");
60+
Point p = new Point(0, 0);
61+
62+
cursor = tk.createCustomCursor(image, p, "Test");
63+
64+
PassFailJFrame.builder()
65+
.title("Test Instructions")
66+
.instructions(INSTRUCTIONS)
67+
.rows((int) INSTRUCTIONS.lines().count() + 2)
68+
.columns(35)
69+
.testUI(InvalidImageCustomCursorTest::createUI)
70+
.logArea(5)
71+
.build()
72+
.awaitAndCheck();
73+
}
74+
75+
public static Frame createUI() {
76+
Frame f = new Frame("Invalid Cursor Image Test");
77+
f.setLayout(new BorderLayout());
78+
f.setSize(200, 200);
79+
80+
Button def = new Button("Default");
81+
Button hide = new Button("Hide");
82+
Panel panel = new Panel();
83+
84+
def.addActionListener(e -> panel.setCursor(Cursor.getDefaultCursor()));
85+
hide.addActionListener(e -> panel.setCursor(cursor));
86+
87+
panel.setBackground(Color.green);
88+
panel.setSize(100, 100);
89+
f.add("Center", panel);
90+
f.add("North", hide);
91+
f.add("South", def);
92+
93+
return f;
94+
}
95+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
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 4111379
27+
* @summary Test for setting cursor to null for lightweight components
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual NullCursorTest
31+
*/
32+
33+
import java.awt.Button;
34+
import java.awt.Color;
35+
import java.awt.Component;
36+
import java.awt.Container;
37+
import java.awt.Cursor;
38+
import java.awt.Frame;
39+
import java.awt.Graphics;
40+
import java.awt.Rectangle;
41+
import java.awt.event.ActionEvent;
42+
import java.awt.event.ActionListener;
43+
import java.awt.event.MouseAdapter;
44+
import java.awt.event.MouseEvent;
45+
46+
public class NullCursorTest {
47+
public static void main(String[] args) throws Exception {
48+
String INSTRUCTIONS = """
49+
1. Hover over each colored area as described:
50+
Green area shows a CrossCursor.
51+
Red area shows a TextCursor.
52+
Yellow area shows a HandCursor.
53+
2. Click once in red area, then:
54+
Green area shows a HandCursor.
55+
Red area shows a BusyCursor.
56+
Yellow area shows a HandCursor.
57+
3. Click again in red area, then:
58+
Green area shows a CrossCursor.
59+
Red area shows a HandCursor.
60+
Yellow area shows a HandCursor.
61+
""";
62+
63+
PassFailJFrame.builder()
64+
.title("Test Instructions")
65+
.instructions(INSTRUCTIONS)
66+
.rows((int) INSTRUCTIONS.lines().count() + 2)
67+
.columns(35)
68+
.testUI(NullCursorTest::createUI)
69+
.build()
70+
.awaitAndCheck();
71+
}
72+
73+
public static Frame createUI() {
74+
Frame f = new Frame("Null Cursor Test Frame");
75+
f.setSize(200, 200);
76+
final Container p = f;
77+
p.setName("parent");
78+
p.setLayout(null);
79+
80+
final Component green = p.add(new Component() {
81+
public void paint(Graphics g) {
82+
Rectangle r = getBounds();
83+
g.setColor(Color.green);
84+
g.fillRect(0, 0, r.width, r.height);
85+
}
86+
});
87+
green.setName("green");
88+
green.setBackground(Color.red);
89+
green.setBounds(50, 50, 75, 75);
90+
green.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
91+
92+
Container h = new Container() {
93+
public void paint(Graphics g) {
94+
Rectangle r = getBounds();
95+
g.setColor(Color.yellow);
96+
g.fillRect(0, 0, r.width, r.height);
97+
super.paint(g);
98+
}
99+
};
100+
h.setBounds(15, 25, 150, 150);
101+
h.setName("container");
102+
h.setBackground(Color.yellow);
103+
h.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
104+
final Component red = new Component() {
105+
public void paint(Graphics g) {
106+
Rectangle r = getBounds();
107+
Color c = getBackground();
108+
g.setColor(c);
109+
g.fillRect(0, 0, r.width, r.height);
110+
super.paint(g);
111+
}
112+
};
113+
red.setName("red");
114+
red.setBackground(Color.red);
115+
red.setBounds(10, 10, 120, 120);
116+
red.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
117+
118+
final Button b = (Button)h.add(new Button("Test"));
119+
b.setBounds(10, 10, 40, 20);
120+
h.add(red);
121+
p.add(h);
122+
123+
b.addActionListener(new ActionListener() {
124+
boolean f = false;
125+
public void actionPerformed(ActionEvent e) {
126+
if (f) {
127+
b.setCursor(null);
128+
} else {
129+
b.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
130+
}
131+
f = !f;
132+
}
133+
});
134+
red.addMouseListener(new MouseAdapter() {
135+
boolean f = true;
136+
137+
public void mouseClicked(MouseEvent e) {
138+
Component c = (Component)e.getSource();
139+
if (f) {
140+
c.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
141+
p.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
142+
green.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
143+
f = false;
144+
} else {
145+
c.setCursor(null);
146+
p.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
147+
green.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
148+
f = true;
149+
}
150+
}
151+
});
152+
return f;
153+
}
154+
}

0 commit comments

Comments
 (0)
Please sign in to comment.