com.ccg.swing
Class FilenameFilter

java.lang.Object
  extended by javax.swing.filechooser.FileFilter
      extended by com.ccg.swing.FilenameFilter

public class FilenameFilter
extends FileFilter

Builds a "file filter" which matches file names and is suitable for use with the Swing JFileChooser.

This is a helper class which simplifies the process of building file filters for Swing. It aids in the following:

Here is a quick example of how one might use this object to select only HTML files (which end with "htm" OR "html" extensions):

   public void addFilter(JFileChooser fc) {
     fc.addChoosableFileFilter(new FilenameFilter("*.html;*.htm",
                                 "HTML Documents"));
   }
 

Please note that the "match" filter is only applied to file names and that ALL directories are accepted by this filter.

Since:
1.0
Version:
$Revision: 1.1 $
Author:
$Author: pkb $
See Also:
FileFilter, JFileChooser

Field Summary
(package private)  String _Description
           
(package private)  FilenameFilterWild _Filter
           
 
Constructor Summary
FilenameFilter(String match, String des)
          Fully construct and initialize the object (ready for use).
 
Method Summary
 boolean accept(File f)
          Returns true if the file passed matches one of the acceptable forms.
 String getDescription()
          Get the text description of the filter (what to show user).
 String toString()
          The text description of the filter (what to show user).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_Filter

FilenameFilterWild _Filter

_Description

String _Description
Constructor Detail

FilenameFilter

public FilenameFilter(String match,
                      String des)
Fully construct and initialize the object (ready for use).

Parameters:
match - One or more "wild" strings (separated by semi-colons) which describe what files should be accepted. For example: "*.txt" or "*.htm;*.html". Must NOT be null.
Since:
1.0
Method Detail

accept

public boolean accept(File f)
Returns true if the file passed matches one of the acceptable forms.

Specified by:
accept in class FileFilter
Parameters:
f - File to check (we handle null).
Returns:
true if the file passed should be accepted (we accept ALL directories).
Since:
1.0

getDescription

public String getDescription()
Get the text description of the filter (what to show user).

Specified by:
getDescription in class FileFilter
Returns:
Text description of filter (never returns null).
Since:
1.0

toString

public String toString()
The text description of the filter (what to show user).

Overrides:
toString in class Object
Returns:
Text description of filter (never returns null).
Since:
1.0


Copyright 1998-1998-2006 null. All Rights Reserved.