FileDialogpublic class FileDialog extends Dialog The FileDialog class displays a dialog window
from which the user can select a file.
Since it is a modal dialog, when the application calls
its show method to display the dialog,
it blocks the rest of the application until the user has
chosen a file. |
Fields Summary |
---|
public static final int | LOADThis constant value indicates that the purpose of the file
dialog window is to locate a file from which to read. | public static final int | SAVEThis constant value indicates that the purpose of the file
dialog window is to locate a file to which to write. | int | mode | String | dir | String | file | FilenameFilter | filter | private static final String | base | private static int | nameCounter | private static final long | serialVersionUID |
Constructors Summary |
---|
public FileDialog(Frame parent)Creates a file dialog for loading a file. The title of the
file dialog is initially empty. This is a convenience method for
FileDialog(parent, "", LOAD) .
/* ensure that the necessary native libraries are loaded */
Toolkit.loadLibraries();
if (!GraphicsEnvironment.isHeadless()) {
initIDs();
}
this(parent, "", LOAD);
| public FileDialog(Frame parent, String title)Creates a file dialog window with the specified title for loading
a file. The files shown are those in the current directory.
This is a convenience method for
FileDialog(parent, title, LOAD) .
this(parent, title, LOAD);
| public FileDialog(Frame parent, String title, int mode)Creates a file dialog window with the specified title for loading
or saving a file.
If the value of mode is LOAD , then the
file dialog is finding a file to read, and the files shown are those
in the current directory. If the value of
mode is SAVE , the file dialog is finding
a place to write a file.
super(parent, title, true);
this.setMode(mode);
setLayout(null);
| public FileDialog(Dialog parent)Creates a file dialog for loading a file. The title of the
file dialog is initially empty. This is a convenience method for
FileDialog(parent, "", LOAD) .
this(parent, "", LOAD);
| public FileDialog(Dialog parent, String title)Creates a file dialog window with the specified title for loading
a file. The files shown are those in the current directory.
This is a convenience method for
FileDialog(parent, title, LOAD) .
this(parent, title, LOAD);
| public FileDialog(Dialog parent, String title, int mode)Creates a file dialog window with the specified title for loading
or saving a file.
If the value of mode is LOAD , then the
file dialog is finding a file to read, and the files shown are those
in the current directory. If the value of
mode is SAVE , the file dialog is finding
a place to write a file.
super(parent, title, true);
this.setMode(mode);
setLayout(null);
|
Methods Summary |
---|
public void | addNotify()Creates the file dialog's peer. The peer allows us to change the look
of the file dialog without changing its functionality.
synchronized(getTreeLock()) {
if (parent != null && parent.getPeer() == null) {
parent.addNotify();
}
if (peer == null)
peer = getToolkit().createFileDialog(this);
super.addNotify();
}
| java.lang.String | constructComponentName()Constructs a name for this component. Called by getName()
when the name is null .
synchronized (getClass()) {
return base + nameCounter++;
}
| public java.lang.String | getDirectory()Gets the directory of this file dialog.
return dir;
| public java.lang.String | getFile()Gets the selected file of this file dialog. If the user
selected CANCEL , the returned file is null .
return file;
| public java.io.FilenameFilter | getFilenameFilter()Determines this file dialog's filename filter. A filename filter
allows the user to specify which files appear in the file dialog
window. Filename filters do not function in Sun's reference
implementation for Microsoft Windows.
return filter;
| public int | getMode()Indicates whether this file dialog box is for loading from a file
or for saving to a file.
return mode;
| private static native void | initIDs()Initialize JNI field and method IDs for fields that may be
accessed from C.
| protected java.lang.String | paramString()Returns a string representing the state of this FileDialog
window. This method is intended to be used only for debugging purposes,
and the content and format of the returned string may vary between
implementations. The returned string may be empty but may not be
null .
String str = super.paramString();
str += ",dir= " + dir;
str += ",file= " + file;
return str + ((mode == LOAD) ? ",load" : ",save");
| boolean | postsOldMouseEvents()
return false;
| private void | readObject(java.io.ObjectInputStream s)Reads the ObjectInputStream and performs
a backwards compatibility check by converting
either a dir or a file
equal to an empty string to null .
s.defaultReadObject();
// 1.1 Compatibility: "" is not converted to null in 1.1
if (dir != null && dir.equals("")) {
dir = null;
}
if (file != null && file.equals("")) {
file = null;
}
| public void | setDirectory(java.lang.String dir)Sets the directory of this file dialog window to be the
specified directory. Specifying a null or an
invalid directory implies an implementation-defined default.
This default will not be realized, however, until the user
has selected a file. Until this point, getDirectory()
will return the value passed into this method.
Specifying "" as the directory is exactly equivalent to
specifying null as the directory.
this.dir = (dir != null && dir.equals("")) ? null : dir;
FileDialogPeer peer = (FileDialogPeer)this.peer;
if (peer != null) {
peer.setDirectory(this.dir);
}
| public void | setFile(java.lang.String file)Sets the selected file for this file dialog window to be the
specified file. This file becomes the default file if it is set
before the file dialog window is first shown.
Specifying "" as the file is exactly equivalent to specifying
null
as the file.
this.file = (file != null && file.equals("")) ? null : file;
FileDialogPeer peer = (FileDialogPeer)this.peer;
if (peer != null) {
peer.setFile(this.file);
}
| public synchronized void | setFilenameFilter(java.io.FilenameFilter filter)Sets the filename filter for this file dialog window to the
specified filter.
Filename filters do not function in Sun's reference
implementation for Microsoft Windows.
this.filter = filter;
FileDialogPeer peer = (FileDialogPeer)this.peer;
if (peer != null) {
peer.setFilenameFilter(filter);
}
| public void | setMode(int mode)Sets the mode of the file dialog. If mode is not
a legal value, an exception will be thrown and mode
will not be set.
switch (mode) {
case LOAD:
case SAVE:
this.mode = mode;
break;
default:
throw new IllegalArgumentException("illegal file dialog mode");
}
|
|