com.lamatek.util
Class JFileFilter

java.lang.Object
  extended by javax.swing.filechooser.FileFilter
      extended by com.lamatek.util.JFileFilter

public class JFileFilter
extends javax.swing.filechooser.FileFilter

Provides a functional javax.swing.filechooser.FileFilter object to filter files accepted in a JFileChooser.

Users should create a JFileFilter, set it's description, and add each extension (with the '.') that this filter should accept. Then add the new JFileFilter to the JFileChooser by calling the JFileChooser.addChoosableFileFilter(FileFilter) method.


Constructor Summary
JFileFilter()
          Creates and initializes a new FileFilter.
JFileFilter(java.lang.String description)
          Create a new FileFilter with the given description.
JFileFilter(java.lang.String description, java.lang.String extension)
          Creates a new FileFilter with the given description, that accepts the given extension.
JFileFilter(java.lang.String description, java.lang.String extension, boolean acceptDirectories)
          Creates a new FileFilter with the given description that accepts the given extension and accepts/unaccepts directories.
 
Method Summary
 boolean accept(java.io.File file)
          Denotes whether the file fits this filters acceptance list.
 void acceptDirectories(boolean acceptDirectories)
          Sets whether this FileFiler should accept and display directories.
 void addExtension(java.lang.String extension)
          Adds an extension that this filter will accept.
 java.lang.String getDescription()
          Returns the textual description for this filter.
 void setDescription(java.lang.String description)
          Sets the description that will be shown in the JFileChooser drop-down list for this filter.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JFileFilter

public JFileFilter()
Creates and initializes a new FileFilter.


JFileFilter

public JFileFilter(java.lang.String description)
Create a new FileFilter with the given description.

Parameters:
description - The text description for this filter.

JFileFilter

public JFileFilter(java.lang.String description,
                   java.lang.String extension)
Creates a new FileFilter with the given description, that accepts the given extension.

Parameters:
description - The text description for this filter.
filter - The file extension this filter will accept.

JFileFilter

public JFileFilter(java.lang.String description,
                   java.lang.String extension,
                   boolean acceptDirectories)
Creates a new FileFilter with the given description that accepts the given extension and accepts/unaccepts directories.

Parameters:
description - The text description for this filter.
extension - The file extension this filter will accept.
acceptDirectories - Denotes whether this filter should accept directories.
Method Detail

acceptDirectories

public void acceptDirectories(boolean acceptDirectories)
Sets whether this FileFiler should accept and display directories.

Parameters:
acceptDirectories - Denotes whether this FileFilter should accept directories.

setDescription

public void setDescription(java.lang.String description)
Sets the description that will be shown in the JFileChooser drop-down list for this filter.

Parameters:
description - Text description for this file filter.

addExtension

public void addExtension(java.lang.String extension)
Adds an extension that this filter will accept. A JFileFilter can accept any number of extensions.

For example, you could create a JFileFilter that accepts all graphics formats like so:

 JFileFilter gFilter = new JFileFilter();
 gFilter.setDescription("Graphic Files");
 gFilter.addExtension("gif");
 gFilter.addExtension("jpg");
 gFilter.addExtension("bmp");
 fileChooser.addChoosableFileFilter(gFilter);

Parameters:
extension - The extension (without a period) to accept.

getDescription

public java.lang.String getDescription()
Returns the textual description for this filter.

Specified by:
getDescription in class javax.swing.filechooser.FileFilter
Returns:
A text description for this filter.

accept

public boolean accept(java.io.File file)
Denotes whether the file fits this filters acceptance list.

Specified by:
accept in class javax.swing.filechooser.FileFilter
Parameters:
file - The file to check.
Returns:
True if the file is accepted, false if it is not.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object