Class FileChooser

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class FileChooser extends JFileChooser
Improvements to JFileChooser, namely:
 - Accessory toolbar with FlatLaf buttons to:
   - Navigation history: Drop-down list of recent locations
   - Toggle visibility of hidden files
   - Filter file list by string pattern
   - Reveal current directory in native file explorer
   - Rescan current directory
 - Confirmation dialog when overriding files
 - Fix for column widths resetting on directory change
 - Fix for detailed view not resizing with dialog
 - Setters for list/details view
 - Workaround current directory defaulting to root directory on Linux
 
Modifications should fail gracefully and are not expected to interfere w/ normal JFileChooser functionality. Drag and drop support is provided by GuiUtils to keep dependencies to a minimum (FlatLaf is the only dependency needed). TODO: submit this upstream to SciJava
See Also:
  • Constructor Details

    • FileChooser

      public FileChooser()
  • Method Details

    • reset

      public void reset()
      Resets preferences, column widths (detailed view), list of recent locations, and pattern filters.
    • isListView

      public boolean isListView()
      Checks if the current view type is list view.
      Returns:
      true if the current view type is list view, false otherwise.
    • isDetailsView

      public boolean isDetailsView()
      Checks if the current view type is details view.
      Returns:
      true if the current view type is details view, false otherwise.
    • setViewTypeList

      public void setViewTypeList()
      Sets the file view type to "list".
    • setViewTypeDetails

      public void setViewTypeDetails()
      Sets the file view type to "details".
    • getCurrentDirectory

      public File getCurrentDirectory()
      Overrides:
      getCurrentDirectory in class JFileChooser
    • setCurrentDirectory

      public void setCurrentDirectory(File dir)
      Overrides:
      setCurrentDirectory in class JFileChooser
    • setFileHidingEnabled

      public void setFileHidingEnabled(boolean b)
      Overrides:
      setFileHidingEnabled in class JFileChooser
    • approveSelection

      public void approveSelection()
      Overrides:
      approveSelection in class JFileChooser
    • cancelSelection

      public void cancelSelection()
      Overrides:
      cancelSelection in class JFileChooser
    • setFileFilter

      public void setFileFilter(FileFilter filter)
      Overrides:
      setFileFilter in class JFileChooser
    • getPatternFileFilters

      public FileFilter[] getPatternFileFilters()
      Gets the user 'pattern' file filters (created using the filter by pattern button)
      Returns:
      a FileFilter array containing the pattern file filters
    • error

      public void error(String msg)
      Displays an error message dialog.
      Parameters:
      msg - the error message to display.
    • resetPreferences

      public static void resetPreferences()
      Resets persisting preferences, including list of recent locations.
    • reveal

      Reveals the specified file in the native file explorer.
      Parameters:
      file - the file to be revealed. If the file is not a directory, its parent directory is used
      Throws:
      IllegalArgumentException - if file is null or does not exist.
      IOException - if an I/O error occurs.
      SecurityException - if a security manager exists and its checkRead method denies read access to the file.
      UnsupportedOperationException - if the current platform does not support desktop browsing.