27 import java.awt.peer.FileDialogPeer;
28 import java.io.FilenameFilter;
29 import java.io.IOException;
30 import java.io.ObjectInputStream;
31 import java.io.File;
32 import sun.awt.AWTAccessor;
33
34 /**
35 * The <code>FileDialog</code> class displays a dialog window
36 * from which the user can select a file.
37 * <p>
38 * Since it is a modal dialog, when the application calls
39 * its <code>show</code> method to display the dialog,
40 * it blocks the rest of the application until the user has
41 * chosen a file.
42 *
43 * @see Window#show
44 *
45 * @author Sami Shaio
46 * @author Arthur van Hoff
47 * @since JDK1.0
48 */
49 public class FileDialog extends Dialog {
50
51 /**
52 * This constant value indicates that the purpose of the file
53 * dialog window is to locate a file from which to read.
54 */
55 public static final int LOAD = 0;
56
57 /**
58 * This constant value indicates that the purpose of the file
59 * dialog window is to locate a file to which to write.
60 */
61 public static final int SAVE = 1;
62
63 /*
64 * There are two <code>FileDialog</code> modes: <code>LOAD</code> and
65 * <code>SAVE</code>.
66 * This integer will represent one or the other.
67 * If the mode is not specified it will default to <code>LOAD</code>.
159 public boolean isMultipleMode(FileDialog fileDialog) {
160 synchronized (fileDialog.getObjectLock()) {
161 return fileDialog.multipleMode;
162 }
163 }
164 });
165 }
166
167 /**
168 * Initialize JNI field and method IDs for fields that may be
169 accessed from C.
170 */
171 private static native void initIDs();
172
173 /**
174 * Creates a file dialog for loading a file. The title of the
175 * file dialog is initially empty. This is a convenience method for
176 * <code>FileDialog(parent, "", LOAD)</code>.
177 *
178 * @param parent the owner of the dialog
179 * @since JDK1.1
180 */
181 public FileDialog(Frame parent) {
182 this(parent, "", LOAD);
183 }
184
185 /**
186 * Creates a file dialog window with the specified title for loading
187 * a file. The files shown are those in the current directory.
188 * This is a convenience method for
189 * <code>FileDialog(parent, title, LOAD)</code>.
190 *
191 * @param parent the owner of the dialog
192 * @param title the title of the dialog
193 */
194 public FileDialog(Frame parent, String title) {
195 this(parent, title, LOAD);
196 }
197
198 /**
199 * Creates a file dialog window with the specified title for loading
336 * @see java.awt.FileDialog#SAVE
337 * @see java.awt.FileDialog#setMode
338 */
339 public int getMode() {
340 return mode;
341 }
342
343 /**
344 * Sets the mode of the file dialog. If <code>mode</code> is not
345 * a legal value, an exception will be thrown and <code>mode</code>
346 * will not be set.
347 *
348 * @param mode the mode for this file dialog, either
349 * <code>FileDialog.LOAD</code> or
350 * <code>FileDialog.SAVE</code>
351 * @see java.awt.FileDialog#LOAD
352 * @see java.awt.FileDialog#SAVE
353 * @see java.awt.FileDialog#getMode
354 * @exception IllegalArgumentException if an illegal file
355 * dialog mode is supplied
356 * @since JDK1.1
357 */
358 public void setMode(int mode) {
359 switch (mode) {
360 case LOAD:
361 case SAVE:
362 this.mode = mode;
363 break;
364 default:
365 throw new IllegalArgumentException("illegal file dialog mode");
366 }
367 }
368
369 /**
370 * Gets the directory of this file dialog.
371 *
372 * @return the (potentially <code>null</code> or invalid)
373 * directory of this <code>FileDialog</code>
374 * @see java.awt.FileDialog#setDirectory
375 */
376 public String getDirectory() {
|
27 import java.awt.peer.FileDialogPeer;
28 import java.io.FilenameFilter;
29 import java.io.IOException;
30 import java.io.ObjectInputStream;
31 import java.io.File;
32 import sun.awt.AWTAccessor;
33
34 /**
35 * The <code>FileDialog</code> class displays a dialog window
36 * from which the user can select a file.
37 * <p>
38 * Since it is a modal dialog, when the application calls
39 * its <code>show</code> method to display the dialog,
40 * it blocks the rest of the application until the user has
41 * chosen a file.
42 *
43 * @see Window#show
44 *
45 * @author Sami Shaio
46 * @author Arthur van Hoff
47 * @since 1.0
48 */
49 public class FileDialog extends Dialog {
50
51 /**
52 * This constant value indicates that the purpose of the file
53 * dialog window is to locate a file from which to read.
54 */
55 public static final int LOAD = 0;
56
57 /**
58 * This constant value indicates that the purpose of the file
59 * dialog window is to locate a file to which to write.
60 */
61 public static final int SAVE = 1;
62
63 /*
64 * There are two <code>FileDialog</code> modes: <code>LOAD</code> and
65 * <code>SAVE</code>.
66 * This integer will represent one or the other.
67 * If the mode is not specified it will default to <code>LOAD</code>.
159 public boolean isMultipleMode(FileDialog fileDialog) {
160 synchronized (fileDialog.getObjectLock()) {
161 return fileDialog.multipleMode;
162 }
163 }
164 });
165 }
166
167 /**
168 * Initialize JNI field and method IDs for fields that may be
169 accessed from C.
170 */
171 private static native void initIDs();
172
173 /**
174 * Creates a file dialog for loading a file. The title of the
175 * file dialog is initially empty. This is a convenience method for
176 * <code>FileDialog(parent, "", LOAD)</code>.
177 *
178 * @param parent the owner of the dialog
179 * @since 1.1
180 */
181 public FileDialog(Frame parent) {
182 this(parent, "", LOAD);
183 }
184
185 /**
186 * Creates a file dialog window with the specified title for loading
187 * a file. The files shown are those in the current directory.
188 * This is a convenience method for
189 * <code>FileDialog(parent, title, LOAD)</code>.
190 *
191 * @param parent the owner of the dialog
192 * @param title the title of the dialog
193 */
194 public FileDialog(Frame parent, String title) {
195 this(parent, title, LOAD);
196 }
197
198 /**
199 * Creates a file dialog window with the specified title for loading
336 * @see java.awt.FileDialog#SAVE
337 * @see java.awt.FileDialog#setMode
338 */
339 public int getMode() {
340 return mode;
341 }
342
343 /**
344 * Sets the mode of the file dialog. If <code>mode</code> is not
345 * a legal value, an exception will be thrown and <code>mode</code>
346 * will not be set.
347 *
348 * @param mode the mode for this file dialog, either
349 * <code>FileDialog.LOAD</code> or
350 * <code>FileDialog.SAVE</code>
351 * @see java.awt.FileDialog#LOAD
352 * @see java.awt.FileDialog#SAVE
353 * @see java.awt.FileDialog#getMode
354 * @exception IllegalArgumentException if an illegal file
355 * dialog mode is supplied
356 * @since 1.1
357 */
358 public void setMode(int mode) {
359 switch (mode) {
360 case LOAD:
361 case SAVE:
362 this.mode = mode;
363 break;
364 default:
365 throw new IllegalArgumentException("illegal file dialog mode");
366 }
367 }
368
369 /**
370 * Gets the directory of this file dialog.
371 *
372 * @return the (potentially <code>null</code> or invalid)
373 * directory of this <code>FileDialog</code>
374 * @see java.awt.FileDialog#setDirectory
375 */
376 public String getDirectory() {
|