Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JComboBox/6236162/bug6236162.java
41154 views
1
/*
2
* Copyright (c) 2013, 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 6236162
28
* @summary Checks that there is no an inconsistence in combo box
29
* behavior when user points an item in combo popup
30
* by mouse and then uses UP/DOWN keys.
31
* @run main bug6236162
32
*/
33
34
import javax.swing.*;
35
import javax.swing.plaf.basic.*;
36
import javax.swing.plaf.metal.MetalComboBoxUI;
37
import java.awt.*;
38
import java.awt.event.KeyEvent;
39
40
public class bug6236162 {
41
private static JFrame frame;
42
private static JComboBox combo;
43
private static MyComboUI comboUI;
44
private static Robot robot;
45
46
public static void main(String[] args) throws Exception {
47
robot = new Robot();
48
robot.setAutoDelay(100);
49
try {
50
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
51
SwingUtilities.invokeAndWait(new Runnable() {
52
public void run() {
53
createAndShowGUI();
54
}
55
});
56
robot.waitForIdle();
57
robot.delay(1000);
58
test();
59
System.out.println("Test passed");
60
} finally {
61
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
62
}
63
}
64
65
private static void createAndShowGUI() {
66
frame = new JFrame("bug6236162");
67
68
combo = new JComboBox(new String[]{"one", "two", "three", "four", "five"});
69
combo.setEditable(true);
70
comboUI = new MyComboUI();
71
combo.setUI(comboUI);
72
combo.setSelectedIndex(3);
73
frame.getContentPane().add(combo);
74
75
frame.pack();
76
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
77
frame.setLocationRelativeTo(null);
78
frame.setVisible(true);
79
frame.toFront();
80
}
81
82
private static void test() throws AWTException {
83
84
// Open popup menu
85
robot.keyPress(KeyEvent.VK_DOWN);
86
robot.keyRelease(KeyEvent.VK_DOWN);
87
88
// Move mouse to the first popup menu item
89
robot.waitForIdle();
90
Point p = combo.getLocationOnScreen();
91
Dimension size = combo.getSize();
92
p.x += size.width / 2;
93
p.y += size.height;
94
float dy = 1;
95
robot.mouseMove(p.x, p.y - 5);
96
for (int i=1; i <= 10; i++) {
97
robot.mouseMove((int)(p.x), (int)(p.y - 5 + dy*i));
98
}
99
100
// Select the second popup menu item
101
robot.waitForIdle();
102
robot.keyPress(KeyEvent.VK_DOWN);
103
robot.keyRelease(KeyEvent.VK_DOWN);
104
105
robot.waitForIdle();
106
JList list = comboUI.getComboPopup().getList();
107
if (list.getSelectedIndex() != 1) {
108
throw new RuntimeException("There is an inconsistence in combo box " +
109
"behavior when user points an item in combo popup " +
110
"by mouse and then uses UP/DOWN keys.");
111
}
112
}
113
114
115
// Gives access to BasicComboBoxUI.popup field
116
private static class MyComboUI extends MetalComboBoxUI {
117
public ComboPopup getComboPopup() {
118
return popup;
119
}
120
}
121
}
122
123