Package org.jdesktop.swingx.search
Class PatternModel
java.lang.Object
org.jdesktop.swingx.search.PatternModel
Presentation Model for Find/Filter Widgets.
Compiles and holds a Pattern from rawText. There are different predefined strategies to control the compilation:
- TODO: list and explain
- caseSensitive -
- empty - true if there's no searchString
- incremental - a hint to clients to react immediately to pattern changes.
- backwards - search direction if used in a find context
- wrapping - wrap over the end/start if not found
- foundIndex - storage for last found index
- autoAdjustFoundIndex - flag to indicate auto-incr/decr of foundIndex on setting. Here the property correlates to !isIncremental() - to simplify batch vs. incremental search ui.
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
Nested ClassesModifier and TypeClassDescriptionstatic class
Support for anchored input.static class
Responsible for converting a "raw text" into a valid regular expression in the context of a set of rules. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private boolean
private int
private boolean
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
private Pattern
private PropertyChangeSupport
private String
static final String
static final String
static final String
static final String
private PatternModel.RegexCreator
private String
static final String
The prefix marker to find component related properties in the resourcebundle.private boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
private String
createRegEx
(String searchString) returns a regEx for compilation into a pattern.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) private int
private String
private int
getFlags()
int
private PatternModel.RegexCreator
boolean
boolean
boolean
boolean
isEmpty()
private boolean
boolean
boolean
void
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) private void
updatePattern
(boolean caseSensitive) private void
updatePattern
(String regEx)
-
Field Details
-
SEARCH_PREFIX
The prefix marker to find component related properties in the resourcebundle.- See Also:
-
REGEX_UNCHANGED
- See Also:
-
REGEX_ANCHORED
- See Also:
-
REGEX_WILDCARD
- See Also:
-
REGEX_MATCH_RULES
- See Also:
-
MATCH_RULE_CONTAINS
- See Also:
-
MATCH_RULE_EQUALS
- See Also:
-
MATCH_RULE_ENDSWITH
- See Also:
-
MATCH_RULE_STARTSWITH
- See Also:
-
MATCH_BACKWARDS_ACTION_COMMAND
- See Also:
-
MATCH_WRAP_ACTION_COMMAND
- See Also:
-
MATCH_CASE_ACTION_COMMAND
- See Also:
-
MATCH_INCREMENTAL_ACTION_COMMAND
- See Also:
-
rawText
-
backwards
private boolean backwards -
pattern
-
foundIndex
private int foundIndex -
caseSensitive
private boolean caseSensitive -
propertySupport
-
regexCreatorKey
-
regexCreator
-
wrapping
private boolean wrapping -
incremental
private boolean incremental
-
-
Constructor Details
-
PatternModel
public PatternModel()
-
-
Method Details
-
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
-
getRawText
-
setRawText
-
isEmpty
public boolean isEmpty() -
createRegEx
returns a regEx for compilation into a pattern. Here: either a "contains" (== partial find) or null if the input was empty.- Parameters:
searchString
-- Returns:
- null if the input was empty, or a regex according to the internal rules
-
isEmpty
- Parameters:
s
-- Returns:
-
updatePattern
-
getFlags
private int getFlags() -
getCaseInsensitiveFlag
private int getCaseInsensitiveFlag() -
updatePattern
private void updatePattern(boolean caseSensitive) -
addPropertyChangeListener
-
removePropertyChangeListener
-
firePropertyChange
-
setRegexCreatorKey
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
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
-
getDefaultRegexCreatorKey
-
getRegexCreator
-
setRegexCreator
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
-
getMatchRule
-
getMatchRules
-