|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavax.swing.filechooser.FileFilter
org.jscience.io.ExtensionFileFilter
public class ExtensionFileFilter
ExtensionFileFilter is a flexible multi-purpose FileFilter. ExtensionFileFilter implements java.io.FileFilter as well as extending javax.swing.filechooser.FileFilter, so it can be used for GUIs as well as for other more general purposes.
ExtensionFileFilter keeps a default type, which can be used when saving a file when no file type was given (in the case of using ExtensionFileFilter as a javax.swing.filechooser.FileFilter). If a ExtensionFileFilter is constructed with the argument null for the default type, all file types will be accepted regardless of any additional added types; pattern matching will still take place.
As for the pattern matching capabilities:
By default, no pattern matching takes place until you explicitly add
include or exclude patterns. If any patterns are present (i.e.
getIncludePattern() or getExcludePattern() return an array with more than
zero elements), the file is loaded as a String into memory and is checked
against the given patterns. Note, therefore, that include/exclude patterns
should only be used for small/medium sized files; if a file is too big to
fit into memory to perform the pattern search, accept() will
return false.
If include and/or exclude patterns are set, a file is accepted by this
MyFilter only if all include patterns are found AND all exclude patterns
are not found in the file. If any patterns are set and - during pattern
matching - an IOException is caught, the file will not be accepted.
Note that include and/or exclude patterns should only be used if all files
that may run through the accept() method fit into memory.
| Constructor Summary | |
|---|---|
ExtensionFileFilter()
provides a default filter for text files (*.txt) |
|
ExtensionFileFilter(java.lang.String defaultExtensionType)
Creates a new ExtensionFileFilter object. |
|
ExtensionFileFilter(java.lang.String defaultType,
java.lang.String description)
if the defaultType is null, all files are initially accepted |
|
| Method Summary | |
|---|---|
boolean |
accept(java.io.File f)
checks file type and include/exclude pattern if applicable. |
boolean |
addExcludePattern(java.lang.String pattern)
adds a pattern to be excluded in a file to be accepted |
boolean |
addIncludePattern(java.lang.String pattern)
adds a pattern to be included in a file to be accepted |
boolean |
addType(java.lang.String type)
allows to add additional file types to be accepted by this filter. |
java.lang.String[] |
getAddedTypes()
returns file types other than the default type if they were added through addType(String). |
java.lang.String |
getDefaultType()
returns the default type for this filter |
java.lang.String |
getDescription()
DOCUMENT ME! |
java.lang.String[] |
getExcludePattern()
returns all exclude patterns to be checked (empty array returned if none) |
java.lang.String[] |
getIncludePattern()
returns all include patterns to be checked (empty array returned if none) |
void |
removeAllPattern()
removes all include and exclude patterns and ensures therefore that the accept() method doesn't have to load the content of a file |
boolean |
removeExcludePattern(java.lang.String pattern)
removes a pattern to be included in a file to be accepted |
boolean |
removeIncludePattern(java.lang.String pattern)
removes a pattern to be included in a file to be accepted |
boolean |
removeType(java.lang.String type)
removes previously added type. |
java.lang.String |
toString()
DOCUMENT ME! |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public ExtensionFileFilter()
public ExtensionFileFilter(java.lang.String defaultExtensionType)
defaultExtensionType - DOCUMENT ME!
public ExtensionFileFilter(java.lang.String defaultType,
java.lang.String description)
defaultType - a string specifying the default type (example: "txt");
the string will be converted to lowercasedescription - a string with a description (example: "Text files (*.txt)")| Method Detail |
|---|
public boolean addType(java.lang.String type)
getDefaultType()public boolean removeType(java.lang.String type)
getDefaultType()public java.lang.String[] getAddedTypes()
addType(String). Note that if the default
type is null, added types have no effect as all file types are then
accepted (unless restricted by patterns).
getDefaultType()public boolean addIncludePattern(java.lang.String pattern)
pattern - DOCUMENT ME!
public boolean addExcludePattern(java.lang.String pattern)
pattern - DOCUMENT ME!
public boolean removeIncludePattern(java.lang.String pattern)
pattern - DOCUMENT ME!
public boolean removeExcludePattern(java.lang.String pattern)
pattern - DOCUMENT ME!
public java.lang.String[] getIncludePattern()
public java.lang.String[] getExcludePattern()
public void removeAllPattern()
public boolean accept(java.io.File f)
accept in interface java.io.FileFilteraccept in class javax.swing.filechooser.FileFilterf - DOCUMENT ME!
public java.lang.String getDescription()
getDescription in class javax.swing.filechooser.FileFilterpublic java.lang.String getDefaultType()
public java.lang.String toString()
toString in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||