Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/FileDialog/MultipleMode/MultipleMode.java
41152 views
1
/*
2
* Copyright (c) 2010, 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 6467204
27
@summary Need to implement "extended" native FileDialog for JFileChooser
28
@author [email protected] area=awt.filedialog
29
@run applet/manual=yesno MultipleMode.html
30
*/
31
32
// Note there is no @ in front of test above. This is so that the
33
// harness will not mistake this file as a test file. It should
34
// only see the html file as a test file. (the harness runs all
35
// valid test files, so it would run this test twice if this file
36
// were valid as well as the html file.)
37
// Also, note the area= after Your Name in the author tag. Here, you
38
// should put which functional area the test falls in. See the
39
// AWT-core home page -> test areas and/or -> AWT team for a list of
40
// areas.
41
// There are several places where ManualYesNoTest appear. It is
42
// recommended that these be changed by a global search and replace,
43
// such as ESC-% in xemacs.
44
45
46
47
/**
48
* MultipleMode.java
49
*
50
* summary:
51
*/
52
53
import java.applet.Applet;
54
import java.awt.*;
55
import java.awt.event.*;
56
import java.io.File;
57
58
59
//Manual tests should run as applet tests if possible because they
60
// get their environments cleaned up, including AWT threads, any
61
// test created threads, and any system resources used by the test
62
// such as file descriptors. (This is normally not a problem as
63
// main tests usually run in a separate VM, however on some platforms
64
// such as the Mac, separate VMs are not possible and non-applet
65
// tests will cause problems). Also, you don't have to worry about
66
// synchronisation stuff in Applet tests the way you do in main
67
// tests...
68
69
70
public class MultipleMode extends Applet
71
{
72
//Declare things used in the test, like buttons and labels here
73
74
public void init()
75
{
76
//Create instructions for the user here, as well as set up
77
// the environment -- set the layout manager, add buttons,
78
// etc.
79
this.setLayout (new BorderLayout ());
80
81
String[] instructions =
82
{
83
" 1. Turn the 'multiple' checkbox off and press the 'open' button ",
84
" 2. Verify that the file dialog doesn't allow the multiple file selection ",
85
" 3. Select any file and close the file dialog ",
86
" 4. The results will be displayed, verify the results ",
87
" 5. Turn the 'multiple' checkbox on and press the 'open' button ",
88
" 6. Verify that the file dialog allows the multiple file selection ",
89
" 7. Select several files and close the file dialog ",
90
" 8. The results will be displayed, verify the results "
91
};
92
Sysout.createDialogWithInstructions( instructions );
93
94
}//End init()
95
96
public void start ()
97
{
98
final Checkbox mode = new Checkbox("multiple", true);
99
Button open = new Button("open");
100
open.addActionListener(new ActionListener() {
101
@Override
102
public void actionPerformed(ActionEvent e) {
103
FileDialog d = new FileDialog((Frame)null);
104
d.setMultipleMode(mode.getState());
105
d.setVisible(true);
106
107
// print the results
108
Sysout.println("DIR:");
109
Sysout.println(d.getDirectory());
110
Sysout.println("FILE:");
111
Sysout.println(d.getFile());
112
Sysout.println("FILES:");
113
File files[] = d.getFiles();
114
for (File f : files) {
115
Sysout.println(String.valueOf(f));
116
}
117
}
118
});
119
120
setLayout(new FlowLayout());
121
add(mode);
122
add(open);
123
124
//Get things going. Request focus, set size, et cetera
125
setSize (200,200);
126
setVisible(true);
127
validate();
128
129
}// start()
130
131
//The rest of this class is the actions which perform the test...
132
133
//Use Sysout.println to communicate with the user NOT System.out!!
134
//Sysout.println ("Something Happened!");
135
136
}// class ManualYesNoTest
137
138
/* Place other classes related to the test after this line */
139
140
141
142
143
144
/****************************************************
145
Standard Test Machinery
146
DO NOT modify anything below -- it's a standard
147
chunk of code whose purpose is to make user
148
interaction uniform, and thereby make it simpler
149
to read and understand someone else's test.
150
****************************************************/
151
152
/**
153
This is part of the standard test machinery.
154
It creates a dialog (with the instructions), and is the interface
155
for sending text messages to the user.
156
To print the instructions, send an array of strings to Sysout.createDialog
157
WithInstructions method. Put one line of instructions per array entry.
158
To display a message for the tester to see, simply call Sysout.println
159
with the string to be displayed.
160
This mimics System.out.println but works within the test harness as well
161
as standalone.
162
*/
163
164
class Sysout
165
{
166
private static TestDialog dialog;
167
private static boolean numbering = false;
168
private static int messageNumber = 0;
169
170
public static void createDialogWithInstructions( String[] instructions )
171
{
172
dialog = new TestDialog( new Frame(), "Instructions" );
173
dialog.printInstructions( instructions );
174
dialog.setVisible(true);
175
println( "Any messages for the tester will display here." );
176
}
177
178
public static void createDialog( )
179
{
180
dialog = new TestDialog( new Frame(), "Instructions" );
181
String[] defInstr = { "Instructions will appear here. ", "" } ;
182
dialog.printInstructions( defInstr );
183
dialog.setVisible(true);
184
println( "Any messages for the tester will display here." );
185
}
186
187
/* Enables message counting for the tester. */
188
public static void enableNumbering(boolean enable){
189
numbering = enable;
190
}
191
192
public static void printInstructions( String[] instructions )
193
{
194
dialog.printInstructions( instructions );
195
}
196
197
198
public static void println( String messageIn )
199
{
200
if (numbering) {
201
messageIn = "" + messageNumber + " " + messageIn;
202
messageNumber++;
203
}
204
dialog.displayMessage( messageIn );
205
}
206
207
}// Sysout class
208
209
/**
210
This is part of the standard test machinery. It provides a place for the
211
test instructions to be displayed, and a place for interactive messages
212
to the user to be displayed.
213
To have the test instructions displayed, see Sysout.
214
To have a message to the user be displayed, see Sysout.
215
Do not call anything in this dialog directly.
216
*/
217
class TestDialog extends Dialog
218
{
219
220
TextArea instructionsText;
221
TextArea messageText;
222
int maxStringLength = 80;
223
224
//DO NOT call this directly, go through Sysout
225
public TestDialog( Frame frame, String name )
226
{
227
super( frame, name );
228
int scrollBoth = TextArea.SCROLLBARS_BOTH;
229
instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
230
add( "North", instructionsText );
231
232
messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
233
add("Center", messageText);
234
235
pack();
236
237
setVisible(true);
238
}// TestDialog()
239
240
//DO NOT call this directly, go through Sysout
241
public void printInstructions( String[] instructions )
242
{
243
//Clear out any current instructions
244
instructionsText.setText( "" );
245
246
//Go down array of instruction strings
247
248
String printStr, remainingStr;
249
for( int i=0; i < instructions.length; i++ )
250
{
251
//chop up each into pieces maxSringLength long
252
remainingStr = instructions[ i ];
253
while( remainingStr.length() > 0 )
254
{
255
//if longer than max then chop off first max chars to print
256
if( remainingStr.length() >= maxStringLength )
257
{
258
//Try to chop on a word boundary
259
int posOfSpace = remainingStr.
260
lastIndexOf( ' ', maxStringLength - 1 );
261
262
if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
263
264
printStr = remainingStr.substring( 0, posOfSpace + 1 );
265
remainingStr = remainingStr.substring( posOfSpace + 1 );
266
}
267
//else just print
268
else
269
{
270
printStr = remainingStr;
271
remainingStr = "";
272
}
273
274
instructionsText.append( printStr + "\n" );
275
276
}// while
277
278
}// for
279
280
}//printInstructions()
281
282
//DO NOT call this directly, go through Sysout
283
public void displayMessage( String messageIn )
284
{
285
messageText.append( messageIn + "\n" );
286
System.out.println(messageIn);
287
}
288
289
}// TestDialog class
290
291