Class FileNameExtensionFilter


  • public final class FileNameExtensionFilter
    extends javax.swing.filechooser.FileFilter
    Creates a file filter for a specified file type. The filter takes a description of the file type and a list of matching extensions and creates a suitable filter for the file type and filters out files that do not match the extension (folders are not filtered out, to allow navigation).
    Since:
    3.0
    Author:
    Chris Jennings
    • Constructor Summary

      Constructors 
      Constructor Description
      FileNameExtensionFilter​(java.lang.String fileTypeDescription, java.lang.String... fileNameExtensions)
      Creates a file name filter for files that match the specified extensions.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean accept​(java.io.File file)
      Returns true if the filter accepts the file; that is, if a file chooser using the filter would display the file.
      java.lang.String getDescription()
      Returns a human-friendly description of the filter.
      boolean matches​(java.lang.String extension)
      Returns true if the specified extension matches one of the extensions in the filter.
      java.lang.String toString()
      Returns a string description of the filter for debugging purposes.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • FileNameExtensionFilter

        public FileNameExtensionFilter​(java.lang.String fileTypeDescription,
                                       java.lang.String... fileNameExtensions)
        Creates a file name filter for files that match the specified extensions. The provided description will be used as part of a description of the file type, but the exact description may vary by platform.
        Parameters:
        fileTypeDescription - the file type description
        fileNameExtensions - file extensions to accept; may not be null, empty, or contain null elements
    • Method Detail

      • accept

        public boolean accept​(java.io.File file)
        Returns true if the filter accepts the file; that is, if a file chooser using the filter would display the file.
        Specified by:
        accept in class javax.swing.filechooser.FileFilter
        Parameters:
        file - the file to test
        Returns:
        true if the file represents a folder or matches one of the filter's extensions
      • getDescription

        public java.lang.String getDescription()
        Returns a human-friendly description of the filter.
        Specified by:
        getDescription in class javax.swing.filechooser.FileFilter
        Returns:
        a description of the file filter
      • matches

        public boolean matches​(java.lang.String extension)
        Returns true if the specified extension matches one of the extensions in the filter.
        Parameters:
        extension - the extension (not including the '.' character)
        Returns:
        true if the extension matches one of the extensions accepted by this filter
      • toString

        public java.lang.String toString()
        Returns a string description of the filter for debugging purposes.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string describing the filter