flatscape.util
Class SuffixFileFilter

java.lang.Object
  |
  +--javax.swing.filechooser.FileFilter
        |
        +--flatscape.util.SuffixFileFilter
All Implemented Interfaces:
Configurable, java.io.FileFilter

public class SuffixFileFilter
extends javax.swing.filechooser.FileFilter
implements java.io.FileFilter, Configurable

A FileFilter that accepts only files that end with the provided suffix(es). This filter can be used by the File class and the JFileChooser dialog. Note that suffixes must contain the . if needed. For example:

new SuffixFileFilter("TIFF Files", new String[] {".tif", ".tiff"})

Copyright (c) 2001 Rutgers, The State University of New Jersey

Since:
flatscape %Version%
Version:
%Version%, %Time%

Field Summary
 boolean acceptDirs
          If set to false, all directories are filtered out.
 boolean acceptHidden
          If set to false, all hidden files and directories are filtered out.
protected  java.lang.String description
           
protected  java.lang.String[] suffixes
           
 
Constructor Summary
SuffixFileFilter()
          Constructs a filter which allows all files.
SuffixFileFilter(java.lang.String suffix)
          Constructs a filter which allows only files ending with the specified suffix.
SuffixFileFilter(java.lang.String[] suffixes)
          Constructs a filter which allows only files ending with any of the specified suffixes.
SuffixFileFilter(java.lang.String description, java.lang.String suffix)
          Constructs a filter which allows only files ending with the specified suffix, and has the given description.
SuffixFileFilter(java.lang.String description, java.lang.String[] suffixes)
          Constructs a filter which allows only files ending with any of the specified suffixes, and has the given description.
 
Method Summary
 boolean accept(java.io.File file)
           
 java.lang.Object config(java.lang.Object parent, org.w3c.dom.Element config)
          Returns a configured SuffixFileFilter instance.
 java.lang.String getDescription()
          Returns a String of the description followed by the list of acceptable suffixes.
static java.lang.String stripSuffix(java.io.File file)
          Returns the file name minus any suffix present.
static java.lang.String stripSuffix(java.lang.String source)
          Returns the the name of a file extracted from a source path.
 java.lang.String toString()
          Returns the result of the getDescription method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

description

protected java.lang.String description

suffixes

protected java.lang.String[] suffixes

acceptDirs

public boolean acceptDirs
If set to false, all directories are filtered out. Default value is true.


acceptHidden

public boolean acceptHidden
If set to false, all hidden files and directories are filtered out. Default value is false.

Constructor Detail

SuffixFileFilter

public SuffixFileFilter()
Constructs a filter which allows all files.


SuffixFileFilter

public SuffixFileFilter(java.lang.String suffix)
Constructs a filter which allows only files ending with the specified suffix.


SuffixFileFilter

public SuffixFileFilter(java.lang.String[] suffixes)
Constructs a filter which allows only files ending with any of the specified suffixes.


SuffixFileFilter

public SuffixFileFilter(java.lang.String description,
                        java.lang.String suffix)
Constructs a filter which allows only files ending with the specified suffix, and has the given description.


SuffixFileFilter

public SuffixFileFilter(java.lang.String description,
                        java.lang.String[] suffixes)
Constructs a filter which allows only files ending with any of the specified suffixes, and has the given description.

Method Detail

stripSuffix

public static java.lang.String stripSuffix(java.lang.String source)
Returns the the name of a file extracted from a source path. The name will also have any suffix present removed.


stripSuffix

public static java.lang.String stripSuffix(java.io.File file)
Returns the file name minus any suffix present.


config

public java.lang.Object config(java.lang.Object parent,
                               org.w3c.dom.Element config)
                        throws java.lang.Exception
Returns a configured SuffixFileFilter instance. The attributes "description" "acceptDirs" and "acceptHidden" can be specified. The value of the element is tokenized into the suffix array.

Specified by:
config in interface Configurable
Parameters:
parent - The argument passed into the FConfig.getList method
config - The DOM element representing the XML element that loaded this class.
Returns:
The configured class, usually returns this.
Throws:
java.lang.Exception - Thrown if there is any problem configuring this class.

accept

public boolean accept(java.io.File file)
Specified by:
accept in interface java.io.FileFilter
Specified by:
accept in class javax.swing.filechooser.FileFilter

getDescription

public java.lang.String getDescription()
Returns a String of the description followed by the list of acceptable suffixes.

Specified by:
getDescription in class javax.swing.filechooser.FileFilter

toString

public java.lang.String toString()
Returns the result of the getDescription method.

Overrides:
toString in class java.lang.Object


Copyright (c) 2003 Rutgers, The State University of New Jersey