edu.rice.cs.drjava.model
Class FindReplaceMachine

java.lang.Object
  extended by edu.rice.cs.drjava.model.FindReplaceMachine

public class FindReplaceMachine
extends Object

Implementation of logic of find/replace over a document.

Version:
$Id: FindReplaceMachine.java 4691 2008-12-02 23:33:27Z dlsmith $

Constructor Summary
FindReplaceMachine(SingleDisplayModel model, DocumentIterator docIterator)
          Standard Constructor.
 
Method Summary
 void cleanUp()
           
 FindResult findNext()
           
 int getCurrentOffset()
          Gets the character offset to which this machine is currently pointing.
 OpenDefinitionsDocument getDocument()
           
 String getFindWord()
           
 OpenDefinitionsDocument getFirstDoc()
           
 boolean getIgnoreCommentsAndStrings()
           
 boolean getIgnoreTestCases()
           
 boolean getMatchCase()
           
 boolean getMatchWholeWord()
           
 String getReplaceWord()
           
 boolean getSearchAllDocuments()
           
 boolean isSearchBackwards()
           
 boolean onMatch()
          Determine if the machine is on an instance of the find word.
 void positionChanged()
          Called when the current position is updated in the document implying _skipText should not be set if the user toggles _searchBackwards
 int processAll(Runnable1<FindResult> findAction)
          Processes all occurences of the find word with the replace word in the current document or in all documents depending the value of the machine register _searchAllDocuments.
 int replaceAll()
          Replaces all occurences of the find word with the replace word in the current document of in all documents depending the value of the machine register _searchAllDocuments.
 boolean replaceCurrent()
          If we're on a match for the find word, replace it with the replace word.
 void setDocument(OpenDefinitionsDocument doc)
           
 void setFindAnyOccurrence()
           
 void setFindWord(String word)
          Change the word being sought.
 void setFirstDoc(OpenDefinitionsDocument firstDoc)
           
 void setIgnoreCommentsAndStrings(boolean ignoreCommentsAndStrings)
           
 void setIgnoreTestCases(boolean ignoreTestCases)
           
 void setLastFindWord()
           
 void setMatchCase(boolean matchCase)
           
 void setMatchWholeWord()
           
 void setPosition(int pos)
           
 void setReplaceWord(String word)
          Change the replacing word.
 void setSearchAllDocuments(boolean searchAllDocuments)
           
 void setSearchBackwards(boolean searchBackwards)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FindReplaceMachine

public FindReplaceMachine(SingleDisplayModel model,
                          DocumentIterator docIterator)
Standard Constructor. Creates new machine to perform find/replace operations on a particular document starting from a given position.

Parameters:
docIterator - an object that allows navigation through open Swing documents (it is DefaultGlobalModel)
Method Detail

cleanUp

public void cleanUp()

positionChanged

public void positionChanged()
Called when the current position is updated in the document implying _skipText should not be set if the user toggles _searchBackwards


setLastFindWord

public void setLastFindWord()

isSearchBackwards

public boolean isSearchBackwards()

setSearchBackwards

public void setSearchBackwards(boolean searchBackwards)

setMatchCase

public void setMatchCase(boolean matchCase)

getMatchCase

public boolean getMatchCase()

setMatchWholeWord

public void setMatchWholeWord()

getMatchWholeWord

public boolean getMatchWholeWord()

setFindAnyOccurrence

public void setFindAnyOccurrence()

setSearchAllDocuments

public void setSearchAllDocuments(boolean searchAllDocuments)

setIgnoreCommentsAndStrings

public void setIgnoreCommentsAndStrings(boolean ignoreCommentsAndStrings)

getIgnoreCommentsAndStrings

public boolean getIgnoreCommentsAndStrings()

setIgnoreTestCases

public void setIgnoreTestCases(boolean ignoreTestCases)

getIgnoreTestCases

public boolean getIgnoreTestCases()

setDocument

public void setDocument(OpenDefinitionsDocument doc)

setFirstDoc

public void setFirstDoc(OpenDefinitionsDocument firstDoc)

setPosition

public void setPosition(int pos)

getCurrentOffset

public int getCurrentOffset()
Gets the character offset to which this machine is currently pointing.


getFindWord

public String getFindWord()

getReplaceWord

public String getReplaceWord()

getSearchAllDocuments

public boolean getSearchAllDocuments()

getDocument

public OpenDefinitionsDocument getDocument()

getFirstDoc

public OpenDefinitionsDocument getFirstDoc()

setFindWord

public void setFindWord(String word)
Change the word being sought.

Parameters:
word - the new word to seek

setReplaceWord

public void setReplaceWord(String word)
Change the replacing word.

Parameters:
word - the new replacing word

onMatch

public boolean onMatch()
Determine if the machine is on an instance of the find word. Only executes in event thread except for initialization.

Returns:
true if the current position is right after an instance of the find word.

replaceCurrent

public boolean replaceCurrent()
If we're on a match for the find word, replace it with the replace word. Only executes in event thread.


replaceAll

public int replaceAll()
Replaces all occurences of the find word with the replace word in the current document of in all documents depending the value of the machine register _searchAllDocuments.

Returns:
the number of replacements

processAll

public int processAll(Runnable1<FindResult> findAction)
Processes all occurences of the find word with the replace word in the current document or in all documents depending the value of the machine register _searchAllDocuments.

Parameters:
findAction - action to perform on the occurrences; input is the FindResult, output is ignored
Returns:
the number of processed occurrences

findNext

public FindResult findNext()