Skip to content

Commit f840f01

Browse files
committed
8340966: Open source few Checkbox and Cursor tests - Set1
Backport-of: 3d38cd97eff2228e2172bfdbf5cc21cf2060f871
1 parent c200dd1 commit f840f01

File tree

5 files changed

+477
-0
lines changed

5 files changed

+477
-0
lines changed
Lines changed: 72 additions & 0 deletions
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+
}
Lines changed: 84 additions & 0 deletions
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+
}
Lines changed: 72 additions & 0 deletions
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+
}
Lines changed: 95 additions & 0 deletions
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+
}

0 commit comments

Comments
 (0)