Skip to content

Commit 1ead0df

Browse files
committed
8340639: Open source few more AWT List tests
Backport-of: dd56990962d58e4f482773f67bc43383d7748536
1 parent 1d9bf98 commit 1ead0df

File tree

4 files changed

+388
-0
lines changed

4 files changed

+388
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright (c) 2006, 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 6355467
27+
* @summary Horizontal scroll bar thumb of a List does not stay at the end
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @requires (os.family == "linux")
31+
* @run main/manual HorizScrollWorkTest
32+
*/
33+
34+
import java.awt.FlowLayout;
35+
import java.awt.Frame;
36+
import java.awt.List;
37+
38+
public class HorizScrollWorkTest {
39+
40+
private static final String INSTRUCTIONS = """
41+
This is a linux only test.
42+
Drag and drop the horizontal scroll bar thumb at the right end.
43+
If the thumb does not stay at the right end, then the test failed. Otherwise passed.""";
44+
45+
public static void main(String[] args) throws Exception {
46+
PassFailJFrame.builder()
47+
.title("HorizScrollWorkTest Instructions")
48+
.instructions(INSTRUCTIONS)
49+
.rows((int)INSTRUCTIONS.lines().count() + 2)
50+
.columns(35)
51+
.testUI(HorizScrollWorkTest::createTestUI)
52+
.build()
53+
.awaitAndCheck();
54+
}
55+
56+
private static Frame createTestUI() {
57+
Frame frame = new Frame("HorizScrollWorkTest Frame");
58+
List list = new List(4);
59+
60+
frame.setLayout (new FlowLayout());
61+
62+
list.add("veryyyyyyyyyyyyyyyyyyyyyyyyyy longgggggggggggggggggggggg stringggggggggggggggggggggg");
63+
64+
frame.add(list);
65+
frame.pack();
66+
67+
return frame;
68+
}
69+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*
2+
* Copyright (c) 2003, 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 4895367
27+
* @summary List scrolling w/ down arrow keys obscures horizontal scrollbar
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @requires (os.family == "linux")
31+
* @run main/manual HorizScrollbarEraseTest
32+
*/
33+
34+
import java.awt.BorderLayout;
35+
import java.awt.Button;
36+
import java.awt.Frame;
37+
import java.awt.GridLayout;
38+
import java.awt.List;
39+
import java.awt.Panel;
40+
import java.awt.TextArea;
41+
import java.awt.event.ActionEvent;
42+
import java.awt.event.ActionListener;
43+
44+
public class HorizScrollbarEraseTest {
45+
46+
private static final String INSTRUCTIONS = """
47+
This is a Unix-only test.
48+
Do the four mini-tests below.
49+
If the horizontal scrollbar is ever erased by a rectangle
50+
of the background color, the test FAILS.
51+
If the horizontal scrollbars remain painted, test passes.""";
52+
53+
public static void main(String[] args) throws Exception {
54+
PassFailJFrame.builder()
55+
.title("HorizScrollbarEraseTest Instructions")
56+
.instructions(INSTRUCTIONS)
57+
.rows((int) INSTRUCTIONS.lines().count() + 2)
58+
.columns(35)
59+
.testUI(HorizScrollbarEraseTest::createTestUI)
60+
.build()
61+
.awaitAndCheck();
62+
}
63+
64+
private static Frame createTestUI() {
65+
Frame frame = new Frame("HorizScrollbarEraseTest");
66+
Panel borderPanel = new Panel();
67+
borderPanel.setLayout(new BorderLayout());
68+
Button focusedButton = new Button("Focus starts here");
69+
borderPanel.add(focusedButton, BorderLayout.NORTH);
70+
71+
Panel gridPanel = new Panel();
72+
gridPanel.setLayout(new GridLayout(0, 4));
73+
borderPanel.add(gridPanel, BorderLayout.CENTER);
74+
75+
InstructionList il1 = new InstructionList("Tab to Item 2, then \n" +
76+
"press the down" +
77+
"arrow key to scroll down");
78+
il1.list.select(2);
79+
il1.list.makeVisible(0);
80+
gridPanel.add(il1);
81+
82+
InstructionList il2 = new InstructionList("Tab to the next List,\n" +
83+
"then press the down\n" +
84+
"arrow key to select\n" +
85+
"the last item.");
86+
il2.list.select(3);
87+
il2.list.makeVisible(0);
88+
gridPanel.add(il2);
89+
90+
InstructionList il3 = new InstructionList("Click the button to\n" +
91+
"programmatically\n" +
92+
"select item 3 (not showing)");
93+
Button selectBtn = new Button("Click Me");
94+
final List selectList = il3.list;
95+
selectBtn.addActionListener(new ActionListener() {
96+
public void actionPerformed(ActionEvent e) {
97+
selectList.select(3);
98+
}
99+
});
100+
il3.add(selectBtn, BorderLayout.CENTER);
101+
gridPanel.add(il3);
102+
103+
InstructionList il4 = new InstructionList("Click the button to\nprogrammatically\ndeselect item 3\n(not showing)");
104+
Button deselectBtn = new Button("Click Me");
105+
final List deselectList = il4.list;
106+
deselectBtn.addActionListener(new ActionListener() {
107+
public void actionPerformed(ActionEvent e) {
108+
deselectList.deselect(3);
109+
}
110+
});
111+
il4.add(deselectBtn, BorderLayout.CENTER);
112+
il4.list.select(3);
113+
il4.list.makeVisible(0);
114+
gridPanel.add(il4);
115+
116+
frame.add(borderPanel);
117+
frame.pack();
118+
return frame;
119+
120+
}
121+
}
122+
123+
class InstructionList extends Panel {
124+
TextArea ta;
125+
public List list;
126+
127+
public InstructionList(String instructions) {
128+
super();
129+
setLayout(new BorderLayout());
130+
ta = new TextArea(instructions, 6, 25, TextArea.SCROLLBARS_NONE);
131+
ta.setFocusable(false);
132+
list = new List();
133+
for (int i = 0; i < 5; i++) {
134+
list.add("Item " + i + ", a long, long, long, long item");
135+
}
136+
add(ta, BorderLayout.NORTH);
137+
add(list, BorderLayout.SOUTH);
138+
}
139+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (c) 2006, 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 6336384
27+
* @summary ScrollBar does not show up correctly
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual ScrollbarPresenceTest
31+
*/
32+
33+
import java.awt.Font;
34+
import java.awt.Frame;
35+
import java.awt.List;
36+
37+
public class ScrollbarPresenceTest {
38+
39+
private static final String INSTRUCTIONS = """
40+
You will see a list,
41+
If a vertical scrollbar appears on the list and the list is big enough
42+
to show all items then the test failed else the test passed.""";
43+
44+
public static void main(String[] args) throws Exception {
45+
PassFailJFrame.builder()
46+
.title("ScrollbarPresenceTest Instructions")
47+
.instructions(INSTRUCTIONS)
48+
.rows((int) INSTRUCTIONS.lines().count() + 2)
49+
.columns(35)
50+
.testUI(ScrollbarPresenceTest::createTestUI)
51+
.build()
52+
.awaitAndCheck();
53+
}
54+
55+
private static Frame createTestUI() {
56+
Frame frame = new Frame("ScrollbarPresenceTest Frame");
57+
List list = new List();
58+
59+
for (int i = 0; i < 6; i++) {
60+
list.addItem("Row " + i);
61+
}
62+
63+
list.setFont(new Font("MonoSpaced", Font.PLAIN, 12));
64+
list.setBounds(30, 30, 128, 104);
65+
frame.add(list);
66+
67+
frame.pack();
68+
return frame;
69+
}
70+
71+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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 6246467
27+
* @summary Tests that list works correctly if user specified foreground colors on XToolkit/Motif
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual SetForegroundTest
31+
*/
32+
33+
import java.awt.Button;
34+
import java.awt.Component;
35+
import java.awt.Checkbox;
36+
import java.awt.Choice;
37+
import java.awt.Color;
38+
import java.awt.Component;
39+
import java.awt.Dimension;
40+
import java.awt.FlowLayout;
41+
import java.awt.Frame;
42+
import java.awt.Label;
43+
import java.awt.List;
44+
import java.awt.Panel;
45+
import java.awt.TextArea;
46+
import java.awt.TextField;
47+
import java.awt.ScrollPane;
48+
49+
public class SetForegroundTest {
50+
51+
private static final String INSTRUCTIONS = """
52+
To make sure, that for each component
53+
(Button, Checkbox, Label, List, TextArea, TextField, Choice)
54+
in the frame,
55+
the title exist and the color of the title is red.
56+
If not, the test failed.""";
57+
58+
public static void main(String[] args) throws Exception {
59+
PassFailJFrame.builder()
60+
.title("SetForegroundTest Instructions")
61+
.instructions(INSTRUCTIONS)
62+
.rows((int) INSTRUCTIONS.lines().count() + 2)
63+
.columns(35)
64+
.testUI(SetForegroundTest::createTestUI)
65+
.build()
66+
.awaitAndCheck();
67+
}
68+
69+
private static Frame createTestUI() {
70+
Frame frame = new Frame();
71+
ScrollPane sp = new ScrollPane() {
72+
public Dimension getPreferredSize() {
73+
return new Dimension(180, 180);
74+
}
75+
};
76+
Panel p = new Panel();
77+
Component childs[] = new Component[] {new Button("button"),
78+
new Checkbox("checkbox"),
79+
new Label("label"),
80+
new List(3, false),
81+
new TextArea("text area"),
82+
new TextField("text field"),
83+
new Choice()};
84+
85+
p.setLayout (new FlowLayout ());
86+
87+
sp.add(p);
88+
89+
sp.validate();
90+
91+
frame.add(sp);
92+
for (int i = 0; i < childs.length; i++){
93+
childs[i].setForeground(Color.red);
94+
}
95+
96+
for (int i = 0; i < childs.length; i++) {
97+
p.add(childs[i]);
98+
if (childs[i] instanceof List) {
99+
((List)childs[i]).add("list1");
100+
((List)childs[i]).add("list2");
101+
} else if (childs[i] instanceof Choice) {
102+
((Choice)childs[i]).add("choice1");
103+
((Choice)childs[i]).add("choice2");
104+
}
105+
}
106+
frame.pack();
107+
return frame;
108+
}
109+
}

0 commit comments

Comments
 (0)