Class GenericFileFilter

java.lang.Object
  extended by javax.swing.filechooser.FileFilter
      extended by GenericFileFilter

public class GenericFileFilter
extends javax.swing.filechooser.FileFilter

This is a generic file filter. The class allows for the addition and removal of extensions. After instanciating an instance of this class, the user can add all extensions to be accepted by the filter. This allows for custom file filters without the need to create a new class for each different filter.


Field Summary
(package private)  java.lang.String filterDesc
          The filter description
(package private)  java.util.ArrayList validExt
          Holds the list of valid extensions.
 
Constructor Summary
GenericFileFilter()
           
 
Method Summary
 boolean accept(java.io.File f)
          Returns true on directories and files with supported extensions.
 void addExtension(java.lang.String ext)
          Adds the passed in extension to the list of accepted extensions.
 void clearExtensions()
          Clears the list of extensions to accept.
 java.lang.String getDescription()
          Returns the description string of the FileFilter.
static java.lang.String getExtension(java.io.File f)
          Deterimines the file extension of the passed in file, then returns it.
 void removeExtension(java.lang.String ext)
          Removes the passed in extension from the list of accepted extensions.
 void setDescription(java.lang.String newDesc)
          Sets the description of the FileFilter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

validExt

java.util.ArrayList validExt
Holds the list of valid extensions. Stored as Strings.


filterDesc

java.lang.String filterDesc
The filter description

Constructor Detail

GenericFileFilter

public GenericFileFilter()
Method Detail

accept

public boolean accept(java.io.File f)
Returns true on directories and files with supported extensions. This function searches an array list of extensions to see if any match the passed in file's extension.

Specified by:
accept in class javax.swing.filechooser.FileFilter
Parameters:
f - File to test for acceptance
Returns:
true on accepted; false otherwise.

getDescription

public java.lang.String getDescription()
Returns the description string of the FileFilter.

Specified by:
getDescription in class javax.swing.filechooser.FileFilter
Returns:
The description of the FileFilter

setDescription

public void setDescription(java.lang.String newDesc)
Sets the description of the FileFilter.

Parameters:
newDesc - Description to use for the filter.

clearExtensions

public void clearExtensions()
Clears the list of extensions to accept.


removeExtension

public void removeExtension(java.lang.String ext)
Removes the passed in extension from the list of accepted extensions.

Parameters:
ext - The extension to remove.

addExtension

public void addExtension(java.lang.String ext)
Adds the passed in extension to the list of accepted extensions.

Parameters:
ext - The extension to add.

getExtension

public static java.lang.String getExtension(java.io.File f)
Deterimines the file extension of the passed in file, then returns it.

Parameters:
f - The file to determine the extension of
Returns:
The file extension