Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JComboBox/8033069/bug8033069NoScrollBar.java
41153 views
1
/*
2
* Copyright (c) 2015, 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
import java.awt.AWTException;
25
import java.awt.Dimension;
26
import java.awt.GridLayout;
27
import java.awt.Point;
28
import java.awt.Robot;
29
import java.awt.event.InputEvent;
30
import javax.swing.JComboBox;
31
import javax.swing.JFrame;
32
import javax.swing.JPanel;
33
import javax.swing.SwingUtilities;
34
import javax.swing.UIManager;
35
import javax.swing.UIManager.LookAndFeelInfo;
36
import javax.swing.UnsupportedLookAndFeelException;
37
38
/*
39
* @test
40
* @key headful
41
* @bug 8033069
42
* @summary Checks that JComboBox popup does not close when mouse wheel is
43
* rotated over combo box and over its popup. The case where popup
44
* has no scroll bar.
45
* @library ../../regtesthelpers
46
* @build Util
47
* @run main bug8033069NoScrollBar
48
*/
49
public class bug8033069NoScrollBar {
50
51
private static final String[] NO_SCROLL_ITEMS = new String[] {
52
"A", "B", "C", "D", "E", "F"
53
};
54
55
private final Robot robot;
56
57
private final String[] items;
58
59
private JFrame frame;
60
private JComboBox cb1;
61
private JComboBox cb2;
62
63
private volatile Point p;
64
private volatile Dimension d;
65
66
public static void main(String[] args) throws Exception {
67
iterateLookAndFeels(new bug8033069NoScrollBar(NO_SCROLL_ITEMS));
68
}
69
70
protected static void iterateLookAndFeels(final bug8033069NoScrollBar test) throws Exception {
71
LookAndFeelInfo[] lafInfo = UIManager.getInstalledLookAndFeels();
72
for (LookAndFeelInfo info : lafInfo) {
73
try {
74
UIManager.setLookAndFeel(info.getClassName());
75
System.out.println("Look and Feel: " + info.getClassName());
76
test.runTest();
77
} catch (UnsupportedLookAndFeelException e) {
78
System.out.println("Skipping unsupported LaF: " + info);
79
}
80
}
81
}
82
83
public bug8033069NoScrollBar(String[] items) throws AWTException {
84
this.items = items;
85
86
robot = new Robot();
87
robot.setAutoDelay(200);
88
}
89
90
private void setupUI() {
91
frame = new JFrame();
92
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
93
94
cb1 = new JComboBox<>(items);
95
cb2 = new JComboBox<>(items);
96
JPanel panel = new JPanel(new GridLayout(1, 2));
97
panel.add(cb1);
98
panel.add(cb2);
99
100
frame.add(panel);
101
102
frame.pack();
103
frame.setLocationRelativeTo(null);
104
frame.setVisible(true);
105
}
106
107
private void disposeUI() {
108
if (frame != null) {
109
frame.dispose();
110
}
111
}
112
113
public void runTest() throws Exception {
114
try {
115
SwingUtilities.invokeAndWait(this::setupUI);
116
117
robot.waitForIdle();
118
assertFalse("cb1 popup is visible",
119
Util.invokeOnEDT(cb1::isPopupVisible));
120
121
// Move mouse pointer to the center of the fist combo box
122
SwingUtilities.invokeAndWait(() -> {
123
p = cb1.getLocationOnScreen();
124
d = cb1.getSize();
125
});
126
127
robot.mouseMove(p.x + d.width / 2, p.y + d.height / 2);
128
// Click it to open popup
129
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
130
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
131
132
robot.waitForIdle();
133
assertTrue("cb1 popup is not visible",
134
Util.invokeOnEDT(cb1::isPopupVisible));
135
136
robot.mouseWheel(1);
137
robot.waitForIdle();
138
assertTrue("cb1 popup is not visible after mouse wheel up on combo box",
139
Util.invokeOnEDT(cb1::isPopupVisible));
140
141
robot.mouseWheel(-1);
142
robot.waitForIdle();
143
assertTrue("cb1 popup is not visible after mouse wheel down on combo box",
144
Util.invokeOnEDT(cb1::isPopupVisible));
145
146
// Move mouse down on the popup
147
robot.mouseMove(p.x + d.width / 2, p.y + d.height * 3);
148
149
robot.mouseWheel(1);
150
robot.waitForIdle();
151
assertTrue("cb1 popup is not visible after mouse wheel up on popup",
152
Util.invokeOnEDT(cb1::isPopupVisible));
153
154
robot.mouseWheel(-1);
155
robot.waitForIdle();
156
assertTrue("cb1 popup is not visible after mouse wheel down on popup",
157
Util.invokeOnEDT(cb1::isPopupVisible));
158
159
160
// Move mouse pointer to the center of the second combo box
161
SwingUtilities.invokeAndWait(() -> {
162
p = cb2.getLocationOnScreen();
163
d = cb2.getSize();
164
});
165
166
robot.mouseMove(p.x + d.width / 2, p.y + d.height / 2);
167
168
robot.mouseWheel(1);
169
robot.waitForIdle();
170
assertFalse("cb1 popup is visible after mouse wheel up on cb2",
171
Util.invokeOnEDT(cb1::isPopupVisible));
172
} finally {
173
SwingUtilities.invokeAndWait(this::disposeUI);
174
}
175
176
System.out.println("Test passed");
177
}
178
179
private static void assertTrue(String message, boolean value) {
180
assertEquals(message, true, value);
181
}
182
183
private static void assertFalse(String message, boolean value) {
184
assertEquals(message, false, value);
185
}
186
187
private static void assertEquals(String message, boolean expected, boolean actual) {
188
if (expected != actual) {
189
throw new RuntimeException(message);
190
}
191
}
192
}
193
194