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