public class ExtensionFileFilter extends javax.swing.filechooser.FileFilter implements java.io.FileFilter, java.io.FilenameFilter
FileFilter
and implements
both the Java I/O interfaces FileFilter
and FilenameFilter
. It implements functionality similar
to that of FileNameExtensionFilter
but offers more features and allows extending this class, which is
prohibited by FileNameExtensionFilter
.Modifier and Type | Field and Description |
---|---|
static char |
EXTENSION_SEPARATOR
The character separating an extension from the file name.
|
Constructor and Description |
---|
ExtensionFileFilter(java.lang.String description,
boolean addExtensionListToDescription,
java.util.List<java.lang.String> extensions)
Creates a new instance of this class.
|
ExtensionFileFilter(java.lang.String description,
boolean addExtensionListToDescription,
java.lang.String... extensions)
Creates a new instance of this class.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(java.io.File f)
This default implementation accepts all files that are directories or that end with one of the defined extensions.
|
boolean |
accept(java.io.File dir,
java.lang.String name)
|
java.lang.String |
getDefaultExtension()
Returns the default file extension of this filter.
|
java.lang.String |
getDescription() |
java.util.List<java.lang.String> |
getExtensions()
Returns a list of all extensions accepted by this filter.
|
java.lang.String |
getExtensionsAsString()
Returns all extensions stored in this filter as a single string.
|
public static final char EXTENSION_SEPARATOR
public ExtensionFileFilter(java.lang.String description, boolean addExtensionListToDescription, java.lang.String... extensions)
description
- the description of this file type to be displayed e.g. in open dialogsaddExtensionListToDescription
- Specify true
here, if a list of valid extensions shall be appended
on the specified description in parentheses.extensions
- one and possibly additional alternative extensions accepted by this filter (All file extension
should be specified without a leading '.'
.)java.lang.NullPointerException
- if description
or any specified extension are null
java.lang.IllegalArgumentException
- if not at least one extension has been specifiedpublic ExtensionFileFilter(java.lang.String description, boolean addExtensionListToDescription, java.util.List<java.lang.String> extensions)
description
- the description of this file type to be displayed e.g. in open dialogsaddExtensionListToDescription
- Specify true
here, if a list of valid extensions shall be appended
on the specified description in parentheses.extensions
- one and possibly additional alternative extensions accepted by this filter (All file extension
should be specified without a leading '.'
.)java.lang.NullPointerException
- if description
or any specified extension are null
java.lang.IllegalArgumentException
- if not at least one extension has been specifiedpublic java.lang.String getExtensionsAsString()
Example: If the extensions jpeg
, jpg
and jpe
would be have been passed to the constructor
of this class, the return value would be "*.jpeg;*.jpg;*.jpe
" (The path separator used, would depending on the
operating system).
public boolean accept(java.io.File f)
Inherited classes may add additional functionality to this method by overwriting, if the specified file extensions are ambiguous.
accept
in interface java.io.FileFilter
accept
in class javax.swing.filechooser.FileFilter
FileFilter.accept(java.io.File)
,
FileFilter.accept(File)
public boolean accept(java.io.File dir, java.lang.String name)
accept
in interface java.io.FilenameFilter
FilenameFilter.accept(java.io.File, java.lang.String)
public java.lang.String getDescription()
getDescription
in class javax.swing.filechooser.FileFilter
public java.lang.String getDefaultExtension()
'.'
public java.util.List<java.lang.String> getExtensions()
getDefaultExtension()
.