Class XFileChooser

All Implemented Interfaces:
ImageObserver, MenuContainer, PropertyChangeListener, Serializable, EventListener, Accessible

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:
  • Field Details

    • XDIRECTORY_CHANGED_PROPERTY

      public static final String XDIRECTORY_CHANGED_PROPERTY
      Identifies user's directory change.
      See Also:
    • SELECTED_XFILE_CHANGED_PROPERTY

      public static final String SELECTED_XFILE_CHANGED_PROPERTY
      Identifes change in user's single-file selection.
      See Also:
    • SELECTED_XFILES_CHANGED_PROPERTY

      public static final String SELECTED_XFILES_CHANGED_PROPERTY
      Identifes change in user's multiple-file selection.
      See Also:
  • 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

    • 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.
      Specified by:
      propertyChange in interface PropertyChangeListener
    • getCurrentXDirectory

      public XFile getCurrentXDirectory()
      Returns XFile Object of the current directory.
      Returns:
      the XFile object of the current directory
      See Also:
    • 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.
      See Also:
    • 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
      See Also:
    • 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
      See Also:
    • 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
      See Also:
    • setSelectedXFiles

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

      public XFileInputStream getSelectedXFileInputStream()
      Returns the XFileInputStream object of the selected file
      Returns:
      XFileInputStream of the selected input file
      See Also:
    • getSelectedXFileOutputStream

      public XFileOutputStream getSelectedXFileOutputStream()
      Returns the XFileOutputStream object of the selected file
      Returns:
      XFileOutputStream of the selected output file
      See Also:
    • ensureFileIsVisible

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

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