Class BaseDirectoryChooser

  • All Implemented Interfaces:
    ImageObserver, MenuContainer, Serializable, Accessible

    public class BaseDirectoryChooser
    extends com.jidesoft.swing.FolderChooser
    Extended version of the com.jidesoft.swing.FolderChooser to handle PlaceholderFile objects.
    Author:
    FracPete (fracpete at waikat dot ac dot nz)
    See Also:
    Serialized Form
    • Constructor Detail

      • BaseDirectoryChooser

        public BaseDirectoryChooser()
        Creates a BaseDirectoryChooser pointing to the user's home directory.
      • BaseDirectoryChooser

        public BaseDirectoryChooser​(File currentDirectory)
        Creates a BaseDirectoryChooser using the given File as the path.
        Parameters:
        currentDirectory - the directory to start in
      • BaseDirectoryChooser

        public BaseDirectoryChooser​(File currentDirectory,
                                    FileSystemView fsv)
        Creates a BaseDirectoryChooser using the given current directory and FileSystemView.
        Parameters:
        currentDirectory - the directory to start in
        fsv - the view to use
      • BaseDirectoryChooser

        public BaseDirectoryChooser​(FileSystemView fsv)
        Creates a BaseDirectoryChooser using the given FileSystemView.
        Parameters:
        fsv - the view to use
      • BaseDirectoryChooser

        public BaseDirectoryChooser​(String currentDirectoryPath)
        Creates a BaseDirectoryChooser using the given path.
        Parameters:
        currentDirectoryPath - the directory to start in
      • BaseDirectoryChooser

        public BaseDirectoryChooser​(String currentDirectoryPath,
                                    FileSystemView fsv)
        Creates a BaseDirectoryChooser using the given path and FileSystemView.
        Parameters:
        currentDirectoryPath - the directory to start in
        fsv - the view to use
    • Method Detail

      • initialize

        protected void initialize()
        For initializing some stuff.

        Default implementation does nothing.
      • createAccessoryPanel

        protected JComponent createAccessoryPanel()
        Creates an accessory panel displayed next to the files.
        Returns:
        the panel or null if none available
      • showBookmarks

        protected void showBookmarks​(boolean value)
        Either displays or hides the bookmarks.
        Parameters:
        value - true if to show bookmarks
      • findExistingDir

        protected static File findExistingDir​(File dir)
        Returns a directory that exists, starting with the provided one. If path cannot be used at all, they current working directory ("user.dir") is returned.
        Parameters:
        dir - the starting dir
        Returns:
        the existing dir
      • setSelectedFile

        public void setSelectedFile​(File file)
        Sets the selected file. If the file's parent directory is not the current directory, changes the current directory to be the file's parent directory.
        Overrides:
        setSelectedFile in class JFileChooser
        Parameters:
        file - the selected file
        See Also:
        getSelectedFile()
      • getSelectedFile

        public File getSelectedFile()
        Returns the selected file. This can be set either by the programmer via setFile or by a user action, such as either typing the filename into the UI or selecting the file from a list in the UI.
        Overrides:
        getSelectedFile in class JFileChooser
        Returns:
        the selected file
      • getSelectedDirectory

        public PlaceholderDirectory getSelectedDirectory()
        Returns the selected directory.
        Returns:
        the selected directory
      • setSelectedFiles

        public void setSelectedFiles​(File[] selectedFiles)
        Sets the list of selected files if the file chooser is set to allow multiple selection.
        Overrides:
        setSelectedFiles in class JFileChooser
        Parameters:
        selectedFiles - the files to select initially
      • getSelectedFiles

        public File[] getSelectedFiles()
        Returns a list of selected files if the file chooser is set to allow multiple selection.
        Overrides:
        getSelectedFiles in class JFileChooser
        Returns:
        the selected file
      • getSelectedDirectories

        public PlaceholderDirectory[] getSelectedDirectories()
        Returns the selected directories.
        Returns:
        the selected directories
      • setCurrentDirectory

        public void setCurrentDirectory​(File dir)
        Sets the current directory. Passing in null sets the file chooser to point to the user's default directory. This default depends on the operating system. It is typically the "My Documents" folder on Windows, and the user's home directory on Unix. 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 directory, or hits the root of the file system.
        Overrides:
        setCurrentDirectory in class JFileChooser
        Parameters:
        dir - the current directory to point to
        See Also:
        getCurrentDirectory()
      • main

        public static void main​(String[] args)
        For testing only.
        Parameters:
        args - ignored