Package org.jdesktop.swingx.search
Class PatternModel
- java.lang.Object
-
- org.jdesktop.swingx.search.PatternModel
-
public class PatternModel extends java.lang.ObjectPresentation 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 Classes Modifier and Type Class Description static classPatternModel.AnchoredSearchModeSupport for anchored input.static classPatternModel.RegexCreatorResponsible for converting a "raw text" into a valid regular expression in the context of a set of rules.
-
Field Summary
Fields Modifier and Type Field Description private booleanbackwardsprivate booleancaseSensitiveprivate intfoundIndexprivate booleanincrementalstatic java.lang.StringMATCH_BACKWARDS_ACTION_COMMANDstatic java.lang.StringMATCH_CASE_ACTION_COMMANDstatic java.lang.StringMATCH_INCREMENTAL_ACTION_COMMANDstatic java.lang.StringMATCH_RULE_CONTAINSstatic java.lang.StringMATCH_RULE_ENDSWITHstatic java.lang.StringMATCH_RULE_EQUALSstatic java.lang.StringMATCH_RULE_STARTSWITHstatic java.lang.StringMATCH_WRAP_ACTION_COMMANDprivate java.util.regex.Patternpatternprivate java.beans.PropertyChangeSupportpropertySupportprivate java.lang.StringrawTextstatic java.lang.StringREGEX_ANCHOREDstatic java.lang.StringREGEX_MATCH_RULESstatic java.lang.StringREGEX_UNCHANGEDstatic java.lang.StringREGEX_WILDCARDprivate PatternModel.RegexCreatorregexCreatorprivate java.lang.StringregexCreatorKeystatic java.lang.StringSEARCH_PREFIXThe prefix marker to find component related properties in the resourcebundle.private booleanwrapping
-
Constructor Summary
Constructors Constructor Description PatternModel()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPropertyChangeListener(java.beans.PropertyChangeListener l)private java.lang.StringcreateRegEx(java.lang.String searchString)returns a regEx for compilation into a pattern.protected voidcreateRegexCreator(java.lang.String mode)Creates and sets the strategy to use for compiling a pattern from rawtext.protected voidfirePropertyChange(java.lang.String name, java.lang.Object oldValue, java.lang.Object newValue)private intgetCaseInsensitiveFlag()private java.lang.StringgetDefaultRegexCreatorKey()private intgetFlags()intgetFoundIndex()java.lang.StringgetMatchRule()java.util.List<java.lang.String>getMatchRules()java.util.regex.PatterngetPattern()java.lang.StringgetRawText()private PatternModel.RegexCreatorgetRegexCreator()java.lang.StringgetRegexCreatorKey()booleanisAutoAdjustFoundIndex()booleanisBackwards()booleanisCaseSensitive()booleanisEmpty()private booleanisEmpty(java.lang.String text)booleanisIncremental()booleanisWrapping()voidremovePropertyChangeListener(java.beans.PropertyChangeListener l)voidsetBackwards(boolean backwards)voidsetCaseSensitive(boolean caseSensitive)voidsetFoundIndex(int foundIndex)voidsetIncremental(boolean incremental)voidsetMatchRule(java.lang.String category)voidsetRawText(java.lang.String findText)voidsetRegexCreator(PatternModel.RegexCreator regexCreator)This is a quick-fix to allow custom strategies for compiling rawtext to patterns.voidsetRegexCreatorKey(java.lang.String mode)Set the strategy to use for compiling a pattern from rawtext.voidsetWrapping(boolean wrapping)protected voidupdateFoundIndex(int newFoundIndex)private voidupdatePattern(boolean caseSensitive)private voidupdatePattern(java.lang.String regEx)
-
-
-
Field Detail
-
SEARCH_PREFIX
public static final java.lang.String SEARCH_PREFIX
The prefix marker to find component related properties in the resourcebundle.- See Also:
- Constant Field Values
-
REGEX_UNCHANGED
public static final java.lang.String REGEX_UNCHANGED
- See Also:
- Constant Field Values
-
REGEX_ANCHORED
public static final java.lang.String REGEX_ANCHORED
- See Also:
- Constant Field Values
-
REGEX_WILDCARD
public static final java.lang.String REGEX_WILDCARD
- See Also:
- Constant Field Values
-
REGEX_MATCH_RULES
public static final java.lang.String REGEX_MATCH_RULES
- See Also:
- Constant Field Values
-
MATCH_RULE_CONTAINS
public static final java.lang.String MATCH_RULE_CONTAINS
- See Also:
- Constant Field Values
-
MATCH_RULE_EQUALS
public static final java.lang.String MATCH_RULE_EQUALS
- See Also:
- Constant Field Values
-
MATCH_RULE_ENDSWITH
public static final java.lang.String MATCH_RULE_ENDSWITH
- See Also:
- Constant Field Values
-
MATCH_RULE_STARTSWITH
public static final java.lang.String MATCH_RULE_STARTSWITH
- See Also:
- Constant Field Values
-
MATCH_BACKWARDS_ACTION_COMMAND
public static final java.lang.String MATCH_BACKWARDS_ACTION_COMMAND
- See Also:
- Constant Field Values
-
MATCH_WRAP_ACTION_COMMAND
public static final java.lang.String MATCH_WRAP_ACTION_COMMAND
- See Also:
- Constant Field Values
-
MATCH_CASE_ACTION_COMMAND
public static final java.lang.String MATCH_CASE_ACTION_COMMAND
- See Also:
- Constant Field Values
-
MATCH_INCREMENTAL_ACTION_COMMAND
public static final java.lang.String MATCH_INCREMENTAL_ACTION_COMMAND
- See Also:
- Constant Field Values
-
rawText
private java.lang.String rawText
-
backwards
private boolean backwards
-
pattern
private java.util.regex.Pattern pattern
-
foundIndex
private int foundIndex
-
caseSensitive
private boolean caseSensitive
-
propertySupport
private java.beans.PropertyChangeSupport propertySupport
-
regexCreatorKey
private java.lang.String regexCreatorKey
-
regexCreator
private PatternModel.RegexCreator regexCreator
-
wrapping
private boolean wrapping
-
incremental
private boolean incremental
-
-
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 java.util.regex.Pattern getPattern()
-
getRawText
public java.lang.String getRawText()
-
setRawText
public void setRawText(java.lang.String findText)
-
isEmpty
public boolean isEmpty()
-
createRegEx
private java.lang.String createRegEx(java.lang.String searchString)
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
private boolean isEmpty(java.lang.String text)
- Parameters:
s-- Returns:
-
updatePattern
private void updatePattern(java.lang.String regEx)
-
getFlags
private int getFlags()
-
getCaseInsensitiveFlag
private int getCaseInsensitiveFlag()
-
updatePattern
private void updatePattern(boolean caseSensitive)
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
-
firePropertyChange
protected void firePropertyChange(java.lang.String name, java.lang.Object oldValue, java.lang.Object newValue)
-
setRegexCreatorKey
public void setRegexCreatorKey(java.lang.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(java.lang.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 java.lang.String getRegexCreatorKey()
-
getDefaultRegexCreatorKey
private java.lang.String getDefaultRegexCreatorKey()
-
getRegexCreator
private PatternModel.RegexCreator getRegexCreator()
-
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(java.lang.String category)
-
getMatchRule
public java.lang.String getMatchRule()
-
getMatchRules
public java.util.List<java.lang.String> getMatchRules()
-
-