com.swabunga.spell.event
Class DocumentWordTokenizer

java.lang.Object
  extended by com.swabunga.spell.event.DocumentWordTokenizer
All Implemented Interfaces:
WordTokenizer

public class DocumentWordTokenizer
extends java.lang.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(javax.swing.text.Document document)
          Creates a new DocumentWordTokenizer to work on a document
 
Method Summary
 java.lang.String getContext()
          Returns the current text that is being tokenized (includes any changes that have been made)
 int getCurrentWordCount()
          Returns the number of word tokens that have been processed thus far
 int getCurrentWordEnd()
          Returns an index representing the end location of the current word in the text.
 int getCurrentWordPosition()
          Returns the number of word tokens that have been processed thus far
 boolean hasMoreWords()
          Indicates if there are more words left
 boolean isNewSentence()
          Indicates if the current word is at the start of a sentence
 java.lang.String nextWord()
          This returns the next word in the iteration.
 void posStartFullWordFrom(int pos)
          Sets the current word position at the start of the word containing the char at position pos.
 void replaceWord(java.lang.String newWord)
          Replaces the current word token
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DocumentWordTokenizer

public DocumentWordTokenizer(javax.swing.text.Document document)
Creates a new DocumentWordTokenizer to work on a document

Parameters:
document - The document to spell check
Method Detail

hasMoreWords

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

Specified by:
hasMoreWords in interface WordTokenizer
Returns:
true if more words can be found in the text.

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.

getCurrentWordPosition

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

Specified by:
getCurrentWordPosition in interface WordTokenizer
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.

Specified by:
getCurrentWordEnd in interface WordTokenizer
Returns:
index of the end of the current word in the text.

nextWord

public java.lang.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).

Specified by:
nextWord in interface WordTokenizer
Returns:
the next word in the iteration.

getCurrentWordCount

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

Specified by:
getCurrentWordCount in interface WordTokenizer
Returns:
the number of words found so far.

replaceWord

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

Specified by:
replaceWord in interface WordTokenizer
Parameters:
newWord - The new word to replace the misspelt one

getContext

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

Specified by:
getContext in interface WordTokenizer
Returns:
The text, including changes.

isNewSentence

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

Specified by:
isNewSentence in interface WordTokenizer
Returns:
true if the current word is at the start of a sentence