org.jdesktop.swingx.search
Class PatternModel

java.lang.Object
  extended by org.jdesktop.swingx.search.PatternModel

public class PatternModel
extends Object

Presentation Model for Find/Filter Widgets.

Compiles and holds a Pattern from rawText. There are different predefined strategies to control the compilation:

Holds state for controlling the match process for both find and filter (TODO - explain). Relevant in all Relevant in find contexts: JW: Work-in-progress - Anchors will be factored into AnchoredSearchMode Anchors By default, the scope of the pattern relative to strings being tested are unanchored, ie, the pattern will match any part of the tested string. Traditionally, special characters ('^' and '$') are used to describe patterns that match the beginning (or end) of a string. If those characters are included in the pattern, the regular expression will honor them. However, for ease of use, two properties are included in this model that will determine how the pattern will be evaluated when these characters are omitted.

The StartAnchored property determines if the pattern must match from the beginning of tested strings, or if the pattern can appear anywhere in the tested string. Likewise, the EndAnchored property determines if the pattern must match to the end of the tested string, or if the end of the pattern can appear anywhere in the tested string. The default values (false in both cases) correspond to the common database 'LIKE' operation, where the pattern is considered to be a match if any part of the tested string matches the pattern.


Nested Class Summary
static class PatternModel.AnchoredSearchMode
          Support for anchored input.
static class PatternModel.RegexCreator
          Responsible for converting a "raw text" into a valid regular expression in the context of a set of rules.
 
Field Summary
static String MATCH_BACKWARDS_ACTION_COMMAND
           
static String MATCH_CASE_ACTION_COMMAND
           
static String MATCH_INCREMENTAL_ACTION_COMMAND
           
static String MATCH_RULE_CONTAINS
           
static String MATCH_RULE_ENDSWITH
           
static String MATCH_RULE_EQUALS
           
static String MATCH_RULE_STARTSWITH
           
static String MATCH_WRAP_ACTION_COMMAND
           
static String REGEX_ANCHORED
           
static String REGEX_MATCH_RULES
           
static String REGEX_UNCHANGED
           
static String REGEX_WILDCARD
           
static String SEARCH_PREFIX
          The prefix marker to find component related properties in the resourcebundle.
 
Constructor Summary
PatternModel()
           
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener l)
           
protected  void createRegexCreator(String mode)
          Creates and sets the strategy to use for compiling a pattern from rawtext.
protected  void firePropertyChange(String name, Object oldValue, Object newValue)
           
 int getFoundIndex()
           
 String getMatchRule()
           
 List getMatchRules()
           
 Pattern getPattern()
           
 String getRawText()
           
 String getRegexCreatorKey()
           
 boolean isAutoAdjustFoundIndex()
           
 boolean isBackwards()
           
 boolean isCaseSensitive()
           
 boolean isEmpty()
           
 boolean isIncremental()
           
 boolean isWrapping()
           
 void removePropertyChangeListener(PropertyChangeListener l)
           
 void setBackwards(boolean backwards)
           
 void setCaseSensitive(boolean caseSensitive)
           
 void setFoundIndex(int foundIndex)
           
 void setIncremental(boolean incremental)
           
 void setMatchRule(String category)
           
 void setRawText(String findText)
           
 void setRegexCreator(PatternModel.RegexCreator regexCreator)
          This is a quick-fix to allow custom strategies for compiling rawtext to patterns.
 void setRegexCreatorKey(String mode)
          Set the strategy to use for compiling a pattern from rawtext.
 void setWrapping(boolean wrapping)
           
protected  void updateFoundIndex(int newFoundIndex)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEARCH_PREFIX

public static final String SEARCH_PREFIX
The prefix marker to find component related properties in the resourcebundle.

See Also:
Constant Field Values

REGEX_UNCHANGED

public static final String REGEX_UNCHANGED
See Also:
Constant Field Values

REGEX_ANCHORED

public static final String REGEX_ANCHORED
See Also:
Constant Field Values

REGEX_WILDCARD

public static final String REGEX_WILDCARD
See Also:
Constant Field Values

REGEX_MATCH_RULES

public static final String REGEX_MATCH_RULES
See Also:
Constant Field Values

MATCH_RULE_CONTAINS

public static final String MATCH_RULE_CONTAINS
See Also:
Constant Field Values

MATCH_RULE_EQUALS

public static final String MATCH_RULE_EQUALS
See Also:
Constant Field Values

MATCH_RULE_ENDSWITH

public static final String MATCH_RULE_ENDSWITH
See Also:
Constant Field Values

MATCH_RULE_STARTSWITH

public static final String MATCH_RULE_STARTSWITH
See Also:
Constant Field Values

MATCH_BACKWARDS_ACTION_COMMAND

public static final String MATCH_BACKWARDS_ACTION_COMMAND
See Also:
Constant Field Values

MATCH_WRAP_ACTION_COMMAND

public static final String MATCH_WRAP_ACTION_COMMAND
See Also:
Constant Field Values

MATCH_CASE_ACTION_COMMAND

public static final String MATCH_CASE_ACTION_COMMAND
See Also:
Constant Field Values

MATCH_INCREMENTAL_ACTION_COMMAND

public static final String MATCH_INCREMENTAL_ACTION_COMMAND
See Also:
Constant Field Values
Constructor Detail

PatternModel

public PatternModel()
Method Detail

getFoundIndex

public int getFoundIndex()

setFoundIndex

public void setFoundIndex(int foundIndex)

updateFoundIndex

protected void updateFoundIndex(int newFoundIndex)
Parameters:
newFoundIndex -

isAutoAdjustFoundIndex

public boolean isAutoAdjustFoundIndex()

isBackwards

public boolean isBackwards()

setBackwards

public void setBackwards(boolean backwards)

isWrapping

public boolean isWrapping()

setWrapping

public void setWrapping(boolean wrapping)

setIncremental

public void setIncremental(boolean incremental)

isIncremental

public boolean isIncremental()

isCaseSensitive

public boolean isCaseSensitive()

setCaseSensitive

public void setCaseSensitive(boolean caseSensitive)

getPattern

public Pattern getPattern()

getRawText

public String getRawText()

setRawText

public void setRawText(String findText)

isEmpty

public boolean isEmpty()

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener l)

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener l)

firePropertyChange

protected void firePropertyChange(String name,
                                  Object oldValue,
                                  Object newValue)

setRegexCreatorKey

public void setRegexCreatorKey(String mode)
Set the strategy to use for compiling a pattern from rawtext. NOTE: This is imcomplete (in fact it wasn't implemented at all) - only recognizes REGEX_ANCHORED, every other value results in REGEX_MATCH_RULES.

Parameters:
mode - the String key of the match strategy to use.

createRegexCreator

protected void createRegexCreator(String mode)
Creates and sets the strategy to use for compiling a pattern from rawtext. NOTE: This is imcomplete (in fact it wasn't implemented at all) - only recognizes REGEX_ANCHORED, every other value results in REGEX_MATCH_RULES.

Parameters:
mode - the String key of the match strategy to use.

getRegexCreatorKey

public String getRegexCreatorKey()

setRegexCreator

public void setRegexCreator(PatternModel.RegexCreator regexCreator)
This is a quick-fix to allow custom strategies for compiling rawtext to patterns.

Parameters:
regexCreator - the strategy to use for compiling text into pattern.

setMatchRule

public void setMatchRule(String category)

getMatchRule

public String getMatchRule()

getMatchRules

public List getMatchRules()