Class ExtensionFileFilter

java.lang.Object
javax.swing.filechooser.FileFilter
nz.ac.waikato.cms.gui.core.ExtensionFileFilter
All Implemented Interfaces:
Serializable, Comparable<ExtensionFileFilter>

public class ExtensionFileFilter extends FileFilter implements Comparable<ExtensionFileFilter>, Serializable
A FileFilter for filtering files base on their extension. Directories are always accepted.
Version:
$Revision: 11193 $
Author:
fracpete (fracpete at waikato dot ac dot nz)
See Also:
  • Field Details

    • EXT_ALL_FILES

      public static final String EXT_ALL_FILES
      the "all files" extensions.
      See Also:
    • m_Description

      protected String m_Description
      the description of the filter.
    • m_Extensions

      protected String[] m_Extensions
      the extensions.
    • m_CaseSensitive

      protected boolean m_CaseSensitive
      whether case-sensitive or not.
  • Constructor Details

    • ExtensionFileFilter

      public ExtensionFileFilter()
      Constructs a filter that matches all files.
    • ExtensionFileFilter

      public ExtensionFileFilter(String description, String extension)
      Constructs a filter that matches files with the given extension, not case-sensitive.
      Parameters:
      description - the display string
      extension - the extensions of the files (no dot!)
    • ExtensionFileFilter

      public ExtensionFileFilter(String description, String[] extensions)
      Constructs a filter that matches files with the given extension, not case-sensitive.
      Parameters:
      description - the display string
      extensions - the extensions of the files (no dot!)
    • ExtensionFileFilter

      public ExtensionFileFilter(String description, String extension, boolean caseSensitive)
      Constructs a filter that matches files with the given extension, not case-sensitive.
      Parameters:
      description - the display string
      extension - the extensions of the files (no dot!)
      caseSensitive - if true then the filter is case-sensitive
    • ExtensionFileFilter

      public ExtensionFileFilter(String description, String[] extensions, boolean caseSensitive)
      Constructs a filter that matches files with the given extension, not case-sensitive.
      Parameters:
      description - the display string
      extensions - the extensions of the files (no dot!)
      caseSensitive - if true then the filter is case-sensitive
  • Method Details

    • accept

      public boolean accept(File f)
      Whether the given file is accepted by this filter.
      Specified by:
      accept in class FileFilter
      Parameters:
      f - the file to check
      Returns:
      true if accepted
    • getDescription

      public String getDescription()
      The description of this filter.
      Specified by:
      getDescription in class FileFilter
      Returns:
      the description
    • getExtensions

      public String[] getExtensions()
      Returns the extensions.
      Returns:
      the extensions
    • isCaseSensitive

      public boolean isCaseSensitive()
      Returns whether the filter is case-sensitive or not.
      Returns:
      true if case-sensitive
    • compareTo

      public int compareTo(ExtensionFileFilter o)
      Compares this image format with the specified filter for order. Returns a negative integer, zero, or a positive integer as this filter is less than, equal to, or greater than the specified filter.
      Specified by:
      compareTo in interface Comparable<ExtensionFileFilter>
      Parameters:
      o - the filter to be compared.
      Returns:
      a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
    • equals

      public boolean equals(Object obj)
      Indicates whether some other object is "equal to" this one.

      For some reason, we cannot override this method, using the result returned by the compareTo(ExtensionFileFilter) method. This results in the user no longer being able to change the file filter in the FileChooser dialog.
      Overrides:
      equals in class Object
      Parameters:
      obj - the reference object with which to compare.
      Returns:
      true if this object is the same as the obj argument; false otherwise.
    • toString

      public String toString()
      Returns a short description of the filter.
      Overrides:
      toString in class Object
      Returns:
      the description
    • getTextFileFilter

      public static ExtensionFileFilter getTextFileFilter()
      Returns a filter for text files.
      Returns:
      the text filter
    • getLogFileFilter

      public static ExtensionFileFilter getLogFileFilter()
      Returns a filter for log files.
      Returns:
      the log filter
    • getPropertiesFileFilter

      public static ExtensionFileFilter getPropertiesFileFilter()
      Returns a filter for props files.
      Returns:
      the props filter
    • getCsvFileFilter

      public static ExtensionFileFilter getCsvFileFilter()
      Returns a filter for CSV files.
      Returns:
      the CSV filter
    • getPdfFileFilter

      public static ExtensionFileFilter getPdfFileFilter()
      Returns a filter for PDF files.
      Returns:
      the PDF filter
    • getZipFileFilter

      public static ExtensionFileFilter getZipFileFilter()
      Returns a filter for ZIP files.
      Returns:
      the ZIP filter