Package org.sm.smtools.util
Class JFileFilter
java.lang.Object
javax.swing.filechooser.FileFilter
org.sm.smtools.util.JFileFilter
public final class JFileFilter
extends javax.swing.filechooser.FileFilter
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
Constructors Constructor Description JFileFilter()
Constructs aJFileFilter
object.JFileFilter(java.lang.String extension)
Constructs aJFileFilter
object for the specified single file extension.JFileFilter(java.lang.String extension, java.lang.String description)
Constructs aJFileFilter
object for the specified single file extension.JFileFilter(java.util.ArrayList<java.lang.String> extensions)
Constructs aJFileFilter
object for the specified multiple file extensions.JFileFilter(java.util.ArrayList<java.lang.String> extensions, java.lang.String description)
Constructs aJFileFilter
object for the specified multiple file extensions. -
Method Summary
Modifier and Type Method Description boolean
accept(java.io.File f)
Returns whether or not a specified file is accepted by the filter.void
addExtension(java.lang.String extension)
Adds the specified extension to the file filter.static boolean
fileExists(java.lang.String filename)
Returns whether or not a file with the specified filename exists (and is not a directory).java.lang.String
getDescription()
Returns the description of the file filter.java.lang.String
getExtension(java.io.File f)
Returns the extension of a specified file.boolean
isExtensionListInDescription()
Returns whether or not the accepted extensions of the file filter are appended to the description.void
setDescription(java.lang.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.Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
JFileFilter
public JFileFilter()Constructs aJFileFilter
object. -
JFileFilter
public JFileFilter(java.lang.String extension)Constructs aJFileFilter
object for the specified single file extension.- Parameters:
extension
- the filetype (i.e., extension) to allow
-
JFileFilter
public JFileFilter(java.lang.String extension, java.lang.String description)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
public JFileFilter(java.util.ArrayList<java.lang.String> extensions)Constructs aJFileFilter
object for the specified multiple file extensions.- Parameters:
extensions
- the different filetypes (i.e., extensions) to allow
-
JFileFilter
public JFileFilter(java.util.ArrayList<java.lang.String> extensions, java.lang.String description)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
public boolean accept(java.io.File f)Returns whether or not a specified file is accepted by the filter.Note that this method accepts directories by default.
- Specified by:
accept
in classjavax.swing.filechooser.FileFilter
- Returns:
true
if the specified file is accepted by the filter,false
otherwise
-
getExtension
public java.lang.String getExtension(java.io.File f)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
public void addExtension(java.lang.String extension)Adds the specified extension to the file filter.- Parameters:
extension
- the extension to add to thisJFileFilter
object
-
getDescription
public java.lang.String 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 classjavax.swing.filechooser.FileFilter
- Returns:
- the description of the file filter
-
setDescription
public void setDescription(java.lang.String description)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
public static boolean fileExists(java.lang.String filename)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
-