Skip to content

Commit ab07108

Browse files
committed
8341177: Opensource few List and a Window test
Backport-of: 602408e4f3848b30299ea94264e88ead5361a310
1 parent 98847a3 commit ab07108

File tree

4 files changed

+448
-0
lines changed

4 files changed

+448
-0
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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+
/*
25+
* @test
26+
* @bug 4234245
27+
* @summary the actionEvent is not invoked when hit enter on list.
28+
* @key headful
29+
* @run main ActionEventWhenHitEnterTest
30+
*/
31+
32+
import java.awt.BorderLayout;
33+
import java.awt.EventQueue;
34+
import java.awt.Frame;
35+
import java.awt.IllegalComponentStateException;
36+
import java.awt.List;
37+
import java.awt.Point;
38+
import java.awt.Robot;
39+
import java.awt.event.ActionEvent;
40+
import java.awt.event.ActionListener;
41+
import java.awt.event.InputEvent;
42+
import java.awt.event.ItemEvent;
43+
import java.awt.event.ItemListener;
44+
import java.awt.event.KeyEvent;
45+
46+
public class ActionEventWhenHitEnterTest
47+
implements ActionListener, ItemListener {
48+
49+
volatile boolean passed1;
50+
volatile boolean passed2;
51+
volatile Point pt;
52+
List list;
53+
Frame frame;
54+
55+
public static void main(final String[] args) throws Exception {
56+
ActionEventWhenHitEnterTest app = new ActionEventWhenHitEnterTest();
57+
app.doTest();
58+
}
59+
60+
public ActionEventWhenHitEnterTest() {
61+
list = new List(7);
62+
for (int i = 0; i < 10; i++) {
63+
list.add("Item " + i);
64+
}
65+
list.addItemListener(this);
66+
list.addActionListener(this);
67+
}
68+
69+
public void actionPerformed(ActionEvent ae) {
70+
passed1 = true;
71+
System.out.println("--> Action event invoked: " + ae.getSource());
72+
}
73+
74+
public void itemStateChanged(ItemEvent ie) {
75+
passed2 = true;
76+
System.out.println("--> Item state changed:" + ie.getSource());
77+
}
78+
79+
public void doTest() throws Exception {
80+
EventQueue.invokeAndWait(() -> {
81+
frame = new Frame("ActionEventWhenHitEnterTest");
82+
frame.add(list);
83+
frame.setSize(200, 200);
84+
frame.setLocationRelativeTo(null);
85+
frame.setVisible(true);
86+
});
87+
88+
try {
89+
Robot robot = new Robot();
90+
robot.setAutoDelay(100);
91+
robot.waitForIdle();
92+
robot.delay(1000);
93+
94+
EventQueue.invokeAndWait(() -> {
95+
pt = list.getLocationOnScreen();
96+
});
97+
98+
if (pt.x != 0 || pt.y != 0) {
99+
robot.mouseMove(pt.x + list.getWidth() / 2,
100+
pt.y + list.getHeight() / 2);
101+
robot.waitForIdle();
102+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
103+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
104+
robot.waitForIdle();
105+
106+
robot.keyPress(KeyEvent.VK_ENTER);
107+
robot.keyRelease(KeyEvent.VK_ENTER);
108+
}
109+
110+
robot.waitForIdle();
111+
} finally {
112+
EventQueue.invokeAndWait(() -> {
113+
if (frame != null) {
114+
frame.dispose();
115+
}
116+
});
117+
}
118+
119+
if (!passed1 || !passed2) {
120+
throw new RuntimeException("ActionEventWhenHitEnterTest FAILED");
121+
}
122+
System.out.println("Test PASSED");
123+
124+
}
125+
126+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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 4117288
27+
* @summary JDKversion1.2beta3-J List's add() method is much slower.
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual ListAddPerfTest
31+
*/
32+
33+
import java.awt.BorderLayout;
34+
import java.awt.Button;
35+
import java.awt.Frame;
36+
import java.awt.List;
37+
import java.awt.event.ActionEvent;
38+
import java.awt.event.ActionListener;
39+
40+
public class ListAddPerfTest {
41+
42+
static Button button;
43+
static List list;
44+
45+
private static final String INSTRUCTIONS = """
46+
It is used to check the performance of List add operation.
47+
48+
Instructions:
49+
Click on the Remove All button.
50+
The list should be cleared.
51+
The button is now named "Add Items".
52+
Click on the "Add Items" button.
53+
800 items should be added to the list.
54+
Notice not only how fast or slow this is, but also how
55+
'smooth' it goes as well i.e. without any flashing.
56+
57+
Press pass if the list performance is acceptable.""";
58+
59+
public static void main(String[] args) throws Exception {
60+
PassFailJFrame.builder()
61+
.title("ListAddPerfTest Instructions")
62+
.instructions(INSTRUCTIONS)
63+
.rows((int)INSTRUCTIONS.lines().count() + 2)
64+
.columns(35)
65+
.testUI(ListAddPerfTest::createTestUI)
66+
.build()
67+
.awaitAndCheck();
68+
}
69+
70+
private static Frame createTestUI() {
71+
Frame frame = new Frame("ListAddPerfTest");
72+
frame.setLayout(new BorderLayout());
73+
74+
button = new Button("Remove All");
75+
button.addActionListener((ActionEvent e) -> {
76+
if (list.getItemCount() > 0) {
77+
list.removeAll();
78+
list.invalidate();
79+
button.setLabel("Add Items");
80+
} else {
81+
for (int i = 0; i < 800; i ++) {
82+
list.add("My number is " + i);
83+
}
84+
button.setLabel("Remove All");
85+
}
86+
});
87+
88+
list = new List(15);
89+
for (int i = 0; i < 800; i ++) {
90+
list.add("My number is " + i);
91+
}
92+
93+
frame.add("North", button);
94+
frame.add("South", list);
95+
96+
frame.pack();
97+
return frame;
98+
}
99+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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 6240151
27+
* @summary XToolkit: Dragging the List scrollbar initiates DnD
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual MouseDraggedOriginatedByScrollBarTest
31+
*/
32+
33+
import java.awt.FlowLayout;
34+
import java.awt.Frame;
35+
import java.awt.List;
36+
import java.awt.event.MouseMotionAdapter;
37+
import java.awt.event.MouseAdapter;
38+
import java.awt.event.MouseEvent;
39+
40+
public class MouseDraggedOriginatedByScrollBarTest {
41+
42+
private static final String INSTRUCTIONS = """
43+
1) Click and drag the scrollbar of the list.
44+
2) Keep dragging till the mouse pointer goes out the scrollbar.
45+
3) The test failed if you see messages about events. The test passed if you don't.""";
46+
47+
public static void main(String[] args) throws Exception {
48+
PassFailJFrame.builder()
49+
.title("MouseDraggedOriginatedByScrollBarTest Instructions")
50+
.instructions(INSTRUCTIONS)
51+
.rows((int) INSTRUCTIONS.lines().count() + 2)
52+
.columns(35)
53+
.testUI(MouseDraggedOriginatedByScrollBarTest::createTestUI)
54+
.logArea()
55+
.build()
56+
.awaitAndCheck();
57+
}
58+
59+
private static Frame createTestUI() {
60+
Frame frame = new Frame();
61+
List list = new List(4, false);
62+
63+
list.add("000");
64+
list.add("111");
65+
list.add("222");
66+
list.add("333");
67+
list.add("444");
68+
list.add("555");
69+
list.add("666");
70+
list.add("777");
71+
list.add("888");
72+
list.add("999");
73+
74+
frame.add(list);
75+
76+
list.addMouseMotionListener(
77+
new MouseMotionAdapter(){
78+
@Override
79+
public void mouseDragged(MouseEvent me){
80+
PassFailJFrame.log(me.toString());
81+
}
82+
});
83+
84+
list.addMouseListener(
85+
new MouseAdapter() {
86+
public void mousePressed(MouseEvent me) {
87+
PassFailJFrame.log(me.toString());
88+
}
89+
90+
public void mouseReleased(MouseEvent me) {
91+
PassFailJFrame.log(me.toString());
92+
}
93+
94+
public void mouseClicked(MouseEvent me){
95+
PassFailJFrame.log(me.toString());
96+
}
97+
});
98+
99+
frame.setLayout(new FlowLayout());
100+
frame.pack();
101+
return frame;
102+
}
103+
}

0 commit comments

Comments
 (0)