|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.swing.filechooser.FileFilter
bb.io.filefilter.FilenameSuffixFilter
public abstract class FilenameSuffixFilter
This abstract class is meant to provide all the base functionality for file filters
which accept or reject File
s depending on how their names end.
This class must be constructed
with a String[] of file name suffix patterns.
A normal file is always accepted if the suffix of its name matches one of the patterns in the array.
The matching of the filename suffix to a pattern String is done char by char.
A boolean arg to the constructor specifies whether or not the matching is case insensitive.
This class's constructor must also take an int arg that specifies how to treat directories. The possibilities are:
FilenameSuffixFilter(java.lang.String[], boolean, int)
for details).
Concrete subclasses typically just need to define (and supply to this class's constructor) an array of suffixes, as well as implement the getDescription method.
Note that this class is both a subclass of javax.swing.filechooser.FileFilter
(so that it can be passed to JFileChooser
),
as well as an implementation of java.io.FileFilter
(so that it is suitable as an argument to File.listFiles
).
This class is multithread safe: it is immutable (both its immediate state, as well as the deep state of its fields).
Nested Class Summary | |
---|---|
static class |
FilenameSuffixFilter.UnitTest
See the Overview page of the project's javadocs for a general description of this unit test class. |
Field Summary | |
---|---|
static int |
acceptDirectories
Specifies that every directory will be accepted, regardless of its name. |
private boolean |
caseSensitive
|
private int |
directoryTreatment
|
private String[] |
filenameSuffixes
|
static int |
filterDirectoriesBySuffix
Specifies that every directory will be subjected to the same name suffix test as normal files. |
static int |
rejectDirectories
Specifies that every directory will be rejected, regardless of its name. |
Constructor Summary | |
---|---|
FilenameSuffixFilter(String[] filenameSuffixes,
boolean caseSensitive,
int directoryTreatment)
Constructs a new FilenameSuffixFilter instance. |
Method Summary | |
---|---|
boolean |
accept(File file)
Reports whether or not the supplied File is accepted by this filter. |
abstract String |
getDescription()
Returns a description of this filter. |
String[] |
getSuffixes()
Returns a clone of the array of filenameSuffixes that are used to match files. |
protected boolean |
isValidDirectoryTreatment(int directoryTreatment)
Reports whether or not the directoryTreatment arg is a valid value. |
static String |
makeDescription(String intro,
String[] suffixes)
Returns a String that consists of the intro arg followed by the Strings in the suffixes arg. |
protected boolean |
suffixMatches(String fileName)
Reports whether or not the supplied fileName's suffix matches one of the patterns. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int rejectDirectories
public static final int filterDirectoriesBySuffix
public static final int acceptDirectories
private final String[] filenameSuffixes
private final boolean caseSensitive
private final int directoryTreatment
Constructor Detail |
---|
public FilenameSuffixFilter(String[] filenameSuffixes, boolean caseSensitive, int directoryTreatment) throws IllegalArgumentException
filenameSuffixes
- String[] of filename suffix patterns that if a file matches, result in the file being accepted;
for top performance, place the most frequently encountered patterns earliest in the arraycaseSensitive
- specifies whether or not the filename suffix comparison is to be case sensitivedirectoryTreatment
- an int that must be one of the following constants of this class:
rejectDirectories
,
filterDirectoriesBySuffix
, or
acceptDirectories
IllegalArgumentException
- if filenameSuffixes is null or 0-length, or if directoryTreatment is invalidMethod Detail |
---|
public String[] getSuffixes()
protected boolean isValidDirectoryTreatment(int directoryTreatment)
public boolean accept(File file) throws IllegalArgumentException, SecurityException
accept
in interface FileFilter
accept
in class FileFilter
IllegalArgumentException
- if file is null
SecurityException
- if a security manager exists and its SecurityManager.checkRead(java.lang.String) method denies read access to the fileprotected boolean suffixMatches(String fileName)
public abstract String getDescription()
getDescription
in class FileFilter
public static String makeDescription(String intro, String[] suffixes) throws IllegalArgumentException
This method is a convenience method to help subclasses generate a description of what file types they filter.
IllegalArgumentException
- if intro or arg suffixes is null
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |