Class FileFilterFactory

java.lang.Object
xal.tools.apputils.files.FileFilterFactory

public class FileFilterFactory extends Object
FileFilterFactory generates file filters based on supplied file types.
Author:
tap
  • Field Details

  • Constructor Details

    • FileFilterFactory

      protected FileFilterFactory()
      Creates a new instance of FileFilterFactory
  • Method Details

    • applyFileFilters

      public static JFileChooser applyFileFilters(JFileChooser fileChooser, String[] fileTypes, String[] fileDescriptions)
      Applies the file filters to the file chooser and returns this file chooser. Existing file filters are removed from the file chooser and then new file filters are added to the file chooser consistent with the specified file types and descriptions.
      Parameters:
      fileChooser - the file chooser to which to add the file filters
      fileTypes - An array of file types to accept
      fileDescriptions - An array of corresponding file type descriptions
      Returns:
      The file chooser that accepts the specified file types (same file chooser as the argument)
    • applyFileFilters

      public static JFileChooser applyFileFilters(JFileChooser fileChooser, String[] fileTypes)
      Applies the file filters to the file chooser and returns this file chooser. Existing file filters are removed from the file chooser and then new file filters are added to the file chooser consistent with the specified file types.
      Parameters:
      fileChooser - the file chooser to which to add the file filters
      fileTypes - An array of file types to accept
      Returns:
      The file chooser that accepts the specified file types (same file chooser as the argument)
    • getFileFilter

      public static FileFilter getFileFilter(String fileType, String description)
      Create a file filter that accepts files of the specified type. This is a supporting method for creating file choosers. A type is identified by its filename suffix.
      Parameters:
      fileType - File type to accept
      description - the description of this file type
      Returns:
      The file filter that accepts the specified file type
    • getSupportedFileFilter

      public static FileFilter getSupportedFileFilter(String[] fileTypes)
      Create a file filter that accepts files of the specified types. This is a supporting method for creating file choosers. A type is identified by its filename suffix.
      Parameters:
      fileTypes - Array of file types to accept
      Returns:
      The file filter that accepts the specified file types
    • getFileExtension

      protected static String getFileExtension(File file)
      Determine the file's extension.
      Parameters:
      file - the file for which to get the extension
      Returns:
      the file's extension
    • isMatch

      protected static boolean isMatch(String extension, String fileType)
      Determine whether the extension matches the file type. If the file type is the wildcard extension, then accept all extensions as matching.
      Parameters:
      extension - the file extension to test for matching to the file type.
      fileType - the file type against which to test for matching the file extension.
      Returns:
      true if the extension matches the file type