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.FileFilterCreates 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 booleanaccept(java.io.File file)Returnstrueif the filter accepts the file; that is, if a file chooser using the filter would display the file.java.lang.StringgetDescription()Returns a human-friendly description of the filter.booleanmatches(java.lang.String extension)Returnstrueif the specified extension matches one of the extensions in the filter.java.lang.StringtoString()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 containnullelements
-
-
Method Detail
-
accept
public boolean accept(java.io.File file)
Returnstrueif the filter accepts the file; that is, if a file chooser using the filter would display the file.- Specified by:
acceptin classjavax.swing.filechooser.FileFilter- Parameters:
file- the file to test- Returns:
trueif 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:
getDescriptionin classjavax.swing.filechooser.FileFilter- Returns:
- a description of the file filter
-
matches
public boolean matches(java.lang.String extension)
Returnstrueif the specified extension matches one of the extensions in the filter.- Parameters:
extension- the extension (not including the '.' character)- Returns:
trueif 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:
toStringin classjava.lang.Object- Returns:
- a string describing the filter
-
-