org.dmonix.io.filters
Class RegExpFilter

java.lang.Object
  extended byjavax.swing.filechooser.FileFilter
      extended byorg.dmonix.io.filters.RegExpFilter
All Implemented Interfaces:
java.io.FileFilter, java.io.FilenameFilter
Direct Known Subclasses:
FileExtensionFilter

public class RegExpFilter
extends javax.swing.filechooser.FileFilter
implements java.io.FileFilter, java.io.FilenameFilter

A file filter that uses regular expression matching.
The filter compares the absolute path name of the file towards the provided regular expression.
As well as implementing the FileFilter and FilenameFilter interfaces the class also extends the javax.swing.filechooser.FileFilter class.
This way the filter can be used in all standard file filtering as well as in conjunction with the JFileChooser class.

Copyright: Copyright (c) 2004

Company: dmonix.org

Version:
1.1
Author:
Peter Nerg

Constructor Summary
protected RegExpFilter()
           
  RegExpFilter(java.util.regex.Pattern filter)
          Creates a filter using the provided pattern.
  RegExpFilter(java.lang.String regex)
          Creates a filter using the provided regular expression.
  RegExpFilter(java.lang.String regex, boolean caseSensitive)
          Creates a filter using the provided regular expression.
 
Method Summary
 boolean accept(java.io.File f)
          The method will match the absolute file path towards the regular expression pattern.
 boolean accept(java.io.File dir, java.lang.String name)
          The method will match the absolute file path towards the regular expression pattern.
 java.lang.String getDescription()
          Returns the description of the currently used pattern.
 java.util.regex.Pattern getPattern()
          Get the pattern that is used by this filter.
 void setDescription(java.lang.String s)
          Set the description of the filter.
 void setPattern(java.util.regex.Pattern filter)
          Set the pattern that is to be used by this filter.
 void setPattern(java.lang.String regex)
          Set the pattern that is to be used by this filter.
 void setPattern(java.lang.String regex, boolean caseSensitive)
          Set the pattern that is to be used by this filter.
 java.lang.String toString()
          Returns the string representation of the currently used regular expression pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RegExpFilter

public RegExpFilter(java.lang.String regex)
Creates a filter using the provided regular expression.
By default the mathcer is case sensitive.
For more information on how to use regular expressions, refer to java.util.regex.Pattern

Parameters:
regex - The regular expression
See Also:
Pattern

RegExpFilter

public RegExpFilter(java.lang.String regex,
                    boolean caseSensitive)
Creates a filter using the provided regular expression.
For more information on how to use regular expressions, refer to java.util.regex.Pattern

Parameters:
regex - The regular expression
caseSensitive - If the matcher shall be case sensitive or not
See Also:
Pattern

RegExpFilter

public RegExpFilter(java.util.regex.Pattern filter)
Creates a filter using the provided pattern.

Parameters:
filter - The pattern

RegExpFilter

protected RegExpFilter()
Method Detail

accept

public boolean accept(java.io.File dir,
                      java.lang.String name)
The method will match the absolute file path towards the regular expression pattern.

Specified by:
accept in interface java.io.FilenameFilter
Parameters:
dir - The file directory
name - The file name
Returns:
true if match, false otherwise

accept

public boolean accept(java.io.File f)
The method will match the absolute file path towards the regular expression pattern.

Specified by:
accept in interface java.io.FileFilter
Parameters:
f - The file to match towards
Returns:
true if match, false otherwise

getDescription

public java.lang.String getDescription()
Returns the description of the currently used pattern.
If not set by the user a default text will be displayed.

Returns:
The description
See Also:
setDescription(String)

setDescription

public void setDescription(java.lang.String s)
Set the description of the filter.
The description text is used by the JFileChooser

Parameters:
s - The description

getPattern

public java.util.regex.Pattern getPattern()
Get the pattern that is used by this filter.

Returns:
The pattern

setPattern

public void setPattern(java.util.regex.Pattern filter)
Set the pattern that is to be used by this filter.
This will overwrite any previously set pattern.
It will also reset the description of the filter.

Parameters:
filter - The pattern

setPattern

public void setPattern(java.lang.String regex)
Set the pattern that is to be used by this filter.
This will overwrite any previously set pattern.

Parameters:
regex - The pattern

setPattern

public void setPattern(java.lang.String regex,
                       boolean caseSensitive)
Set the pattern that is to be used by this filter.
This will overwrite any previously set pattern.

Parameters:
regex - The pattern
caseSensitive - If the matcher shall be case sensitive or not

toString

public java.lang.String toString()
Returns the string representation of the currently used regular expression pattern.

Returns:
The pattern


Copyright © 1998-2005 dmonix.org Peter Nerg, All Rights Reserved.