com.sun.xfilechooser

Class XFileChooser

Implemented Interfaces:
PropertyChangeListener

public class XFileChooser
extends JFileChooser
implements PropertyChangeListener

XFileChooser is an extension of the JFileChooser. It provides a simple mechanism for the user to choose a file locally and remotely via NFS URLs. Instead of returning a File Object which is done in JFileChooser it returns and XFile Object. The XFile object allows access to local and remote files.
Version:
1.0
Author:
Agnes Jacob
See Also:
XFileChooser

Field Summary

static String
SELECTED_XFILES_CHANGED_PROPERTY
Identifes change in user's multiple-file selection.
static String
SELECTED_XFILE_CHANGED_PROPERTY
Identifes change in user's single-file selection.
static String
XDIRECTORY_CHANGED_PROPERTY
Identifies user's directory change.

Constructor Summary

XFileChooser()
Creates a XFileChooser pointing to the user's home directory.
XFileChooser(String currentDirectoryPath)
Creates a XFileChooser using the given path.
XFileChooser(XFile currentDirectory)
Creates a XFileChooser using the given XFile as the path.

Method Summary

void
ensureFileIsVisible(XFile f)
Make sure that the specified file is viewable, and not hidden.
XFile
getCurrentXDirectory()
Returns XFile Object of the current directory.
XFile
getSelectedXFile()
Returns the XFile object of the selected file.
XFileInputStream
getSelectedXFileInputStream()
Returns the XFileInputStream object of the selected file
XFileOutputStream
getSelectedXFileOutputStream()
Returns the XFileOutputStream object of the selected file
XFile[]
getSelectedXFiles()
Returns a list of selected files if the filechooser is set to allow multi-selection.
static void
main(args[] )
Used only for testing of bean
void
propertyChange(PropertyChangeEvent e)
This method gets called when certain bound properties has changed on the associated JFileChooser.
void
setCurrentXDirectory(XFile currentDirectory)
Sets the current directory.
void
setSelectedXFile(XFile selectedFile)
Sets the XFile object of the selected file.
void
setSelectedXFiles(XFile[] selectedFiles)
Sets the list of selected files if the filechooser is set to allow multi-selection.

Field Details

SELECTED_XFILES_CHANGED_PROPERTY

public static final String SELECTED_XFILES_CHANGED_PROPERTY
Identifes change in user's multiple-file selection.

SELECTED_XFILE_CHANGED_PROPERTY

public static final String SELECTED_XFILE_CHANGED_PROPERTY
Identifes change in user's single-file selection.

XDIRECTORY_CHANGED_PROPERTY

public static final String XDIRECTORY_CHANGED_PROPERTY
Identifies user's directory change.

Constructor Details

XFileChooser

public XFileChooser()
Creates a XFileChooser pointing to the user's home directory. Initializes some of the private variables needed for bean's editor.

XFileChooser

public XFileChooser(String currentDirectoryPath)
Creates a XFileChooser using the given path. Passing in a null string causes the file chooser to point to the users home directory.
Parameters:
currentDirectoryPath - a String giving the path to a file or directory

XFileChooser

public XFileChooser(XFile currentDirectory)
Creates a XFileChooser using the given XFile as the path. Passing in a null file causes the file chooser to point to the users's home directory.
Parameters:
currentDirectory - a XFile object specifying the path to a file or directory

Method Details

ensureFileIsVisible

public void ensureFileIsVisible(XFile f)
Make sure that the specified file is viewable, and not hidden.
Parameters:
f - an XFile object

getCurrentXDirectory

public XFile getCurrentXDirectory()
Returns XFile Object of the current directory.
Returns:
the XFile object of the current directory

getSelectedXFile

public XFile getSelectedXFile()
Returns the XFile object of the selected file. This can be set either by the programmer via setSelectedXFile() or by a user action, such as either typing the filename int the UI or selecting the file from a list in the UI.
Returns:
the XFile object of the selected file

getSelectedXFileInputStream

public XFileInputStream getSelectedXFileInputStream()
Returns the XFileInputStream object of the selected file
Returns:
XFileInputStream of the selected input file

getSelectedXFileOutputStream

public XFileOutputStream getSelectedXFileOutputStream()
Returns the XFileOutputStream object of the selected file
Returns:
XFileOutputStream of the selected output file

getSelectedXFiles

public XFile[] getSelectedXFiles()
Returns a list of selected files if the filechooser is set to allow multi-selection.
Returns:
list of XFile objects of the selected files

main

public static void main(args[] )
Used only for testing of bean

propertyChange

public void propertyChange(PropertyChangeEvent e)
This method gets called when certain bound properties has changed on the associated JFileChooser. The properties it will listen to include: DIRECTORY_CHANGED_PROPERTY, SELECTED_FILE_CHANGED_PROPERTY, SELECTED_FILES_CHANGED_PROPERTY. This method is needed to create the corresponding XFile for the File object of the selected file or directory.

setCurrentXDirectory

public void setCurrentXDirectory(XFile currentDirectory)
Sets the current directory. Passing in null sets the filechooser to point to the users's home directory. If the file passed in as currentDirectory is not a directory, the parent of the file will be used as the currentDirectory. If the parent is not traversable, then it will walk up the parent tree until it finds a traversable direcotry, or hits the root of the file system.
Parameters:
currentDirectory - the XFile object of the current directory to point to.

setSelectedXFile

public void setSelectedXFile(XFile selectedFile)
Sets the XFile object of the selected file. If the file's parent directory is not the current directory, it changed the current directory to be the files parent directory. This just calls the setSelectedFile() of JFileChooser, passing it the corresponding File object of the selected file.
Parameters:
selectedFile - the XFile object of the selected file

setSelectedXFiles

public void setSelectedXFiles(XFile[] selectedFiles)
Sets the list of selected files if the filechooser is set to allow multi-selection.