A file chooser is a standalone graphical component for selecting files. Typically, it's brought up when the user chooses Open or Save from a menu or presses an Open or Save button. A typical file chooser is shown in Figure 5-1.
The Java Swing package provides a file chooser by means of the JFileChooser class. Although JFileChooser is typically used to allow a user to open or save files, an application may perform a customized action with the selected files instead. The JFileChooser does not itself perform any action on any file, including opening or saving; instead, it only provides the user with a window for selecting files to be worked with. For each file the user selects, JFileChooser returns a File object to the calling application, which can then perform the usual file operations on it.
For more on JFileChooser, see the javadocs for the JFileChooser and the section How to Use File Choosers in the Java Tutorial.
JFileChooser, however, is limited to local filesystems. To allow an application to select files on distributed filesystems such as NFS, another file chooser class is required: XFileChooser.
The XFileChooser class extends the JFileChooser class; however, it utilizes the Extended File Application Programming Interface (the XFile API, for short) for its file operations instead of java.File. Specifically, it uses XFile objects in place of the File objects used by JFileChooser. Since XFile objects include files distributed on NFS networks, an XFileChooser can access exported files anywhere on an NFS network. So, while JFileChooser allows you to select files on your own local (or "native") system, for example:
/home/marlowe/plays |
XFileChooser can access not only a local file but any exported filesystem on an NFS server, using the syntax specified by the NFS classes used by the Extended File API:
nfs://playstation/export/shakespeare/sonnets |
Although the XFile API theoretically provides access to other kinds of distributed filesystems, including HTTP and CIFS, currently only NFS access is implemented (along with native access).
Because XFileChooser is an extension of JFileChooser, it inherits the public methods and variables of that class. An application uses XFileChooser in virtually the same way it uses JFileChooser; in most cases "porting" an application that uses JFileChooser to using XFileChooser requires only changing the names of methods (for example, from getSelectedFile() to getSelectedXFile()) and replacing File objects with XFile objects. In many cases this may be only a few minutes' work.
XFileChooser is a Java BeanTM. This means that
It can listen for events from other Beans, and notify them of its own events. See "Events" for more information.
The XFileChooser class can be incorporated into a Bean-aware editor, such as BeanBoxTM, by importing the xfilechooser.jar file included with this release. The XFileChooser icon will appear on the palette of the editor:
Here's what the XFileChooserBean looks like when loaded into BeanBox. Note that the Bean suppors a property sheet that allows users to customize the Bean:
Properties that can be modified from the property sheet include: the dialogue type; the dialogue title; the file-selection mode; hidden-file display; text for the "approve" button; mnemonic for the "approve" action; tooltip; look-and-feel; and current directory. See "Properties" for a list of XFileChooser's properties.
XFileChooser inherits from JFileChooser in the following way:
The relationship between XFileChooser, JFileChooser, and the Extended File API is shown in Figure 5-5: