HiRISE

HiRISE.HiPlan.IO
Class Regex_Filename_Filter

java.lang.Object
  extended by javax.swing.filechooser.FileFilter
      extended by HiRISE.HiPlan.IO.Regex_Filename_Filter
All Implemented Interfaces:
FilenameFilter

public class Regex_Filename_Filter
extends FileFilter
implements FilenameFilter

A filename filter based on regular expressions. An instance of this class contains a user-configurable list of filename test regular expressions. As a 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.

Version:
1.5
Author:
Christian Schaller - UA/PIRL
See Also:
Basic_Filename_Filter

Field Summary
static String ID
          Class identification name with source code version and date.
 
Constructor Summary
Regex_Filename_Filter()
          Creates a new filter with an empty regex list and no description.
Regex_Filename_Filter(String[] regexes, String description)
          Creates a new filter with the specified set of regexes and the given description.
Regex_Filename_Filter(String regex, String description)
          Creates a new filter with the single specified regex and the given description.
 
Method Summary
 boolean accept(File file)
          Tests whether the specified file is accepted by this filter.
 boolean accept(File directory, String name)
          Tests whether the specified file is accepted by this filter.
 void addRegex(String regex)
          Adds a single regex to the list of regexes currently used by this filter.
 String getDescription()
          Gets the description of this filter.
 String[] getRegexes()
          Gets the list of regexes currently used by the filter.
 String removeRegex(String regex)
          Removes a single regex from the list of regexes currently used by this filter.
 void setDescription(String description)
          Sets the description of this filter.
 void setRegexes(String... regexes)
          Sets the list of regexes currently used by this filter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ID

public static final String ID
Class identification name with source code version and date.

See Also:
Constant Field Values
Constructor Detail

Regex_Filename_Filter

public Regex_Filename_Filter()
Creates a new filter with an empty regex list and no description.


Regex_Filename_Filter

public Regex_Filename_Filter(String regex,
                             String description)
Creates a new filter with the single specified regex and the given description.

Parameters:
regex - a filename regex; may be null.
description - the description of this filter; may be null.

Regex_Filename_Filter

public Regex_Filename_Filter(String[] regexes,
                             String description)
Creates a new filter with the specified set of regexes and the given description.

Parameters:
regexes - a set of filename regexes; may be null.
description - the description of this filter; may be null.
Method Detail

getRegexes

public String[] getRegexes()
Gets the list of regexes currently used by the filter.

Returns:
the regexes this filter uses; or null if the filter currently has no regexes.

setRegexes

public void setRegexes(String... regexes)
Sets the list of regexes currently used by this filter. Any pre-existing regexes are removed in the process.

Parameters:
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.

getDescription

public String getDescription()
Gets the description of this filter.

Specified by:
getDescription in class FileFilter
Returns:
the filter's description.

setDescription

public void setDescription(String description)
Sets the description of this filter.

Parameters:
description - the new description.

accept

public boolean accept(File file)
Tests whether the specified file is accepted by this filter. If the file is accepted (i.e., if this method returns true), the file will be listed. Only the 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.

Specified by:
accept in class FileFilter
Parameters:
file - the file in question.
Returns:
true if the file's name matches a regex of this filter; false otherwise.

accept

public boolean accept(File directory,
                      String name)
Tests whether the specified file is accepted by this filter. If the file is accepted (i.e., if this method returns true), the file will be listed. Only the name is considered; the directory is ignored.

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.

Specified by:
accept in interface FilenameFilter
Parameters:
directory - the directory in which the file was found.
name - the file's name.
Returns:
true if the filename matches a regex of this filter; false otherwise.

addRegex

public void addRegex(String regex)
Adds a single regex to the list of regexes currently used by this filter. If regex is null, this method does nothing.

Parameters:
regex - the regex to add to the list of regexes; may be null.

removeRegex

public String removeRegex(String regex)
Removes a single regex from the list of regexes currently used by this filter.

Parameters:
regex - the regex to remove from the list of regexes; may be null.
Returns:
the regex removed or null if the regex did not exist in the list.

HiRISE

Copyright (C) Arizona Board of Regents on behalf of the Planetary Image Research Laboratory, Lunar and Planetary Laboratory at the University of Arizona