Class SFileFetch

java.lang.Object
ca.spatial.util.SFileFetch
All Implemented Interfaces:
ActionListener, EventListener

public class SFileFetch extends Object implements ActionListener
This class encapsulates a JFileChooser with additional capabilities. This object is used throughout the Patchworks system to select file names.
  • Field Details

  • Constructor Details

    • SFileFetch

      public SFileFetch()
      Insantiate the chooser with default options
    • SFileFetch

      public SFileFetch(String title)
      Instantiate the choose with a specific title
      Parameters:
      title - the title to use on eht file chooser dialog
  • Method Details

    • setTitle

      public void setTitle(String title)
      Set the title for the file chooser
      Parameters:
      title - the title to use on eht file chooser dialog
    • getCurrentDirectory

      public File getCurrentDirectory()
      Return the current directory for this chooser
    • setCurrentDirectory

      public void setCurrentDirectory(File dir)
      Set the current directory for this chooser
      Parameters:
      dir - the new current directory
    • setCurrentDirectory

      public void setCurrentDirectory(String dirname)
      Set the current directory for this chooser
      Parameters:
      dirname - the new current directory
    • setSelectedFile

      public void setSelectedFile(File file)
      Set the file that is selected this chooser
      Parameters:
      file - the selected file
    • setMatchingFilter

      public void setMatchingFilter(File file)
      Set the first matching filter for the specifed file
    • resetFilters

      public void resetFilters()
      Reset the filter list to empty, accept all
    • addFilter

      public void addFilter(String extention, String description)
      Add a filter for a given extention
      Parameters:
      extention - the file name extention
      description - what the extention means
    • addFilter

      public void addFilter(String[] extentions, String description)
      Add a filter for a given extention
      Parameters:
      extentions - an array of file name extentions
      description - what the extentions mean
    • addFilter

      public void addFilter(FileFilter filter)
      Add a filter
      Parameters:
      filter - the filter to add
    • setOperation

      public void setOperation(int type)
      Set the operation type for this chooser. The operation type may be one of FILE_OPEN, FILE_SAVE, DIR_OPEN, DIR_SAVE
      Parameters:
      type - one of FILE_OPEN, FILE_SAVE, DIR_OPEN, DIR_SAVE
    • filename

      public File filename(Component parent)
      Show the dialog for the default operation and return the result
      Parameters:
      parent - the parent component for the dialog
    • filenameOpen

      public File filenameOpen(Component parent)
      Show the dialog for the FILE_OPEN operation and return the result
      Parameters:
      parent - the parent component for the dialog
    • filenamesOpen

      public File[] filenamesOpen(Component parent)
      Show the dialog for the FILE_OPEN operation and return multiple results
      Parameters:
      parent - the parent component for the dialog
    • filenameSave

      public File filenameSave(Component parent)
      Show the dialog for the FILE_SAVE operation and return the result
      Parameters:
      parent - the parent component for the dialog
    • dirnameSave

      public File dirnameSave(Component parent)
      Show the dialog for the DIR_SAVE operation and return the result
      Parameters:
      parent - the parent component for the dialog
    • dirnameOpen

      public File dirnameOpen(Component parent)
      Show the dialog for the DIR_OPEN operation and return the result
      Parameters:
      parent - the parent component for the dialog
    • dirnamesOpen

      public File[] dirnamesOpen(Component parent)
      Show the dialog for the DIR_OPEN operation and return multiple results
      Parameters:
      parent - the parent component for the dialog
    • actionPerformed

      public void actionPerformed(ActionEvent e)
      Specified by:
      actionPerformed in interface ActionListener
    • updateLru

      public static ArrayList<String> updateLru(String path)
      Update the list of recently used folders
    • loadLru

      public static ArrayList<String> loadLru()
      Return the list of recently used folders
    • glob

      public static String[] glob(File dir, String pattern)
      Get a list of files that match against a glob pattern. Glob patterns use simple wildcards:
      • An asterisk ('*') represents any wildcard sequence
      • A question mark ('?') represents a single wildcard character
      • A sequence inside brackets ('[' and ']') will match a single matchiing character (e.g. [abc] will match to either a, b, or c.
      Parameters:
      dir - The directory containing the files to compare
      pattern - The wildcard pattern
      Returns:
      An array of matching filenames.
    • globToRegex

      public static String globToRegex(String glob)
      Convert a glob pattern to a regex pattern. This routine will escape special characters, and transform '*' and '?' to wildcard strings and characters.
    • escapeRegex

      public static String escapeRegex(String glob)
      This routine will escape special characters.