edu.princeton.swing
Class ExtensionFileFilter

java.lang.Object
  extended by javax.swing.filechooser.FileFilter
      extended by edu.princeton.swing.ExtensionFileFilter

public class ExtensionFileFilter
extends FileFilter

ExtensionFileFilter extends FileFilter to provide a generalized extension-based file filter.


Constructor Summary
ExtensionFileFilter()
          Creates a new ExtensionFileFilter.
ExtensionFileFilter(String baseDescription)
          Creates a new ExtensionFileFilter.
ExtensionFileFilter(String extension, String baseDescription)
          Creates a new ExtensionFileFilter.
 
Method Summary
 boolean accept(File file)
          Extend FileFilter to accept only files with an extension matching one added to the filter.
 void addExtension(String extension)
          Adds an extension to the list of accepted extensions.
 void clearExtensions()
          Removes all extensions from the list of accepted extensions.
 String getDescription()
          Gets a description of this filter.
 String getExtension(int index)
          Return the extension at a given index.
 int getExtensionCount()
          Return the number of extensions this filter will accept.
 void setBaseDescription(String baseDescription)
          Sets the base description of this filter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExtensionFileFilter

public ExtensionFileFilter()
Creates a new ExtensionFileFilter.


ExtensionFileFilter

public ExtensionFileFilter(String baseDescription)
Creates a new ExtensionFileFilter.


ExtensionFileFilter

public ExtensionFileFilter(String extension,
                           String baseDescription)
Creates a new ExtensionFileFilter.

Method Detail

accept

public boolean accept(File file)
Extend FileFilter to accept only files with an extension matching one added to the filter.

Specified by:
accept in class FileFilter

getExtensionCount

public int getExtensionCount()
Return the number of extensions this filter will accept.

Returns:
The number of extensions this filter will accept.

getExtension

public String getExtension(int index)
Return the extension at a given index.

Parameters:
index - The index of the desired extension. An ArrayIndexOutOfBoundsException will be thrown if the index is invalid.
Returns:
The extension at a given index.

addExtension

public void addExtension(String extension)
Adds an extension to the list of accepted extensions.

Parameters:
extension - The new extension to accept. A null value will result in a NullPointerException.

clearExtensions

public void clearExtensions()
Removes all extensions from the list of accepted extensions.


getDescription

public String getDescription()
Gets a description of this filter.

Specified by:
getDescription in class FileFilter
Returns:
A description of this filter, eg. "Web Image Files (*.jpg;*.jpeg;*.gif;*.png)"

setBaseDescription

public void setBaseDescription(String baseDescription)
Sets the base description of this filter.

Parameters:
baseDescription - The base description of this filter, eg. "Web Image Files"