|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.swing.filechooser.FileFilter
com.antelmann.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.
| Field Summary |
|---|
| Fields inherited from interface com.antelmann.util.Filter |
|---|
EXCLUDE_ALL_FILTER, INCLUDE_ALL_FILTER |
| Constructor Summary | |
|---|---|
ExtensionFileFilter()
provides a default filter for text files (*.txt) |
|
ExtensionFileFilter(ExtensionFileFilter filter)
|
|
ExtensionFileFilter(String defaultExtensionType)
|
|
ExtensionFileFilter(String defaultType,
String description)
calls ExtensionFileFilter(defaultType, description, true) |
|
ExtensionFileFilter(String defaultType,
String description,
boolean acceptDirectories)
if the defaultType is null, all files are initially accepted |
|
| Method Summary | |
|---|---|
boolean |
accept(File f)
checks file type and include/exclude pattern if applicable. |
boolean |
accept(File dir,
String name)
|
boolean |
addExcludePattern(String pattern)
adds a pattern to be excluded in a file to be accepted |
boolean |
addIncludePattern(String pattern)
adds a pattern to be included in a file to be accepted |
ExtensionFileFilter |
addType(String... type)
allows to add additional file types to be accepted by this filter. |
boolean |
getAcceptDirectories()
|
String[] |
getAddedTypes()
returns file types other than the default type if they were added through addType(String). |
String |
getDefaultType()
returns the default type for this filter |
String |
getDescription()
|
String[] |
getExcludePattern()
returns all exclude patterns to be checked (empty array returned if none) |
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(String pattern)
removes a pattern to be included in a file to be accepted |
boolean |
removeIncludePattern(String pattern)
removes a pattern to be included in a file to be accepted |
boolean |
removeType(String type)
removes previously added type. |
void |
setAcceptDirectories(boolean flag)
|
String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public ExtensionFileFilter(ExtensionFileFilter filter)
public ExtensionFileFilter()
public ExtensionFileFilter(String defaultExtensionType)
public ExtensionFileFilter(String defaultType,
String description)
public ExtensionFileFilter(String defaultType,
String description,
boolean acceptDirectories)
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)")acceptDirectories - if true, directories are accepted by this filter| Method Detail |
|---|
public void setAcceptDirectories(boolean flag)
public boolean getAcceptDirectories()
public ExtensionFileFilter addType(String... type)
getDefaultType()public boolean removeType(String type)
getDefaultType()public 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(String pattern)
public boolean addExcludePattern(String pattern)
public boolean removeIncludePattern(String pattern)
public boolean removeExcludePattern(String pattern)
public String[] getIncludePattern()
public String[] getExcludePattern()
public void removeAllPattern()
public boolean accept(File dir,
String name)
accept in interface FilenameFilterpublic boolean accept(File f)
accept in interface Filter<File>accept in interface FileFilteraccept in class FileFilterpublic String getDescription()
getDescription in class FileFilterpublic String getDefaultType()
public String toString()
toString in class Object
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||