Class PatternFileFilter

java.lang.Object
javax.swing.filechooser.FileFilter
ucar.unidata.util.PatternFileFilter
All Implemented Interfaces:
FileFilter, FilenameFilter

public class PatternFileFilter extends FileFilter implements FileFilter, FilenameFilter
This holds a set of regular expression patterns that are used for file filters in a JFileChooser. You can also pass in an Object id (which can be used as the client code sees fit) and a directoriesOk flag.
Author:
Metapps development team
  • Field Details

    • NULL_OBJECT_ID

      public static final Object NULL_OBJECT_ID
      Used for passing in a null object id
  • Constructor Details

    • PatternFileFilter

      public PatternFileFilter(String patternsString, String description)
      Create a new PatternFileFilter.
      Parameters:
      patternsString - A comma separated list of regular expressions.
      description - The label to use in the JFileChooser
    • PatternFileFilter

      public PatternFileFilter(String patternsString, String description, String suffix)
      Create a new PatternFileFilter.
      Parameters:
      patternsString - A comma separated list of regular expressions.
      description - The label to use in the JFileChooser
      suffix - The preferred suffix if none is provided.
    • PatternFileFilter

      public PatternFileFilter(String patternsString)
      Create a new PatternFileFilter.
      Parameters:
      patternsString - A comma separated list of regular expressions.
    • PatternFileFilter

      public PatternFileFilter(String patternsString, boolean dirsOk)
      Create a new PatternFileFilter.
      Parameters:
      patternsString - A comma separated list of regular expressions.
      dirsOk - Are directories ok to display.
    • PatternFileFilter

      public PatternFileFilter(String patternsString, boolean dirsOk, boolean hiddenOk)
      Create a new PatternFileFilter.
      Parameters:
      patternsString - A comma separated list of regular expressions.
      dirsOk - Are directories ok to display.
      hiddenOk - true if hidden files are okay.
    • PatternFileFilter

      public PatternFileFilter(String patternsString, Object id, String description)
      Create a new PatternFileFilter.
      Parameters:
      patternsString - A comma separated list of regular expressions.
      id - An arbitary Object for client code to use.
      description - The label to use in the JFileChooser
    • PatternFileFilter

      public PatternFileFilter(String patternsString, Object id, String description, String suffix)
      Create a new PatternFileFilter.
      Parameters:
      patternsString - A comma separated list of regular expressions.
      id - An arbitary Object for client code to use.
      description - The label to use in the JFileChooser
      suffix - The preferred suffix if none is provided.
  • Method Details

    • createFilters

      public static List createFilters(String filterString)
      Parse the given string and return a list of PatternFileFilter-s The string is a ";" delimited list of pattern specifications of the form: pattern":"description or: just the pattern. E.g.: ".*\.nc:Netcdf files;.*\.html;.*\.txt:Text files"
      Parameters:
      filterString - The string of semi-colon delimited filters.
      Returns:
      List of PatternFileFilter objects.
    • getId

      public Object getId()
      Return the object id.
      Returns:
      the object id.
    • toString

      public String toString()
      Override base class method.
      Overrides:
      toString in class Object
      Returns:
      the string representation of this object.
    • accept

      public boolean accept(File file)
      Does this pattern match the given file.
      Specified by:
      accept in interface FileFilter
      Specified by:
      accept in class FileFilter
      Parameters:
      file - The given file.
      Returns:
      Does this pattern match the given file.
    • accept

      public boolean accept(File dir, String name)
      Implement the FilenameFilter method
      Specified by:
      accept in interface FilenameFilter
      Parameters:
      dir - directory to check
      name - name of file
      Returns:
      true if we should accept this.
    • match

      public boolean match(String name)
      Does this pattern match the given file.
      Parameters:
      name - The given file.
      Returns:
      Does this pattern match the given file.
    • getDescription

      public String getDescription()
      Return the description.
      Specified by:
      getDescription in class FileFilter
      Returns:
      the description.
    • setPreferredSuffix

      public void setPreferredSuffix(String value)
      Set the PreferedSuffix property.
      Parameters:
      value - The new value for PreferedSuffix
    • getPreferredSuffix

      public String getPreferredSuffix()
      Get the PreferredSuffix property.
      Returns:
      The PreferredSuffix
    • main

      public static void main(String[] args)
      Test
      Parameters:
      args - Command line args.