WebNFS Developer's Guide

Introduction

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.

Figure 5-1 The Default XFileChooser

Graphic

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.


Note -

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


Note -

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 Bean

XFileChooser is a Java BeanTM. This means that

Figure 5-2 The XFileChooser Bean Icon

Graphic

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:

Figure 5-3 The XFileChooser Bean in the BeanBox Editor

Graphic

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.

Architecture

XFileChooser inherits from JFileChooser in the following way:

Figure 5-4 The XFileChooser Class Hierarchy

Graphic

The relationship between XFileChooser, JFileChooser, and the Extended File API is shown in Figure 5-5:

Figure 5-5 XFileChooser, JFileChooser, and XFile

Graphic