Package org.sm.smtools.util
Class JFileFilter
java.lang.Object
javax.swing.filechooser.FileFilter
org.sm.smtools.util.JFileFilter
The
JFileFilter
class provides selection filter for the JFileChooser
class.
This file filter can handle multiple file types (i.e., extensions) belonging to the same collective description.
Note that this class cannot be subclassed!
- Version:
- 16/08/2019
- Author:
- Sven Maerivoet
-
Constructor Summary
ConstructorDescriptionConstructs aJFileFilter
object.JFileFilter
(String extension) Constructs aJFileFilter
object for the specified single file extension.JFileFilter
(String extension, String description) Constructs aJFileFilter
object for the specified single file extension.JFileFilter
(ArrayList<String> extensions) Constructs aJFileFilter
object for the specified multiple file extensions.JFileFilter
(ArrayList<String> extensions, String description) Constructs aJFileFilter
object for the specified multiple file extensions. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns whether or not a specified file is accepted by the filter.void
addExtension
(String extension) Adds the specified extension to the file filter.static boolean
fileExists
(String filename) Returns whether or not a file with the specified filename exists (and is not a directory).Returns the description of the file filter.getExtension
(File f) Returns the extension of a specified file.boolean
Returns whether or not the accepted extensions of the file filter are appended to the description.void
setDescription
(String description) Sets the description of the file filter.void
setExtensionListInDescription
(boolean b) Sets whether or not the accepted extensions of the file filter should be appended to the description.
-
Constructor Details
-
JFileFilter
public JFileFilter()Constructs aJFileFilter
object. -
JFileFilter
Constructs aJFileFilter
object for the specified single file extension.- Parameters:
extension
- the filetype (i.e., extension) to allow
-
JFileFilter
Constructs aJFileFilter
object for the specified single file extension.The specified
description
is substituted in theJFileChooser
's dialog box.- Parameters:
extension
- the filetype (i.e., extension) to allowdescription
- the description of the filetype
-
JFileFilter
Constructs aJFileFilter
object for the specified multiple file extensions.- Parameters:
extensions
- the different filetypes (i.e., extensions) to allow
-
JFileFilter
Constructs aJFileFilter
object for the specified multiple file extensions.The specified
description
is substituted in theJFileChooser
's dialog box.- Parameters:
extensions
- the different filetypes (i.e., extensions) to allowdescription
- the collective description of the different filetypes
-
-
Method Details
-
accept
Returns whether or not a specified file is accepted by the filter.Note that this method accepts directories by default.
- Specified by:
accept
in classFileFilter
- Returns:
true
if the specified file is accepted by the filter,false
otherwise
-
getExtension
Returns the extension of a specified file.The extension of a file is everything that follows after the last dot of the filename.
- Parameters:
f
- the file to check- Returns:
- the extension of a specified file
-
addExtension
Adds the specified extension to the file filter.- Parameters:
extension
- the extension to add to thisJFileFilter
object
-
getDescription
Returns the description of the file filter.Note that the file filter's extensions can be listed in the description (using the
setExtensionListInDescription(boolean)
method).- Specified by:
getDescription
in classFileFilter
- Returns:
- the description of the file filter
-
setDescription
Sets the description of the file filter.- Parameters:
description
- the description of the file filter
-
setExtensionListInDescription
public void setExtensionListInDescription(boolean b) Sets whether or not the accepted extensions of the file filter should be appended to the description.- Parameters:
b
- aboolean
flag indicating whether or not extensions should be appended to the description
-
isExtensionListInDescription
public boolean isExtensionListInDescription()Returns whether or not the accepted extensions of the file filter are appended to the description.- Returns:
true
when extensions are appended to the description,false
otherwise
-
fileExists
Returns whether or not a file with the specified filename exists (and is not a directory).- Parameters:
filename
- the filename to check for- Returns:
true
when a file with the specified filename exists (and is not a directory),false
otherwise
-