public class Regex_Filename_Filter
extends javax.swing.filechooser.FileFilter
implements java.io.FilenameFilter
FilenameFilter
, these regular expressions are used in comparison
tests to filter directory listings in the list methods of the
File
class and by the AWT FileDialog
component. As a FileFilter
, they are used by the Swing JFileChooser
.Basic_Filename_Filter
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ID
Class identification name with source code version and date.
|
Constructor and Description |
---|
Regex_Filename_Filter()
Creates a new filter with an empty regex list and no description.
|
Regex_Filename_Filter(java.lang.String[] regexes,
java.lang.String description)
Creates a new filter with the specified set of regexes and the given
description.
|
Regex_Filename_Filter(java.lang.String regex,
java.lang.String description)
Creates a new filter with the single specified regex and the given
description.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(java.io.File file)
Tests whether the specified file is accepted by this filter.
|
boolean |
accept(java.io.File directory,
java.lang.String name)
Tests whether the specified file is accepted by this filter.
|
void |
addRegex(java.lang.String regex)
Adds a single regex to the list of regexes currently used by this filter.
|
java.lang.String |
getDescription()
Gets the description of this filter.
|
java.lang.String[] |
getRegexes()
Gets the list of regexes currently used by the filter.
|
java.lang.String |
removeRegex(java.lang.String regex)
Removes a single regex from the list of regexes currently used by this
filter.
|
void |
setDescription(java.lang.String description)
Sets the description of this filter.
|
void |
setRegexes(java.lang.String... regexes)
Sets the list of regexes currently used by this filter.
|
public static final java.lang.String ID
public Regex_Filename_Filter()
public Regex_Filename_Filter(java.lang.String regex, java.lang.String description)
regex
- a filename regex; may be null.description
- the description of this filter; may be null.public Regex_Filename_Filter(java.lang.String[] regexes, java.lang.String description)
regexes
- a set of filename regexes; may be null.description
- the description of this filter; may be null.public java.lang.String[] getRegexes()
public void setRegexes(java.lang.String... regexes)
regexes
- the regexes this filter is to use; if this value is
null, all regexes will be removed and the filter will
accept all filenames.public java.lang.String getDescription()
getDescription
in class javax.swing.filechooser.FileFilter
public void setDescription(java.lang.String description)
description
- the new description.public boolean accept(java.io.File file)
name
portion of this file is tested;
the path
is not.
If file is null, this method returns false.
If file is a directory, this method returns true.
If this filter's list of regexes is empty, this method returns true.
If file's name matches any of this filter's regexes, this method returns true.
Otherwise, this method returns false.
accept
in class javax.swing.filechooser.FileFilter
file
- the file in question.public boolean accept(java.io.File directory, java.lang.String name)
If name is null, this method returns false.
If this filter's list of regexes is empty, this method returns true.
If name matches any of this filter's regexes, this method returns true.
Otherwise, this method returns false.
accept
in interface java.io.FilenameFilter
directory
- the directory in which the file was found.name
- the file's name.public void addRegex(java.lang.String regex)
regex
- the regex to add to the list of regexes; may be null.public java.lang.String removeRegex(java.lang.String regex)
regex
- the regex to remove from the list of regexes; may be
null.Copyright \ (C) Arizona Board of Regents on behalf of the \ Planetary Image Research Laboratory, Lunar and \ Planetary Laboratory at the University of Arizona