bill.util.gui
Class FileFilterExtension

java.lang.Object
  |
  +--javax.swing.filechooser.FileFilter
        |
        +--bill.util.gui.FileFilterExtension

public class FileFilterExtension
extends FileFilter

This is an extension of the standard Java FileFilter class. It allows the user to specify file extensions to be added to the "Save as Type" combo box in a file selection dialog. When the user selects an entry from the combo box it is applied as a filter to the list of files displayed in the file list. Directories are displayed as are files that match the extension. File extensions are not treated as case sensitive, all are converted to lower case for comparison.
To create a filter that only shows .java and .jav files:
JFileChooser chooser = new JFileChooser();
FileFilterExtension filter = new FileFilterExtension ();
filter.addExtension ("java");
filter.addExtension ("jav");
filter.setDesciption ("Java Source Files");
chooser.setFileFilter (filter);
chooser.showOpenDialog (this);


Constructor Summary
FileFilterExtension()
          Default class creator, initializes class instance variables but does not set any filter criteria.
FileFilterExtension(String extension)
          Alternate class creator, set the list of extensions to use as a filter to the value passed in.
FileFilterExtension(String[] extensions)
          Alternate class creator, set the list of extensions to use as a filter to the values passed in.
Example: new FileFilterExtension(String {"java", "jav"});
If a "." is included before the extension it will be stripped off.
FileFilterExtension(String[] extensions, String description)
          Alternate class creator, set the list of extensions to use as a filter to the values passed in.
FileFilterExtension(String extension, String description)
          Alternate class creator, set the list of extensions to use as a filter to the value passed in.
 
Method Summary
 boolean accept(File f)
          Determines whether the given file is accepted by this filter.
 void addExtension(String extension)
          Adds the specified extenstion to the list of extensions we are filtering for.
If a "." is included before the extension it will be stripped off.
 String getDescription()
          Creates the formatted, readable description of this file extension filter.
 void setDescription(String description)
          Sets the descriptive text portion of the file extension filter.
For example: filter.setDescription ("Java Source Files");
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileFilterExtension

public FileFilterExtension()
Default class creator, initializes class instance variables but does not set any filter criteria.

FileFilterExtension

public FileFilterExtension(String extension)
Alternate class creator, set the list of extensions to use as a filter to the value passed in.
Parameters:
extension - The extension to add to the list of extension known by this filter.

FileFilterExtension

public FileFilterExtension(String extension,
                           String description)
Alternate class creator, set the list of extensions to use as a filter to the value passed in. Also sets the extension description to the supplied value.
If a "." is included before the extension it will be stripped off.
Parameters:
extension - The extension to add to the list of extension known by this filter.
description - Textual description of this file filter.

FileFilterExtension

public FileFilterExtension(String[] extensions)
Alternate class creator, set the list of extensions to use as a filter to the values passed in.
Example: new FileFilterExtension(String {"java", "jav"});
If a "." is included before the extension it will be stripped off.

FileFilterExtension

public FileFilterExtension(String[] extensions,
                           String description)
Alternate class creator, set the list of extensions to use as a filter to the values passed in. Also sets the extension description to the supplied value.
Example: new FileFilterExtension (String {"java", "jav"}, "Java source");
If a "." is included before the extension it will stripped off.
Method Detail

accept

public boolean accept(File f)
Determines whether the given file is accepted by this filter. Files that begin with "." are ignored as these are "hidden" files.
Overrides:
accept in class FileFilter
Returns:
A value of true if the file should be displayed, false if it should not.

addExtension

public void addExtension(String extension)
Adds the specified extenstion to the list of extensions we are filtering for.
If a "." is included before the extension it will be stripped off.
Parameters:
extension - The extension to add to the extension filter list.

getDescription

public String getDescription()
Creates the formatted, readable description of this file extension filter.
For example: "Java Source Files (*.java, *.jav)"
Overrides:
getDescription in class FileFilter
Returns:
The formatted description of the file filter.

setDescription

public void setDescription(String description)
Sets the descriptive text portion of the file extension filter.
For example: filter.setDescription ("Java Source Files");
Parameters:
description - The text to set the descriptive text to.