Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JFileChooser/JFileChooserCombolistSelection/JFileChooserCombolistSelection.java
41153 views
1
/*
2
* Copyright (c) 2015, 2020, 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 4674075 8233584
27
@summary Checks if keyboard traversal of JFileChooser's "Look in" combobox is broken
28
@modules java.desktop
29
@requires (os.family == "windows")
30
@key headful
31
@run main/manual JFileChooserCombolistSelection
32
*/
33
import java.awt.Panel;
34
import java.awt.TextArea;
35
import java.awt.event.ActionEvent;
36
import java.awt.event.ActionListener;
37
import javax.swing.JFileChooser;
38
import javax.swing.SwingUtilities;
39
import javax.swing.UIManager;
40
import javax.swing.JFrame;
41
import javax.swing.JDialog;
42
import javax.swing.JButton;
43
44
public class JFileChooserCombolistSelection {
45
46
private static boolean theTestPassed;
47
private static boolean testGeneratedInterrupt;
48
private static Thread mainThread;
49
private static int sleepTime = 90000;
50
public static JFileChooser fileChooser;
51
52
private static void init() throws Exception {
53
54
SwingUtilities.invokeAndWait(new Runnable() {
55
@Override
56
public void run() {
57
String[] instructions
58
= {
59
"Activate the \"Look in\" combobox's popup by "
60
+"clicking on its arrow button."
61
+ "Then navigate in it using keyboard "
62
+"(ie UP and DOWN arrow keys)."
63
+ "When navigating, take a notice, "
64
+"if the contents of the file list changes."
65
+ "If yes, then press \"Fail\", "
66
+"otherwise press \"Passed\"."
67
};
68
Sysout.createDialogWithInstructions(instructions);
69
Sysout.printInstructions(instructions);
70
}
71
});
72
}
73
74
/**
75
* ***************************************************
76
* Standard Test Machinery Section DO NOT modify anything in this section --
77
* it's a standard chunk of code which has all of the synchronisation
78
* necessary for the test harness. By keeping it the same in all tests, it
79
* is easier to read and understand someone else's test, as well as insuring
80
* that all tests behave correctly with the test harness. There is a section
81
* following this for test-defined classes
82
*/
83
public static void main(String args[]) throws Exception {
84
String osName = System.getProperty("os.name");
85
if(!osName.toLowerCase().contains("win")) {
86
System.out.println("The test was skipped because it is sensible only for Windows.");
87
return;
88
}
89
try {
90
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
91
} catch(Exception ex) {
92
return;
93
}
94
mainThread = Thread.currentThread();
95
try {
96
init();
97
} catch (Exception ex) {
98
return;
99
}
100
try {
101
mainThread.sleep(sleepTime);
102
} catch (InterruptedException ex) {
103
Sysout.dispose();
104
if (!theTestPassed && testGeneratedInterrupt) {
105
throw new RuntimeException("Test Failed");
106
}
107
}
108
if (!testGeneratedInterrupt) {
109
Sysout.dispose();
110
throw new RuntimeException("Test Failed");
111
}
112
}
113
114
public static synchronized void pass() {
115
theTestPassed = true;
116
testGeneratedInterrupt = true;
117
mainThread.interrupt();
118
}
119
120
public static synchronized void fail() {
121
theTestPassed = false;
122
testGeneratedInterrupt = true;
123
mainThread.interrupt();
124
}
125
}
126
127
/**
128
* This is part of the standard test machinery. It creates a dialog (with the
129
* instructions), and is the interface for sending text messages to the user. To
130
* print the instructions, send an array of strings to Sysout.createDialog
131
* WithInstructions method. Put one line of instructions per array entry. To
132
* display a message for the tester to see, simply call Sysout.println with the
133
* string to be displayed. This mimics System.out.println but works within the
134
* test harness as well as standalone.
135
*/
136
class Sysout {
137
138
private static TestDialog dialog;
139
private static JFrame frame;
140
141
public static void createDialogWithInstructions(String[] instructions) {
142
frame = new JFrame();
143
dialog = new TestDialog(frame, "Instructions");
144
dialog.printInstructions(instructions);
145
dialog.setVisible(true);
146
println("Any messages for the tester will display here.");
147
}
148
149
public static void printInstructions(String[] instructions) {
150
dialog.printInstructions(instructions);
151
}
152
153
public static void println(String messageIn) {
154
dialog.displayMessage(messageIn);
155
}
156
157
public static void dispose() {
158
Sysout.println("Shutting down the Java process..");
159
if(JFileChooserCombolistSelection.fileChooser != null) {
160
JFileChooserCombolistSelection.fileChooser.cancelSelection();
161
}
162
frame.dispose();
163
dialog.dispose();
164
}
165
}
166
167
/**
168
* This is part of the standard test machinery. It provides a place for the test
169
* instructions to be displayed, and a place for interactive messages to the
170
* user to be displayed. To have the test instructions displayed, see Sysout. To
171
* have a message to the user be displayed, see Sysout. Do not call anything in
172
* this dialog directly.
173
*/
174
class TestDialog extends JDialog {
175
176
private TextArea instructionsText;
177
private TextArea messageText;
178
private int maxStringLength = 80;
179
private Panel buttonP = new Panel();
180
private JButton run = new JButton("Run");
181
private JButton passB = new JButton("Pass");
182
private JButton failB = new JButton("Fail");
183
184
public TestDialog(JFrame frame, String name) {
185
super(frame, name);
186
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
187
int scrollBoth = TextArea.SCROLLBARS_BOTH;
188
instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);
189
add("North", instructionsText);
190
191
messageText = new TextArea("", 5, maxStringLength, scrollBoth);
192
add("Center", messageText);
193
194
buttonP.add("East", run);
195
buttonP.add("East", passB);
196
buttonP.add("West", failB);
197
passB.setEnabled(false);
198
failB.setEnabled(false);
199
add("South", buttonP);
200
201
run.addActionListener(new ActionListener() {
202
203
@Override
204
public void actionPerformed(ActionEvent ae) {
205
JFileChooserCombolistSelection.fileChooser = new JFileChooser();
206
JFileChooserCombolistSelection.fileChooser.showOpenDialog(null);
207
passB.setEnabled(true);
208
failB.setEnabled(true);
209
}
210
});
211
212
passB.addActionListener(new ActionListener() {
213
214
@Override
215
public void actionPerformed(ActionEvent ae) {
216
JFileChooserCombolistSelection.pass();
217
}
218
});
219
220
failB.addActionListener(new ActionListener() {
221
222
@Override
223
public void actionPerformed(ActionEvent ae) {
224
JFileChooserCombolistSelection.fail();
225
}
226
});
227
pack();
228
229
setVisible(true);
230
}
231
232
public void printInstructions(String[] instructions) {
233
instructionsText.setText("");
234
235
String printStr, remainingStr;
236
for (String instruction : instructions) {
237
remainingStr = instruction;
238
while (remainingStr.length() > 0) {
239
if (remainingStr.length() >= maxStringLength) {
240
int posOfSpace = remainingStr.
241
lastIndexOf(' ', maxStringLength - 1);
242
243
if (posOfSpace <= 0) {
244
posOfSpace = maxStringLength - 1;
245
}
246
247
printStr = remainingStr.substring(0, posOfSpace + 1);
248
remainingStr = remainingStr.substring(posOfSpace + 1);
249
} else {
250
printStr = remainingStr;
251
remainingStr = "";
252
}
253
instructionsText.append(printStr + "\n");
254
}
255
}
256
257
}
258
259
public void displayMessage(String messageIn) {
260
messageText.append(messageIn + "\n");
261
}
262
}
263
264