com.swabunga.spell.event

Class DocumentWordTokenizer

public class DocumentWordTokenizer extends Object implements WordTokenizer

This class tokenizes a swing document model. It also allows for the document model to be changed when corrections occur.

Author: Jason Height (jheight@chariot.net.au)

Constructor Summary
DocumentWordTokenizer(Document document)
Creates a new DocumentWordTokenizer to work on a document
Method Summary
StringgetContext()
Returns the current text that is being tokenized (includes any changes that have been made)
intgetCurrentWordCount()
Returns the number of word tokens that have been processed thus far
intgetCurrentWordEnd()
Returns an index representing the end location of the current word in the text.
intgetCurrentWordPosition()
Returns the number of word tokens that have been processed thus far
booleanhasMoreWords()
Indicates if there are more words left
booleanisNewSentence()
Indicates if the current word is at the start of a sentence
StringnextWord()
This returns the next word in the iteration.
voidposStartFullWordFrom(int pos)
Sets the current word position at the start of the word containing the char at position pos.
voidreplaceWord(String newWord)
Replaces the current word token

Constructor Detail

DocumentWordTokenizer

public DocumentWordTokenizer(Document document)
Creates a new DocumentWordTokenizer to work on a document

Parameters: document The document to spell check

Method Detail

getContext

public String getContext()
Returns the current text that is being tokenized (includes any changes that have been made)

Returns: The text, including changes.

getCurrentWordCount

public int getCurrentWordCount()
Returns the number of word tokens that have been processed thus far

Returns: the number of words found so far.

getCurrentWordEnd

public int getCurrentWordEnd()
Returns an index representing the end location of the current word in the text.

Returns: index of the end of the current word in the text.

getCurrentWordPosition

public int getCurrentWordPosition()
Returns the number of word tokens that have been processed thus far

Returns: the number of words found so far.

hasMoreWords

public boolean hasMoreWords()
Indicates if there are more words left

Returns: true if more words can be found in the text.

isNewSentence

public boolean isNewSentence()
Indicates if the current word is at the start of a sentence

Returns: true if the current word is at the start of a sentence

nextWord

public String nextWord()
This returns the next word in the iteration. Note that any implementation should return the current word, and then replace the current word with the next word found in the input text (if one exists).

Returns: the next word in the iteration.

posStartFullWordFrom

public void posStartFullWordFrom(int pos)
Sets the current word position at the start of the word containing the char at position pos. This way a call to nextWord() will return this word.

Parameters: pos position in the word we want to set as current.

replaceWord

public void replaceWord(String newWord)
Replaces the current word token

Parameters: newWord The new word to replace the misspelt one