public class FileExtensionFilter
extends javax.swing.filechooser.FileFilter
Provides a filter for a JFileChooser
to filter files by file extensions. This class is used together with the JFileChooser
by the class FileSelector
.
Modifier and Type | Field and Description |
---|---|
private java.util.ArrayList<java.lang.String> |
allowedExtensions |
private java.util.ArrayList<java.util.regex.Pattern> |
patterns |
private java.lang.String |
type |
Constructor and Description |
---|
FileExtensionFilter(java.lang.String type)
Creates a new file extension filter for a file chooser filtering files by the given file type.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(java.io.File file) |
java.lang.String |
getDescription()
Returns a list of comma-separated, allowed file extensions.
|
java.lang.String |
getType()
Returns the file extension bound to this filter.
|
private void |
init()
Initializes the allowed file extensions and regex patterns according to the file type.
|
private java.lang.String type
private java.util.ArrayList<java.util.regex.Pattern> patterns
private java.util.ArrayList<java.lang.String> allowedExtensions
public FileExtensionFilter(java.lang.String type)
Creates a new file extension filter for a file chooser filtering files by the given file type.
type
- File type to be filtered.private void init()
Initializes the allowed file extensions and regex patterns according to the file type.
public boolean accept(java.io.File file)
accept
in class javax.swing.filechooser.FileFilter
public java.lang.String getDescription()
Returns a list of comma-separated, allowed file extensions. Every extension is preceeded by ’*.’
Example: - *.mid, *.midi, *.kar
getDescription
in class javax.swing.filechooser.FileFilter
public java.lang.String getType()
Returns the file extension bound to this filter.