Package ca.cgjennings.ui
Class FileNameExtensionFilter
- java.lang.Object
-
- javax.swing.filechooser.FileFilter
-
- ca.cgjennings.ui.FileNameExtensionFilter
-
public final class FileNameExtensionFilter extends javax.swing.filechooser.FileFilter
Creates a file filter for a specified file type. The filter takes a description of the file type and a list of matching extensions and creates a suitable filter for the file type and filters out files that do not match the extension (folders are not filtered out, to allow navigation).- Since:
- 3.0
- Author:
- Chris Jennings
-
-
Constructor Summary
Constructors Constructor Description FileNameExtensionFilter(java.lang.String fileTypeDescription, java.lang.String... fileNameExtensions)
Creates a file name filter for files that match the specified extensions.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
accept(java.io.File file)
Returnstrue
if the filter accepts the file; that is, if a file chooser using the filter would display the file.java.lang.String
getDescription()
Returns a human-friendly description of the filter.boolean
matches(java.lang.String extension)
Returnstrue
if the specified extension matches one of the extensions in the filter.java.lang.String
toString()
Returns a string description of the filter for debugging purposes.
-
-
-
Constructor Detail
-
FileNameExtensionFilter
public FileNameExtensionFilter(java.lang.String fileTypeDescription, java.lang.String... fileNameExtensions)
Creates a file name filter for files that match the specified extensions. The provided description will be used as part of a description of the file type, but the exact description may vary by platform.- Parameters:
fileTypeDescription
- the file type descriptionfileNameExtensions
- file extensions to accept; may not benull
, empty, or containnull
elements
-
-
Method Detail
-
accept
public boolean accept(java.io.File file)
Returnstrue
if the filter accepts the file; that is, if a file chooser using the filter would display the file.- Specified by:
accept
in classjavax.swing.filechooser.FileFilter
- Parameters:
file
- the file to test- Returns:
true
if the file represents a folder or matches one of the filter's extensions
-
getDescription
public java.lang.String getDescription()
Returns a human-friendly description of the filter.- Specified by:
getDescription
in classjavax.swing.filechooser.FileFilter
- Returns:
- a description of the file filter
-
matches
public boolean matches(java.lang.String extension)
Returnstrue
if the specified extension matches one of the extensions in the filter.- Parameters:
extension
- the extension (not including the '.' character)- Returns:
true
if the extension matches one of the extensions accepted by this filter
-
toString
public java.lang.String toString()
Returns a string description of the filter for debugging purposes.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string describing the filter
-
-