com.taco.swinger.filechooser
Class ExtensionFileFilter

java.lang.Object
  extended by javax.swing.filechooser.FileFilter
      extended by com.taco.swinger.filechooser.ExtensionFileFilter
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class ExtensionFileFilter
extends javax.swing.filechooser.FileFilter
implements java.lang.Cloneable, java.io.Serializable

A file filter that accepts only files with names that end with one of an approved list of extensions. Its description can be set, or a default one will be generated if necessary.

See Also:
Serialized Form

Field Summary
protected  boolean _acceptDirectories
          If true, accept directories.
protected  int _cachedHashCode
          The hash code for this filter, lazily created and cached.
protected  java.lang.String _description
          The description of the filter, lazily created and cached if not set explicitly.
protected  boolean _descriptionExplicitlySet
          True if the description was set with a non-null value by the user.
protected  java.lang.String[] _extensions
          An array of extensions to match.
 
Constructor Summary
ExtensionFileFilter()
          Create a new instance that accepts no extensions and but accepts directories.
ExtensionFileFilter(java.lang.String[] extensions)
          Construct a new instance that accepts files whose name ends with any of the extensions in the argument array, case insensitively.
ExtensionFileFilter(java.lang.String[] extensions, boolean acceptDirectories)
          Construct a new instance that accepts files whose name ends with any of the extensions in the argument array, case insensitively.
ExtensionFileFilter(java.lang.String[] extensions, java.lang.String description, boolean acceptDirectories)
          Construct a new instance that accepts files whose name ends with any of the extensions in the argument array, case insensitively.
 
Method Summary
 boolean accept(java.io.File file)
           
 boolean equals(java.lang.Object obj)
          This implementation is sensitive to the order of the extensions.
 boolean getAcceptDirectories()
          Return true if this instance accepts directories.
 java.lang.String getDescription()
          If the description has been set to a non-null value, return it.
 java.lang.String[] getExtensions()
          Return a copy of the accepted extension array.
 int hashCode()
           
 void setAcceptDirectories(boolean accept)
          Set whether or not this instance accepts directories.
 void setDescription(java.lang.String description)
          Set the description.
 void setExtensions(java.lang.String[] extensions)
          Set the extension array to the argument, which is NOT copied.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_extensions

protected java.lang.String[] _extensions
An array of extensions to match. For efficiency reasons, each of the extensions should contain the '.' character before the prefix, and should only contain lower case letters.


_acceptDirectories

protected boolean _acceptDirectories
If true, accept directories.


_description

protected java.lang.String _description
The description of the filter, lazily created and cached if not set explicitly.


_descriptionExplicitlySet

protected boolean _descriptionExplicitlySet
True if the description was set with a non-null value by the user. Otherwise, the description needs to be generated each time a modification to this instance is made.


_cachedHashCode

protected int _cachedHashCode
The hash code for this filter, lazily created and cached.

Constructor Detail

ExtensionFileFilter

public ExtensionFileFilter()
Create a new instance that accepts no extensions and but accepts directories.


ExtensionFileFilter

public ExtensionFileFilter(java.lang.String[] extensions)

Construct a new instance that accepts files whose name ends with any of the extensions in the argument array, case insensitively. For efficiency reasons, each of the extensions should contain the '.' character before the prefix, and should only contain lower case letters. The argument array will be copied by reference only, so if changes might be made, a clone of the array should be used.

Directories will not be accepted and a default description will be generated if necessary.


ExtensionFileFilter

public ExtensionFileFilter(java.lang.String[] extensions,
                           boolean acceptDirectories)

Construct a new instance that accepts files whose name ends with any of the extensions in the argument array, case insensitively. For efficiency reasons, each of the extensions should contain the '.' character before the prefix, and should only contain lower case letters. The argument array will be copied by reference only, so if changes might be made, a clone of the array should be used.

If acceptDirectories is true, the filter will also accept directories.

A default description will be generated if necessary.


ExtensionFileFilter

public ExtensionFileFilter(java.lang.String[] extensions,
                           java.lang.String description,
                           boolean acceptDirectories)

Construct a new instance that accepts files whose name ends with any of the extensions in the argument array, case insensitively. For efficiency reasons, each of the extensions should contain the '.' character before the prefix, and should only contain lower case letters. The argument array will be copied by reference only, so if changes might be made, a clone of the array should be used.

If acceptDirectories is true, the filter will also accept directories.

If description is non-null, it will be used as the filter description. Otherwise, a default description will be generated if necessary.

Method Detail

equals

public boolean equals(java.lang.Object obj)
This implementation is sensitive to the order of the extensions.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

accept

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

getExtensions

public java.lang.String[] getExtensions()
Return a copy of the accepted extension array.


setExtensions

public void setExtensions(java.lang.String[] extensions)
Set the extension array to the argument, which is NOT copied. The caller must not modify the argument array afterwards.


getAcceptDirectories

public boolean getAcceptDirectories()
Return true if this instance accepts directories.


setAcceptDirectories

public void setAcceptDirectories(boolean accept)
Set whether or not this instance accepts directories.


getDescription

public java.lang.String getDescription()

If the description has been set to a non-null value, return it. Otherwise, return a string in the format:

Files matching (*.ext, *.yuk)

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

setDescription

public void setDescription(java.lang.String description)
Set the description. If the argument is null, compute a description based on the extension array.


toString

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