Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JComboBox/8015300/Test8015300.java
41153 views
1
/*
2
* Copyright (c) 2013, 2017, 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 com.sun.java.swing.plaf.windows.WindowsComboBoxUI.WindowsComboBoxEditor;
25
import java.awt.Toolkit;
26
import java.awt.event.ItemEvent;
27
import java.awt.event.ItemListener;
28
import javax.swing.ComboBoxEditor;
29
import javax.swing.JComboBox;
30
import javax.swing.JFrame;
31
import javax.swing.JTextField;
32
import javax.swing.UIManager;
33
34
import static javax.swing.SwingUtilities.invokeAndWait;
35
import static javax.swing.SwingUtilities.windowForComponent;
36
import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE;
37
38
/*
39
* @test
40
* @key headful
41
* @bug 8015300
42
@requires (os.family == "windows")
43
* @summary Tests that editable combobox selects all text.
44
* @author Sergey Malenkov
45
* @library /lib/client/
46
* @modules java.desktop/com.sun.java.swing.plaf.windows
47
* @build ExtendedRobot
48
* @run main Test8015300
49
*/
50
51
public class Test8015300 {
52
private static final ExtendedRobot robot = createRobot();
53
private static final String[] ITEMS = {
54
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
55
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
56
57
private static JComboBox<String> combo;
58
59
public static void main(String[] args) throws Exception {
60
UIManager.LookAndFeelInfo[] array = UIManager.getInstalledLookAndFeels();
61
for (UIManager.LookAndFeelInfo info : array) {
62
UIManager.setLookAndFeel(info.getClassName());
63
System.err.println("L&F: " + info.getName());
64
invokeAndWait(new Runnable() {
65
@Override
66
public void run() {
67
combo = new JComboBox<>(ITEMS);
68
combo.addItemListener(new ItemListener() {
69
@Override
70
public void itemStateChanged(ItemEvent event) {
71
if (ItemEvent.SELECTED == event.getStateChange() && combo.isEditable()) {
72
ComboBoxEditor editor = combo.getEditor();
73
Object component = editor.getEditorComponent();
74
if (component instanceof JTextField) {
75
JTextField text = (JTextField) component;
76
boolean selected = null != text.getSelectedText();
77
78
StringBuilder sb = new StringBuilder();
79
sb.append(" - ").append(combo.getSelectedIndex());
80
sb.append(": ").append(event.getItem());
81
if (selected) {
82
sb.append("; selected");
83
}
84
System.err.println(sb);
85
if ((editor instanceof WindowsComboBoxEditor) == (null == text.getSelectedText())) {
86
throw new Error("unexpected state of text selection");
87
}
88
}
89
}
90
}
91
});
92
JFrame frame = new JFrame(getClass().getSimpleName());
93
frame.add(combo);
94
frame.pack();
95
frame.setLocationRelativeTo(null);
96
frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
97
frame.setVisible(true);
98
}
99
});
100
for (int i = 0; i < ITEMS.length; ++i) {
101
select(i, true);
102
select(1, false);
103
}
104
invokeAndWait(new Runnable() {
105
@Override
106
public void run() {
107
windowForComponent(combo).dispose();
108
}
109
});
110
}
111
}
112
113
private static void select(final int index, final boolean editable) throws Exception {
114
invokeAndWait(new Runnable() {
115
@Override
116
public void run() {
117
combo.setEditable(editable);
118
combo.setSelectedIndex(index);
119
}
120
});
121
robot.waitForIdle(50);
122
}
123
private static ExtendedRobot createRobot() {
124
try {
125
ExtendedRobot robot = new ExtendedRobot();
126
return robot;
127
}catch(Exception ex) {
128
ex.printStackTrace();
129
throw new Error("Unexpected Failure");
130
}
131
}
132
}
133
134