Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JComboBox/4199622/bug4199622.java
41154 views
1
/*
2
* Copyright (c) 2013, 2018, 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
@key headful
27
@bug 4199622
28
@requires (os.family == "windows")
29
@summary RFE: JComboBox shouldn't send ActionEvents for keyboard navigation
30
@library /test/lib
31
@modules java.desktop/com.sun.java.swing.plaf.windows
32
@build jdk.test.lib.Platform
33
@run main bug4199622
34
*/
35
36
import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
37
import jdk.test.lib.Platform;
38
39
import javax.swing.*;
40
import javax.swing.plaf.metal.MetalLookAndFeel;
41
import java.awt.*;
42
import java.awt.event.ActionEvent;
43
import java.awt.event.ActionListener;
44
import java.awt.event.KeyEvent;
45
import java.lang.reflect.InvocationTargetException;
46
47
public class bug4199622 extends JFrame implements ActionListener {
48
49
static final int nElems = 20;
50
static JComboBox<String> cb = null;
51
52
bug4199622(LookAndFeel laf) {
53
super();
54
55
try {
56
UIManager.setLookAndFeel(laf);
57
} catch (UnsupportedLookAndFeelException e) {
58
throw new RuntimeException("Test failed", e);
59
}
60
61
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
62
cb = new JComboBox<>();
63
for (int i = 0; i < nElems; i++) {
64
cb.addItem(String.valueOf(i + 1));
65
}
66
cb.addActionListener(this);
67
add(cb);
68
69
setSize(300, 300);
70
pack();
71
setLocationRelativeTo(null);
72
}
73
74
@Override
75
public void actionPerformed(ActionEvent e) {
76
if (UIManager.getBoolean("ComboBox.noActionOnKeyNavigation") && cb.isPopupVisible()) {
77
throw new RuntimeException("Test failed. actionPerformed generated");
78
}
79
}
80
81
static Robot robot = null;
82
83
static void doTest() {
84
if (robot == null) {
85
try {
86
robot = new Robot();
87
robot.setAutoDelay(100);
88
} catch (AWTException e) {
89
throw new RuntimeException("Can't create robot. Test failed", e);
90
}
91
}
92
93
robot.waitForIdle();
94
95
doActualTest();
96
97
try {
98
SwingUtilities.invokeAndWait(new Runnable() {
99
@Override
100
public void run() {
101
cb.hidePopup();
102
cb.setEditable(true);
103
cb.updateUI();
104
}
105
});
106
} catch (InterruptedException e) {
107
throw new RuntimeException("Test failed", e);
108
} catch (InvocationTargetException e) {
109
throw new RuntimeException("Test failed", e);
110
}
111
112
robot.waitForIdle();
113
doActualTest();
114
}
115
116
static void doActualTest() {
117
UIManager.put("ComboBox.noActionOnKeyNavigation", true);
118
doTestUpDown();
119
UIManager.put("ComboBox.noActionOnKeyNavigation", false);
120
doTestUpDown();
121
122
UIManager.put("ComboBox.noActionOnKeyNavigation", true);
123
doTestPgUpDown();
124
UIManager.put("ComboBox.noActionOnKeyNavigation", false);
125
doTestPgUpDown();
126
127
UIManager.put("ComboBox.noActionOnKeyNavigation", true);
128
doTestHomeEnd();
129
UIManager.put("ComboBox.noActionOnKeyNavigation", false);
130
doTestHomeEnd();
131
}
132
133
static void doTestHomeEnd() {
134
try {
135
SwingUtilities.invokeAndWait(new Runnable() {
136
@Override
137
public void run() {
138
cb.hidePopup();
139
cb.setSelectedIndex(0);
140
}
141
});
142
} catch (InterruptedException e) {
143
throw new RuntimeException("Test failed", e);
144
} catch (InvocationTargetException e) {
145
throw new RuntimeException("Test failed", e);
146
}
147
robot.waitForIdle();
148
149
robot.keyPress(KeyEvent.VK_END);
150
robot.keyRelease(KeyEvent.VK_END);
151
robot.waitForIdle();
152
robot.keyPress(KeyEvent.VK_HOME);
153
robot.keyRelease(KeyEvent.VK_HOME);
154
robot.waitForIdle();
155
}
156
157
static void doTestUpDown() {
158
try {
159
SwingUtilities.invokeAndWait(new Runnable() {
160
@Override
161
public void run() {
162
cb.hidePopup();
163
cb.setSelectedIndex(0);
164
}
165
});
166
} catch (InterruptedException e) {
167
throw new RuntimeException("Test failed", e);
168
} catch (InvocationTargetException e) {
169
throw new RuntimeException("Test failed", e);
170
}
171
robot.waitForIdle();
172
173
for (int i = 0; i < nElems; i++) {
174
robot.keyPress(KeyEvent.VK_DOWN);
175
robot.keyRelease(KeyEvent.VK_DOWN);
176
robot.waitForIdle();
177
}
178
179
for (int i = 0; i < nElems; i++) {
180
robot.keyPress(KeyEvent.VK_UP);
181
robot.keyRelease(KeyEvent.VK_UP);
182
robot.waitForIdle();
183
}
184
}
185
186
static void doTestPgUpDown() {
187
try {
188
SwingUtilities.invokeAndWait(new Runnable() {
189
@Override
190
public void run() {
191
cb.hidePopup();
192
cb.setSelectedIndex(0);
193
}
194
});
195
} catch (InterruptedException e) {
196
throw new RuntimeException("Test failed", e);
197
} catch (InvocationTargetException e) {
198
throw new RuntimeException("Test failed", e);
199
}
200
robot.waitForIdle();
201
202
int listHeight = cb.getMaximumRowCount();
203
for (int i = 0; i < nElems; i += listHeight) {
204
robot.keyPress(KeyEvent.VK_PAGE_DOWN);
205
robot.keyRelease(KeyEvent.VK_PAGE_DOWN);
206
robot.waitForIdle();
207
}
208
209
for (int i = 0; i < nElems; i += listHeight) {
210
robot.keyPress(KeyEvent.VK_PAGE_UP);
211
robot.keyRelease(KeyEvent.VK_PAGE_UP);
212
robot.waitForIdle();
213
}
214
}
215
216
public static void main(String[] args) {
217
try {
218
SwingUtilities.invokeAndWait(new Runnable() {
219
@Override
220
public void run() {
221
bug4199622 test = new bug4199622(new MetalLookAndFeel());
222
test.setVisible(true);
223
}
224
});
225
} catch (InterruptedException e) {
226
throw new RuntimeException("Test failed", e);
227
} catch (InvocationTargetException e) {
228
throw new RuntimeException("Test failed", e);
229
}
230
doTest();
231
232
if (Platform.isWindows()) {
233
try {
234
SwingUtilities.invokeAndWait(new Runnable() {
235
@Override
236
public void run() {
237
bug4199622 test = new bug4199622(new WindowsLookAndFeel());
238
test.setVisible(true);
239
}
240
});
241
} catch (InterruptedException e) {
242
throw new RuntimeException("Test failed", e);
243
} catch (InvocationTargetException e) {
244
throw new RuntimeException("Test failed", e);
245
}
246
doTest();
247
}
248
}
249
}
250
251