kawigi.cmd
Class FindReplaceContext

java.lang.Object
  extended by kawigi.cmd.FindReplaceContext

public class FindReplaceContext
extends java.lang.Object

An object held by a CodePane that holds state used by Find/Replace Actions.


Constructor Summary
FindReplaceContext(Dispatcher disp)
          Constructs a new FindReplaceContext which operates on commands in the given subdispatcher.
 
Method Summary
 boolean dialogShowing()
          Returns true if the find/replace dialog has been created and is showing.
 java.lang.String escapePattern(java.lang.String pattern)
          Takes a search string that isn't supposed to be used as a regular expression and makes it regular-expression-able by escaping characters that would otherwise have an unwanted meaning in a regular expression (or worse, make the regular expression not compile, in which case we'd be hosed).
 boolean getCaseSensitive()
          Returns true if the "Case Sensitive" option is on.
 java.util.regex.Pattern getCurrentPattern()
          Gets a regular expression pattern representing the current search string.
 javax.swing.JDialog getDialog()
          Returns the Find/Replace dialog.
 java.lang.String getReplacement()
          Returns the current replacement string.
 java.lang.String getSearchString()
          Returns the current search string.
 boolean getWholeWord()
          Returns true if the "Whole Word" option is on.
 boolean isShowingReplace()
          Returns true if the replace options should be showing.
 void setReplacement(java.lang.String s)
          Sets the current replacement string.
 void setSearchString(java.lang.String s)
          Sets the current search string.
 void setUseLiteral()
          Sets the search mode to literal string matching.
 void setUseRegex()
          Sets the search mode to regular expressions.
 void setUseWildcards()
          Sets the search mode to use wildcards.
 void showing(boolean replace)
          Gets the Find/Replace dialog and shows it.
 void toggleCaseSensitive()
          Toggles the "Case Sensitive" option.
 void toggleWholeWord()
          Toggles the "Whole Word" option.
 boolean useLiteral()
          Returns true if literal string matching should be used.
 boolean useRegex()
          Returns true if regular expression matching should be used.
 boolean useWildcards()
          Returns true if wildcard matching should be used.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FindReplaceContext

public FindReplaceContext(Dispatcher disp)
Constructs a new FindReplaceContext which operates on commands in the given subdispatcher.

Method Detail

getSearchString

public java.lang.String getSearchString()
Returns the current search string.


getReplacement

public java.lang.String getReplacement()
Returns the current replacement string.


setSearchString

public void setSearchString(java.lang.String s)
Sets the current search string.


setReplacement

public void setReplacement(java.lang.String s)
Sets the current replacement string.


showing

public void showing(boolean replace)
Gets the Find/Replace dialog and shows it. Shows the Replace dialog if replace is true, otherwise shows the Find dialog.


isShowingReplace

public boolean isShowingReplace()
Returns true if the replace options should be showing.


toggleWholeWord

public void toggleWholeWord()
Toggles the "Whole Word" option.


toggleCaseSensitive

public void toggleCaseSensitive()
Toggles the "Case Sensitive" option.


getWholeWord

public boolean getWholeWord()
Returns true if the "Whole Word" option is on.


getCaseSensitive

public boolean getCaseSensitive()
Returns true if the "Case Sensitive" option is on.


useLiteral

public boolean useLiteral()
Returns true if literal string matching should be used.


useWildcards

public boolean useWildcards()
Returns true if wildcard matching should be used.


useRegex

public boolean useRegex()
Returns true if regular expression matching should be used.


setUseLiteral

public void setUseLiteral()
Sets the search mode to literal string matching.


setUseWildcards

public void setUseWildcards()
Sets the search mode to use wildcards.


setUseRegex

public void setUseRegex()
Sets the search mode to regular expressions.


getCurrentPattern

public java.util.regex.Pattern getCurrentPattern()
Gets a regular expression pattern representing the current search string. This method is the real magic behind KawigiEdit's search and replace. Regardless of the specified search type, all searching is done with regular expressions underneath. If the search type isn't regex, the search pattern is appropriately escaped (see the escapePattern method). If the search type is wildcard, all the *'s in the escaped pattern are converted to ".*" and all the ?'s in the escaped pattern are converted to ".". Of course, since ? and * are both control characters in regular expressions as well, we have to search for \* and \? to do this munging. Conveniently, case sensitivity can be set as a flag when compiling the pattern. "Whole Word" is implemented by adding \b (word boundary matcher) to the beginning and end of the final resulting pattern.


escapePattern

public java.lang.String escapePattern(java.lang.String pattern)
Takes a search string that isn't supposed to be used as a regular expression and makes it regular-expression-able by escaping characters that would otherwise have an unwanted meaning in a regular expression (or worse, make the regular expression not compile, in which case we'd be hosed). Characters that are currently escaped by this method are \, [, ], ^, $, &, |, (, ), ., *, +, ?, { and }.


dialogShowing

public boolean dialogShowing()
Returns true if the find/replace dialog has been created and is showing.


getDialog

public javax.swing.JDialog getDialog()
Returns the Find/Replace dialog. If the dialog hasn't been created yet, creates the dialog.