|
Groovy Documentation | |||||||
| FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectorg.codehaus.griffon.runtime.search.JTextComponentSearcher
public class JTextComponentSearcher extends Object
Implementation of the Searcher interface that targets JTextComponent.
Heavily based in SearchEngine.
| Constructor Summary | |
JTextComponentSearcher()
Private constructor to prevent instantiation. |
|
| Method Summary | |
|---|---|
boolean
|
find(JComponent subject, String text, boolean forward, boolean matchCase, boolean wholeWord, boolean regex)
Finds the next instance of the string/regular expression specified from the caret position. |
protected String
|
getFindInText(JTextComponent component, int start, boolean forward)
Returns the text in which to search, as a string. |
protected List
|
getMatches(Matcher m, String replaceStr)
This method is called internally by
|
int
|
getNextMatchPos(String searchFor, String searchIn, boolean forward, boolean matchCase, boolean wholeWord)
Searches |
protected int
|
getNextMatchPosImpl(String searchFor, String searchIn, boolean goForward, boolean matchCase, boolean wholeWord)
Actually does the work of matching; assumes searchFor and searchIn are already upper/lower-cased appropriately. |
Point
|
getNextMatchPosRegEx(String regEx, CharSequence searchIn, boolean goForward, boolean matchCase, boolean wholeWord)
Searches |
protected Object
|
getNextMatchPosRegExImpl(String regEx, CharSequence searchIn, boolean goForward, boolean matchCase, boolean wholeWord, String replaceStr)
Searches |
protected RegExReplaceInfo
|
getRegExReplaceInfo(String regEx, String searchIn, boolean goForward, boolean matchCase, boolean wholeWord, String replacement)
Returns information on how to implement a regular expression "replace" action in the specified text with the specified replacement string. |
String
|
getReplacementText(Matcher m, CharSequence template)
Called internally by |
private boolean
|
isWholeWord(CharSequence searchIn, int offset, int len)
Returns whether the characters on either side of
|
protected int
|
makeMarkAndDotEqual(JTextComponent component, boolean forward)
Makes the caret's dot and mark the same location so that, for the next search in the specified direction, a match will be found even if it was within the original dot and mark's selection. |
protected boolean
|
regexReplace(JComponent subject, String toFind, String replaceWith, boolean forward, boolean matchCase, boolean wholeWord)
Finds the next instance of the regular expression specified from the caret position. |
boolean
|
replace(JComponent subject, String toFind, String replaceWith, boolean forward, boolean matchCase, boolean wholeWord, boolean regex)
Finds the next instance of the text/regular expression specified from the caret position. |
int
|
replaceAll(JComponent subject, String toFind, String replaceWith, boolean matchCase, boolean wholeWord, boolean regex)
Replaces all instances of the text/regular expression specified in the specified document with the specified replacement. |
private void
|
selectAndPossiblyCenter(JTextComponent component, int start, int end)
Selects a range of text in a text component. |
| Methods inherited from class Object | |
|---|---|
| wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
| Constructor Detail |
|---|
public JTextComponentSearcher()
| Method Detail |
|---|
public boolean find(JComponent subject, String text, boolean forward, boolean matchCase, boolean wholeWord, boolean regex)
regex is
true but text is not a valid regular
expression.subject - The text area in which to search.text - The string literal or regular expression to search for.forward - Whether to search forward from the caret position or
backward from it.matchCase - Whether the search should be case-sensitive.wholeWord - Whether there should be spaces or tabs on either side
of the match.regex - Whether text is a Java regular expression to
search for.
protected String getFindInText(JTextComponent component, int start, boolean forward)
protected List getMatches(Matcher m, String replaceStr)
getNextMatchPosRegExImpl and is used to get the locations
of all regular-expression matches, and possibly their replacement
strings.Returns either:
RegExReplaceInfos describing the matches
found by the matcher and the replacement strings for each.
replacement is null, this method call is
assumed to be part of a "find" operation and points are returned. If
if is non-null, it is assumed to be part of a "replace"
operation and the RegExReplaceInfos are returned.replaceStr references
an invalid group (less than zero or greater than the number of
groups matched).m - The matcher.replaceStr - The string to replace matches with. This is a
"template" string and can contain captured group references in
the form "\${digit}".
public final int getNextMatchPos(String searchFor, String searchIn, boolean forward, boolean matchCase, boolean wholeWord)
searchIn for an occurrence of
searchFor either forwards or backwards, matching
case or not.
searchFor - The string to look for.searchIn - The string to search in.forward - Whether to search forward or backward in
searchIn.matchCase - If true, do a case-sensitive search for
searchFor.wholeWord - If true, searchFor
occurrences embedded in longer words in searchIn
don't count as matches.-1 if no
match was found.
protected final int getNextMatchPosImpl(String searchFor, String searchIn, boolean goForward, boolean matchCase, boolean wholeWord)
FindInFilesDialog; since it repeatedly calls
this method instead of getNextMatchPos, it gets better
performance as it no longer has to allocate a lower-cased string for
every call.
searchFor - The string to search for.searchIn - The string to search in.goForward - Whether the search is forward or backward.matchCase - Whether the search is case-sensitive.wholeWord - Whether only whole words should be matched.-1 if no
match was found.
public Point getNextMatchPosRegEx(String regEx, CharSequence searchIn, boolean goForward, boolean matchCase, boolean wholeWord)
searchIn for an occurrence of regEx
either forwards or backwards, matching case or not.regEx is an invalid
regular expression.regEx - The regular expression to look for.searchIn - The string to search in.goForward - Whether to search forward. If false,
search backward.matchCase - Whether or not to do a case-sensitive search for
regEx.wholeWord - If true, regEx
occurrences embedded in longer words in searchIn
don't count as matches.Point representing the starting and ending
position of the match, or null if no match was
found.
protected Object getNextMatchPosRegExImpl(String regEx, CharSequence searchIn, boolean goForward, boolean matchCase, boolean wholeWord, String replaceStr)
searchIn for an occurrence of regEx
either forwards or backwards, matching case or not.regEx is an invalid
regular expression.replaceStr references
an invalid group (less than zero or greater than the number of
groups matched).regEx - The regular expression to look for.searchIn - The string to search in.goForward - Whether to search forward. If false,
search backward.matchCase - Whether or not to do a case-sensitive search for
regEx.wholeWord - If true, regEx
occurrences embedded in longer words in searchIn
don't count as matches.replaceStr - The string that will replace the match found (if
a match is found). The object returned will contain the
replacement string with matched groups substituted. If this
value is null, it is assumed this call is part of a
"find" instead of a "replace" operation.replaceStr is null, a
Point representing the starting and ending points
of the match. If it is non-null, an object with
information about the match and the morphed string to replace
it with. If no match is found, null is returned.
protected RegExReplaceInfo getRegExReplaceInfo(String regEx, String searchIn, boolean goForward, boolean matchCase, boolean wholeWord, String replacement)
regEx is an invalid
regular expression.replacement references
an invalid group (less than zero or greater than the number of
groups matched).regEx - The regular expression to look for.searchIn - The string to search in.goForward - Whether to search forward. If false,
search backward.matchCase - Whether or not to do a case-sensitive search for
regEx.wholeWord - If true, regEx occurrences
embedded in longer words in searchIn don't count as
matches.replacement - A template for the replacement string (e.g., this
can contain \\t and \\n to mean tabs
and newlines, respectively, as well as group references
\$n).RegExReplaceInfo object describing how to
implement the replace.
public String getReplacementText(Matcher m, CharSequence template)
getMatches(). This method assumes
that the specified matcher has just found a match, and that you want
to get the string with which to replace that match.template references
an invalid group (less than zero or greater than the number of
groups matched).m - The matcher.template - The template for the replacement string. For example,
"foo" would yield the replacement string
"foo", while "\$1 is the greatest"
would yield different values depending on the value of the first
captured group in the match.
private final boolean isWholeWord(CharSequence searchIn, int offset, int len)
substr(searchIn,startPos,startPos+searchStringLength)
are whitespace. While this isn't the best definition of "whole word",
it's the one we're going to use for now.
protected int makeMarkAndDotEqual(JTextComponent component, boolean forward)
component - The text area.forward - Whether the search will be forward through the
document (false means backward).
protected boolean regexReplace(JComponent subject, String toFind, String replaceWith, boolean forward, boolean matchCase, boolean wholeWord)
toFind is not a
valid regular expression.replaceWith references
an invalid group (less than zero or greater than the number of
groups matched).subject - The text area in which to search.toFind - The regular expression to search for.replaceWith - The string to replace the found regex with.forward - Whether to search forward from the caret position
or backward from it.matchCase - Whether the search should be case-sensitive.wholeWord - Whether there should be spaces or tabs on either
side of the match.
public boolean replace(JComponent subject, String toFind, String replaceWith, boolean forward, boolean matchCase, boolean wholeWord, boolean regex)
regex is
true but toFind is not a valid
regular expression.regex is
true and replaceWith references
an invalid group (less than zero or greater than the number
of groups matched).subject - The text area in which to search.toFind - The text/regular expression to search for.replaceWith - The string to replace the found text with.forward - Whether to search forward from the caret position or
backward from it.matchCase - Whether the search should be case-sensitive.wholeWord - Whether there should be spaces or tabs on either
side of the match.regex - Whether or not this is a regular expression search.
public int replaceAll(JComponent subject, String toFind, String replaceWith, boolean matchCase, boolean wholeWord, boolean regex)
regex is
true and toFind is an invalid
regular expression.replaceWith references
an invalid group (less than zero or greater than the number of
groups matched).subject - The text area in which to search.toFind - The text/regular expression to search for.replaceWith - The string to replace the found text with.matchCase - Whether the search should be case-sensitive.wholeWord - Whether there should be spaces or tabs on either
side of the match.regex - Whether or not this is a regular expression search.
private void selectAndPossiblyCenter(JTextComponent component, int start, int end)
component - The text component whose selection is to be centered.start - The start of the range to select.end - The end of the range to select.
Groovy Documentation