de.jstacs.io
Class RegExFilenameFilter

java.lang.Object
  extended by javax.swing.filechooser.FileFilter
      extended by de.jstacs.io.RegExFilenameFilter
All Implemented Interfaces:
FileFilter, FilenameFilter

public class RegExFilenameFilter
extends FileFilter
implements FileFilter, FilenameFilter

A simple filter on Files that accepts Files with a specific regular expression in the filename.

Author:
Jens Keilwagen
See Also:
String.matches(String), Pattern

Nested Class Summary
static class RegExFilenameFilter.Directory
          A switch to decide whether the results of a RegExFilenameFilter are forbidden, allowed or required to be a directory.
 
Constructor Summary
RegExFilenameFilter(String desc, RegExFilenameFilter.Directory dir, boolean ignoreCase, String... regex)
          Creates a new RegExFilenameFilter with given regular expressions regex to be found in the file name of the Files to be filtered.
 
Method Summary
 boolean accept(File arg0)
           
 boolean accept(File dir, String name)
           
 String getDescription()
           
 String getRegEx()
          Returns a representation of all used regular expressions.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RegExFilenameFilter

public RegExFilenameFilter(String desc,
                           RegExFilenameFilter.Directory dir,
                           boolean ignoreCase,
                           String... regex)
Creates a new RegExFilenameFilter with given regular expressions regex to be found in the file name of the Files to be filtered.

Parameters:
desc - the description of the filter, e.g. "text-files (*.txt)"
dir - a switch whether the results are forbidden, allowed or required to be a directory
ignoreCase - indicates whether to ignore the case of the file names or not
regex - an array of regular expressions; at least one regular expression has to match the file name
Method Detail

accept

public boolean accept(File arg0)
Specified by:
accept in interface FileFilter
Specified by:
accept in class FileFilter

accept

public boolean accept(File dir,
                      String name)
Specified by:
accept in interface FilenameFilter

getDescription

public String getDescription()
Specified by:
getDescription in class FileFilter

getRegEx

public String getRegEx()
Returns a representation of all used regular expressions.

Returns:
a representation of all used regular expressions

toString

public String toString()
Overrides:
toString in class Object