Package org.fife.ui.rtextarea
Class SearchContext
java.lang.Object
org.fife.ui.rtextarea.SearchContext
- All Implemented Interfaces:
Serializable
,Cloneable
Contains information about a find/replace operation. Applications can
keep an instance of this class around and use it to maintain the user's
selection for options such as "match case," "regular expression," etc.,
between search operations. They can then pass the instance as a parameter
to the public
SearchEngine
methods to do the actual searching.- Version:
- 2.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private boolean
private boolean
static final String
Fired when the user toggles the "Mark All" property.static final String
Fired when the "match case" property is toggled.static final String
Fired when the "whole word" property is toggled.static final String
Fired when the "replace with" property is modified.static final String
Fired when the "search for" property is modified.static final String
Fired when search direction is toggled.static final String
Fired when search wrap is toggled.static final String
Fired when "search in selection" is toggled (not currently supported).static final String
Fired when "use regular expressions" is toggled.private boolean
private String
private String
private boolean
private static final long
private PropertyChangeSupport
private boolean
private boolean
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new search context.SearchContext
(String searchFor) Creates a new search context.SearchContext
(String searchFor, boolean matchCase) Creates a new search context. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a property change listener to this context.clone()
protected void
firePropertyChange
(String property, boolean oldValue, boolean newValue) protected void
firePropertyChange
(String property, String oldValue, String newValue) boolean
Returns whether "mark all" should be selected or enabled.boolean
Returns whether case should be honored while searching.Returns the text to replace with, if doing a replace operation.Returns the text to search for.boolean
Returns whether the search should be forward through the text (vs.boolean
Returns whether the search should only be done in the selected text.boolean
Returns whether the search should wrap.boolean
Returns whether only "whole word" matches should be returned.boolean
Returns whether a regular expression search should be done.void
Removes a property change listener from this context.void
setMarkAll
(boolean markAll) Sets whether "mark all" should be selected or enabled.void
setMatchCase
(boolean matchCase) Sets whether case should be honored while searching.void
setRegularExpression
(boolean regex) Sets whether a regular expression search should be done.This method fires a property change event of typePROPERTY_USE_REGEX
.void
setReplaceWith
(String replaceWith) Sets the text to replace with, if doing a replace operation.void
setSearchFor
(String searchFor) Sets the text to search for.void
setSearchForward
(boolean forward) Sets whether the search should be forward through the text (vs.void
setSearchSelectionOnly
(boolean selectionOnly) Sets whether only the selected text should be searched.void
setSearchWrap
(boolean wrap) Sets whether the search should be wrap through the text.void
setWholeWord
(boolean wholeWord) Sets whether only "whole word" matches should be returned.toString()
-
Field Details
-
PROPERTY_SEARCH_FOR
Fired when the "search for" property is modified.- See Also:
-
PROPERTY_REPLACE_WITH
Fired when the "replace with" property is modified.- See Also:
-
PROPERTY_MATCH_CASE
Fired when the "match case" property is toggled.- See Also:
-
PROPERTY_MATCH_WHOLE_WORD
Fired when the "whole word" property is toggled.- See Also:
-
PROPERTY_SEARCH_FORWARD
Fired when search direction is toggled.- See Also:
-
PROPERTY_SEARCH_WRAP
Fired when search wrap is toggled.- See Also:
-
PROPERTY_SELECTION_ONLY
Fired when "search in selection" is toggled (not currently supported).- See Also:
-
PROPERTY_USE_REGEX
Fired when "use regular expressions" is toggled.- See Also:
-
PROPERTY_MARK_ALL
Fired when the user toggles the "Mark All" property.- See Also:
-
searchFor
-
replaceWith
-
forward
private boolean forward -
wrap
private boolean wrap -
matchCase
private boolean matchCase -
wholeWord
private boolean wholeWord -
regex
private boolean regex -
selectionOnly
private boolean selectionOnly -
markAll
private boolean markAll -
support
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
-
Constructor Details
-
SearchContext
public SearchContext()Creates a new search context. Specifies a forward search, case-insensitive, not whole-word, not a regular expression. -
SearchContext
Creates a new search context. Specifies a forward search, case-insensitive, not whole-word, not a regular expression.- Parameters:
searchFor
- The text to search for.
-
SearchContext
Creates a new search context. Specifies a forward search, not whole-word, not a regular expression.- Parameters:
searchFor
- The text to search for.matchCase
- Whether to do a case-sensitive search.
-
-
Method Details
-
addPropertyChangeListener
Adds a property change listener to this context.- Parameters:
l
- The new listener.- See Also:
-
clone
-
firePropertyChange
-
firePropertyChange
-
getMarkAll
public boolean getMarkAll()Returns whether "mark all" should be selected or enabled.- Returns:
- Whether "mark all" should be enabled.
- See Also:
-
getMatchCase
public boolean getMatchCase()Returns whether case should be honored while searching.- Returns:
- Whether case should be honored.
- See Also:
-
getReplaceWith
Returns the text to replace with, if doing a replace operation.- Returns:
- The text to replace with.
- See Also:
-
getSearchFor
Returns the text to search for.- Returns:
- The text to search for.
- See Also:
-
getSearchForward
public boolean getSearchForward()Returns whether the search should be forward through the text (vs. backwards).- Returns:
- Whether we should search forwards.
- See Also:
-
getSearchWrap
public boolean getSearchWrap()Returns whether the search should wrap.- Returns:
- Whether we should search wrap
- See Also:
-
getSearchSelectionOnly
public boolean getSearchSelectionOnly()Returns whether the search should only be done in the selected text. This flag is currently not supported.- Returns:
- Whether only the selected text should be searched.
- See Also:
-
getWholeWord
public boolean getWholeWord()Returns whether only "whole word" matches should be returned. A match is considered to be "whole word" if the character on either side of the matched text is a non-word character, or if there is no character on one side of the word, such as when it's at the beginning or end of a line.- Returns:
- Whether only "whole word" matches should be returned.
- See Also:
-
isRegularExpression
public boolean isRegularExpression()Returns whether a regular expression search should be done.- Returns:
- Whether a regular expression search should be done.
- See Also:
-
removePropertyChangeListener
Removes a property change listener from this context.- Parameters:
l
- The listener to remove.- See Also:
-
setMarkAll
public void setMarkAll(boolean markAll) Sets whether "mark all" should be selected or enabled. This method fires property change events of typePROPERTY_MARK_ALL
.- Parameters:
markAll
- Whether "mark all" should be enabled.- See Also:
-
setMatchCase
public void setMatchCase(boolean matchCase) Sets whether case should be honored while searching. This method fires a property change event of typePROPERTY_MATCH_CASE
.- Parameters:
matchCase
- Whether case should be honored.- See Also:
-
setRegularExpression
public void setRegularExpression(boolean regex) Sets whether a regular expression search should be done.This method fires a property change event of typePROPERTY_USE_REGEX
.- Parameters:
regex
- Whether a regular expression search should be done.- See Also:
-
setReplaceWith
Sets the text to replace with, if doing a replace operation. This method fires a property change event of typePROPERTY_REPLACE_WITH
.- Parameters:
replaceWith
- The text to replace with.- See Also:
-
setSearchFor
Sets the text to search for. This method fires a property change event of typePROPERTY_SEARCH_FOR
.- Parameters:
searchFor
- The text to search for.- See Also:
-
setSearchForward
public void setSearchForward(boolean forward) Sets whether the search should be forward through the text (vs. backwards). This method fires a property change event of typePROPERTY_SEARCH_FORWARD
.- Parameters:
forward
- Whether we should search forwards.- See Also:
-
setSearchWrap
public void setSearchWrap(boolean wrap) Sets whether the search should be wrap through the text. This method fires a property change event of typePROPERTY_SEARCH_WRAP
.- Parameters:
wrap
- Whether we should search wrap- See Also:
-
setSearchSelectionOnly
public void setSearchSelectionOnly(boolean selectionOnly) Sets whether only the selected text should be searched. This method fires a property change event of typePROPERTY_SELECTION_ONLY
.This flag is currently not supported. Calling this method will throw an
UnsupportedOperationException
until it is implemented.- Parameters:
selectionOnly
- Whether only selected text should be searched.- See Also:
-
setWholeWord
public void setWholeWord(boolean wholeWord) Sets whether only "whole word" matches should be returned. A match is considered to be "whole word" if the character on either side of the matched text is a non-word character, or if there is no character on one side of the word, such as when it's at the beginning or end of a line.This method fires a property change event of typePROPERTY_MATCH_WHOLE_WORD
.- Parameters:
wholeWord
- Whether only "whole word" matches should be returned.- See Also:
-
toString
-