public class ExtFilenameFilter extends java.lang.Object implements java.io.FilenameFilter, java.io.FileFilter
Modified by: Joseph A. Huwaldt
Constructor and Description |
---|
ExtFilenameFilter()
Creates a filename filter.
|
ExtFilenameFilter(java.lang.String... filters)
Creates a file filter from the given string array.
|
ExtFilenameFilter(java.lang.String extension)
Creates a filename filter that accepts files with the given extension.
|
ExtFilenameFilter(java.lang.String[] filters,
java.lang.String description)
Creates a file filter from the given string array and description.
|
ExtFilenameFilter(java.lang.String extension,
java.lang.String description)
Creates a file filter that accepts the given file type.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(java.io.File f)
Return true if this file should be shown , false if it should not.
|
boolean |
accept(java.io.File dir,
java.lang.String name)
Return true if this file should be included in a file list, false if it shouldn't.
|
void |
addExtension(java.lang.String extension)
Adds a file name "dot" extension to filter against.
|
void |
addExtensions(java.lang.String extensionList)
Adds a list of extensions parsed from a comma, space or tab delimited list.
|
void |
addFilename(java.lang.String fileName)
Adds a full filename to filter against.
|
java.lang.String |
getDescription()
Returns the human readable description of this filter.
|
static java.lang.String |
getExtension(java.io.File f)
Return the extension portion of the file's name.
|
static java.lang.String |
getExtension(java.lang.String name)
Return the extension portion of the file's name.
|
boolean |
isExtensionListInDescription()
Returns whether the extension list (.jpg,.gif, etc) should show up in the human
readable description.
|
void |
setDescription(java.lang.String description)
Sets the human readable description of this filter.
|
void |
setExtensionListInDescription(boolean useExtInDescription)
Determines whether the extension list (.jpg,.gif, etc) should show up in the human
readable description.
|
public ExtFilenameFilter()
addExtension(java.lang.String)
public ExtFilenameFilter(java.lang.String extension)
extension
- The file name extension to use for this filter. Null extensions
are ignored.addExtension(java.lang.String)
public ExtFilenameFilter(java.lang.String extension, java.lang.String description)
new ExtFilenameFilter("jpg", "JPEG Image Images");
Note that the "." before the extension is not needed, but it is fine if it is there.
extension
- The file name extension to use for this filter. Null extensions
are ignored.description
- A description of the file type of this filter. Null is fine.addExtension(java.lang.String)
public ExtFilenameFilter(java.lang.String... filters)
new ExtFilenameFilter(String {"gif", "jpg"});
Note that the "." before the extension is not needed, but it is fine if it is there.
filters
- An array of String objects where each entry is a file name extension
to be included in this filter. May not be null.addExtension(java.lang.String)
public ExtFilenameFilter(java.lang.String[] filters, java.lang.String description)
new ExtFilenameFilter(String {"gif", "jpg"}, "Gif and JPG Images");
Note that the "." before the extension is not needed, but it is fine if it is there.
filters
- An array of String objects where each entry is a file name
extension to be included in this filter. Any null members of the
array are ignored. The array itself may not be null.description
- The description of the extensions in this filter set. Null is
fine.addExtension(java.lang.String)
public boolean accept(java.io.File f)
accept
in interface java.io.FileFilter
f
- The file that is to be tested for compatibility with this filter.public boolean accept(java.io.File dir, java.lang.String name)
accept
in interface java.io.FilenameFilter
dir
- The directory in which the file was found.name
- The name of the file.public static java.lang.String getExtension(java.lang.String name)
name
- The file name for which the extension is to be returned. May not be
null.getExtension(java.io.File)
public static java.lang.String getExtension(java.io.File f)
f
- The file object for which the extension is to be returned. May not be
null.getExtension(java.lang.String)
public final void addExtension(java.lang.String extension)
For example: the following code will create a filter that filters out all files except those that end in ".jpg" and ".tif":
ExtFilenameFilter filter = new ExtFilenameFilter(); filter.addExtension("jpg"); filter.addExtension("tif");
Note that the "." before the extension is not needed, but it is fine if it is there.
extension
- The file name extension to be added to this filter. May not be
null.public void addFilename(java.lang.String fileName)
For example: the following code will create a filter that filters out all files except those that end in ".jpg" and ".tif" or have the name "foo.bar":
ExtFilenameFilter filter = new ExtFilenameFilter(); filter.addExtension("jpg"); filter.addExtension("tif"); filter.addFileName("foo.bar");
fileName
- A full file name to add to this filter for filtering against. May
not be null.public void addExtensions(java.lang.String extensionList)
For example, the following will create a filter that filters out all files except those that end in ".jpg" and ".png":
ExtFilenameFilter filter = new ExtFilenameFilter(); filter.addExtensions("jpg,png,gif");
extensionList
- A delimited list of extensions to add to the filter. May not
be null.public java.lang.String getDescription()
setDescription(java.lang.String)
,
setExtensionListInDescription(boolean)
,
isExtensionListInDescription()
public final void setDescription(java.lang.String description)
description
- The description to be used for this filter. Null is fine.setDescription(java.lang.String)
,
setExtensionListInDescription(boolean)
,
isExtensionListInDescription()
public void setExtensionListInDescription(boolean useExtInDescription)
Only relevant if a description was provided in the constructor or using
setDescription()
useExtInDescription
- Set to true to use the extension list in the description
of this filter.getDescription()
,
setDescription(java.lang.String)
,
isExtensionListInDescription()
public boolean isExtensionListInDescription()
setDescription()
getDescription()
,
setDescription(java.lang.String)
,
setExtensionListInDescription(boolean)