Skip to content

Commit 97b7430

Browse files
committed
8340621: Open source several AWT List tests
Backport-of: ae4d2f15901bf02efceaac26ee4aa3ae666bf467
1 parent c3f5900 commit 97b7430

File tree

5 files changed

+500
-0
lines changed

5 files changed

+500
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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 6354810
27+
* @summary Items in the list are not grayed out when disabled, XToolkit
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual DisabledListIsGreyTest
31+
*/
32+
33+
import java.awt.FlowLayout;
34+
import java.awt.Frame;
35+
import java.awt.List;
36+
37+
public class DisabledListIsGreyTest {
38+
39+
private static final String INSTRUCTIONS = """
40+
1) After the test started you will see two lists.
41+
2) One of them is enabled, and the second is disabled.
42+
3) Check that the items of the disabled list are grayed.
43+
4) If so, the test passed. Otherwise, failed.""";
44+
45+
46+
public static void main(String[] args) throws Exception {
47+
PassFailJFrame.builder()
48+
.title("DisabledListIsGreyTest Instructions")
49+
.instructions(INSTRUCTIONS)
50+
.rows((int) INSTRUCTIONS.lines().count() + 2)
51+
.columns(35)
52+
.testUI(DisabledListIsGreyTest::createTestUI)
53+
.build()
54+
.awaitAndCheck();
55+
}
56+
57+
private static Frame createTestUI() {
58+
Frame frame = new Frame("DisabledListIsGreyTest Frame");
59+
frame.setLayout(new FlowLayout());
60+
61+
List list1 = new List(3);
62+
List list2 = new List(3);
63+
for (int i = 0; i < 5; i++) {
64+
list1.addItem("Item " + i);
65+
list2.addItem("Item " + i);
66+
}
67+
frame.add(list1);
68+
69+
list2.setEnabled(false);
70+
frame.add(list2);
71+
frame.pack();
72+
return frame;
73+
}
74+
75+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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 4085379
27+
* @summary List component not properly "resized" with GridBagLayout
28+
* @requires (os.family == "windows")
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual ListFrameResizeTest
32+
*/
33+
34+
import java.awt.Color;
35+
import java.awt.Frame;
36+
import java.awt.GridBagConstraints;
37+
import java.awt.GridBagLayout;
38+
import java.awt.Insets;
39+
import java.awt.List;
40+
41+
public class ListFrameResizeTest {
42+
43+
private static final String INSTRUCTIONS = """
44+
This test is for windows only.
45+
46+
1. A Frame will appear with a List
47+
(the List occupies the whole Frame)
48+
2. Minimize the Frame, the Frame is now in the Task Bar (ie.,iconified)
49+
3. Right click (right mouse button) the icon in the task bar
50+
and click on the 'maximize' menuitem to maximize the Frame
51+
4. If you notice the List has not been resized
52+
(ie.,if it partly occupies the Frame), then press FAIL else press PASS".""";
53+
54+
public static void main(String[] args) throws Exception {
55+
PassFailJFrame.builder()
56+
.title("ListFrameResizeTest Instructions")
57+
.instructions(INSTRUCTIONS)
58+
.rows((int) INSTRUCTIONS.lines().count() + 2)
59+
.columns(35)
60+
.testUI(ListFrameResizeTest::createTestUI)
61+
.build()
62+
.awaitAndCheck();
63+
}
64+
65+
private static Frame createTestUI() {
66+
wintest client = new wintest("ListFrameResizeTest Frame");
67+
client.resize(500, 300);
68+
client.setBackground(Color.blue);
69+
return client;
70+
}
71+
72+
}
73+
74+
class wintest extends Frame {
75+
private List msg;
76+
77+
public wintest(String title) {
78+
super(title);
79+
msg = new List();
80+
for (int i = 0; i < 100; i++) {
81+
msg.add("" + i);
82+
}
83+
84+
GridBagLayout gridbag = new GridBagLayout();
85+
GridBagConstraints constraints = new GridBagConstraints();
86+
87+
setLayout(gridbag);
88+
89+
constraints.fill = GridBagConstraints.BOTH;
90+
91+
constraints.anchor = GridBagConstraints.CENTER;
92+
constraints.insets = new Insets(10, 10, 10, 10);
93+
constraints.ipadx = 0;
94+
constraints.ipady = 0;
95+
constraints.weightx = 1;
96+
constraints.weighty = 1;
97+
constraints.gridx = 0;
98+
constraints.gridy = 0;
99+
constraints.gridwidth = GridBagConstraints.REMAINDER;
100+
constraints.gridheight = GridBagConstraints.REMAINDER;
101+
gridbag.setConstraints(msg, constraints);
102+
add(msg);
103+
}
104+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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 4201967
27+
* @summary tests that a multiselection list doesn't causes crash when FileDialog is invoked
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual MultiSelectionListCrashTest
31+
*/
32+
33+
import java.awt.Button;
34+
import java.awt.FileDialog;
35+
import java.awt.FlowLayout;
36+
import java.awt.Frame;
37+
import java.awt.List;
38+
import java.awt.event.ActionEvent;
39+
import java.awt.event.ActionListener;
40+
41+
public class MultiSelectionListCrashTest {
42+
43+
private static final String INSTRUCTIONS = """
44+
Press "Invoke dialog" button to invoke a FileDialog.
45+
When it appears close it by pressing cancel button.
46+
If all remaining frames are enabled and
47+
page fault didn't occur the test passed. Otherwise the test failed.
48+
49+
Try to invoke a FileDialog several times to verify that the bug doesn't exist.""";
50+
51+
public static void main(String[] args) throws Exception {
52+
PassFailJFrame.builder()
53+
.title("MultiSelectionListCrashTest Instructions")
54+
.instructions(INSTRUCTIONS)
55+
.rows((int) INSTRUCTIONS.lines().count() + 2)
56+
.columns(35)
57+
.testUI(MultiSelectionListCrashTest::createTestUI)
58+
.build()
59+
.awaitAndCheck();
60+
}
61+
62+
private static Frame createTestUI() {
63+
64+
Frame frame = new Frame("MultiSelectionListCrashTest frame");
65+
Button button = new Button("Invoke dialog");
66+
button.addActionListener(new FileDialogInvoker(frame));
67+
List list = new List(4, true);
68+
list.add("Item1");
69+
list.add("Item2");
70+
frame.setLayout(new FlowLayout());
71+
frame.add(button);
72+
frame.add(list);
73+
frame.setSize(200, 200);
74+
return frame;
75+
}
76+
}
77+
78+
class FileDialogInvoker implements ActionListener {
79+
FileDialog fileDialog;
80+
81+
public FileDialogInvoker(Frame frame) {
82+
fileDialog = new FileDialog(frame);
83+
}
84+
85+
public void actionPerformed(ActionEvent e) {
86+
fileDialog.setVisible(true);
87+
}
88+
89+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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 4024943
27+
* @summary Test for position of List scrollbar when it is added
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual ScrollbarPositionTest
31+
*/
32+
33+
import java.awt.Button;
34+
import java.awt.Frame;
35+
import java.awt.GridLayout;
36+
import java.awt.List;
37+
import java.awt.Panel;
38+
import java.awt.event.ActionEvent;
39+
import java.awt.event.ActionListener;
40+
41+
public class ScrollbarPositionTest {
42+
static int item = 0;
43+
static List list;
44+
static Button addButton, delButton;
45+
46+
private static final String INSTRUCTIONS = """
47+
Click on the "Add List Item" button many times
48+
until the vertical scrollbar appears.
49+
Verify that the displayed vertical scrollbar does not take the space
50+
that was occupied by buttons before the scrollbar is shown.""";
51+
52+
public static void main(String[] args) throws Exception {
53+
PassFailJFrame.builder()
54+
.title("ScrollbarPositionTest Instructions")
55+
.instructions(INSTRUCTIONS)
56+
.rows((int) INSTRUCTIONS.lines().count() + 2)
57+
.columns(35)
58+
.testUI(ScrollbarPositionTest::createTestUI)
59+
.build()
60+
.awaitAndCheck();
61+
}
62+
63+
private static Frame createTestUI() {
64+
Panel pan;
65+
66+
Frame frame = new Frame("ScrollbarPositionTest Frame");
67+
frame.setLayout(new GridLayout(1, 2));
68+
list = new List();
69+
frame.add(list);
70+
frame.add(pan = new Panel());
71+
pan.setLayout(new GridLayout(4, 1));
72+
73+
MyListener listener = new MyListener();
74+
addButton = new Button("Add List Item");
75+
addButton.addActionListener(listener);
76+
pan.add(addButton);
77+
78+
delButton = new Button("Delete List Item");
79+
delButton.addActionListener(listener);
80+
pan.add(delButton);
81+
82+
frame.pack();
83+
return frame;
84+
}
85+
86+
static class MyListener implements ActionListener {
87+
public void actionPerformed(ActionEvent evt) {
88+
if (evt.getSource() == addButton) {
89+
String s = "item";
90+
for (int i = 0; i <= item; i++) {
91+
s = s +" "+Integer.toString(i);
92+
}
93+
item++;
94+
list.addItem(s);
95+
} else if (evt.getSource() == delButton) {
96+
int i;
97+
if ((i = list.countItems()) > 0) {
98+
list.delItem(i - 1);
99+
--item;
100+
}
101+
}
102+
}
103+
}
104+
}

0 commit comments

Comments
 (0)