public class ExtensionFilenameFilter extends PtFilenameFilter
This class is provided in Ptolemy II to support usage with both java.awt.FileDialog and javax.swing.JFileChooser. As it appears that on MacOSX the FileDialog implementation is better than the JFileChooser, Ptolemy II has some logic in ptolemy.gui.PtGUIUtilities.useFileDialog() to decide which "file-picker"-component to use. Several Ptolemy II classes use this utility while still passing a common filter instance to the selected component. (e.g. ptolemy.gui.Query, ptolemy.gui.Top ...)
The javax.swing.filechooser.FileNameExtensionFilter in the JDK can only be used with JFileChooser.
Constructor and Description |
---|
ExtensionFilenameFilter(java.util.List<java.lang.String> extensions)
Construct a file filter that filters out all files that do not
have one of the extensions in the given list.
|
ExtensionFilenameFilter(java.lang.String[] extensions)
Construct a file filter that filters out all files that do not
have one of the extensions in the given list.
|
ExtensionFilenameFilter(java.lang.String[] extensions,
java.lang.String description)
Creates a filter that accepts the given file type, specified by
a number of extensions and a meaningful description of the file
types involved.
|
ExtensionFilenameFilter(java.lang.String description,
java.lang.String... extensions)
Creates a filter that accepts the given file type, specified by
a number of extensions and a meaningful description of the file
types involved.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(java.io.File file)
Return true if the given file has one of the registered
extensions, or is a directory.
|
boolean |
accept(java.io.File directory,
java.lang.String name)
Return true if the given file name has one of the registered
extensions, or is a directory.
|
java.lang.String |
getDescription()
A description of this FilenameFilter.
|
protected void |
registerExtension(java.lang.String extension)
Register an additional extension to accept.
|
void |
setDescription(java.lang.String description)
Set the human readable description of the types of files accepted by this
filter.
|
java.lang.String |
toString()
Get the description and the registered extensions.
|
public ExtensionFilenameFilter(java.util.List<java.lang.String> extensions)
extensions
- the file extensions to usepublic ExtensionFilenameFilter(java.lang.String[] extensions)
extensions
- the file extensions to usepublic ExtensionFilenameFilter(java.lang.String description, java.lang.String... extensions)
description
- a description of the types of files with one
of the given extensions.extensions
- the file extensions to usepublic ExtensionFilenameFilter(java.lang.String[] extensions, java.lang.String description)
extensions
- the file extensions to usedescription
- a description of the types of files with one
of the given extensionspublic boolean accept(java.io.File file)
Files whose name begins with "." are not accepted.
accept
in class PtFilenameFilter
file
- The file to be checked.public boolean accept(java.io.File directory, java.lang.String name)
Files whose name begins with "." are not accepted.
accept
in interface java.io.FilenameFilter
accept
in class PtFilenameFilter
directory
- the parent directory of the filename
- the name of the file.public java.lang.String getDescription()
PtFilenameFilter
getDescription
in class PtFilenameFilter
setDescription(String)
public void setDescription(java.lang.String description)
description
- the human readable description of the types
of files accepted by this filter.getDescription()
public java.lang.String toString()
toString
in class java.lang.Object
protected void registerExtension(java.lang.String extension)
extension
- The extension to be added.