com.swabunga.spell.event
Class SpellChecker

java.lang.Object
  extended bycom.swabunga.spell.event.SpellChecker

public class SpellChecker
extends java.lang.Object

This is the main class for spell checking (using the new event based spell checking).

Author:
Jason Height ([email protected]) 19 June 2002

Field Summary
static int SPELLCHECK_CANCEL
          Flag indicating that the Spell Check completed due to user cancellation
static int SPELLCHECK_OK
          Flag indicating that the Spell Check completed without any errors present
 
Constructor Summary
SpellChecker()
          Constructs the SpellChecker.
SpellChecker(SpellDictionary dictionary)
          Constructs the SpellChecker.
SpellChecker(SpellDictionary dictionary, int threshold)
          Constructs the SpellChecker with a threshold
 
Method Summary
 void addDictionary(SpellDictionary dictionary)
           
 void addSpellCheckListener(SpellCheckListener listener)
          Adds a SpellCheckListener
 int checkSpelling(WordTokenizer tokenizer)
          This method is called to check the spelling of the words that are returned by the WordTokenizer.
 java.lang.String checkString(java.lang.String text)
          Deprecated. use checkSpelling(WordTokenizer)
protected  boolean fireAndHandleEvent(WordTokenizer tokenizer, SpellCheckEvent event)
          This method will fire the spell check event and then handle the event action that has been selected by the user.
protected  void fireSpellCheckEvent(SpellCheckEvent event)
          Fires off a spell check event to the listeners.
 Configuration getConfiguration()
           
 java.util.List getSuggestions(java.lang.String word, int threshold)
           
static boolean isINETWord(java.lang.String word)
          Returns true iff this word looks like an internet address.
 void removeSpellCheckListener(SpellCheckListener listener)
          Removes a SpellCheckListener
 void reset()
          This method clears the words that are currently being remembered as Ignore All words and Replace All words.
 void setUserDictionary(SpellDictionary dictionary)
          Set user dictionary (used when a word is added)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SPELLCHECK_OK

public static final int SPELLCHECK_OK
Flag indicating that the Spell Check completed without any errors present

See Also:
Constant Field Values

SPELLCHECK_CANCEL

public static final int SPELLCHECK_CANCEL
Flag indicating that the Spell Check completed due to user cancellation

See Also:
Constant Field Values
Constructor Detail

SpellChecker

public SpellChecker()
Constructs the SpellChecker.


SpellChecker

public SpellChecker(SpellDictionary dictionary)
Constructs the SpellChecker. The default threshold is used

Parameters:
dictionary - Description of the Parameter

SpellChecker

public SpellChecker(SpellDictionary dictionary,
                    int threshold)
Constructs the SpellChecker with a threshold

Parameters:
dictionary - Description of the Parameter
threshold - Description of the Parameter
Method Detail

addDictionary

public void addDictionary(SpellDictionary dictionary)

setUserDictionary

public void setUserDictionary(SpellDictionary dictionary)
Set user dictionary (used when a word is added)


getConfiguration

public Configuration getConfiguration()
Returns:
Current Configuration

addSpellCheckListener

public void addSpellCheckListener(SpellCheckListener listener)
Adds a SpellCheckListener

Parameters:
listener - The feature to be added to the SpellCheckListener attribute

removeSpellCheckListener

public void removeSpellCheckListener(SpellCheckListener listener)
Removes a SpellCheckListener

Parameters:
listener - Description of the Parameter

fireSpellCheckEvent

protected void fireSpellCheckEvent(SpellCheckEvent event)
Fires off a spell check event to the listeners.

Parameters:
event - Description of the Parameter

reset

public void reset()
This method clears the words that are currently being remembered as Ignore All words and Replace All words.


checkString

public java.lang.String checkString(java.lang.String text)
Deprecated. use checkSpelling(WordTokenizer)

Checks the text string.

Returns the corrected string.

Parameters:
text - Description of the Parameter
Returns:
Description of the Return Value

isINETWord

public static final boolean isINETWord(java.lang.String word)
Returns true iff this word looks like an internet address. One limitation is that this method cannot currently recognise email addresses. Since the 'word' that is passed in may in fact contain the rest of the document to be checked, it is not (yet!) a good idea to scan for the @ character.

Parameters:
word - Description of the Parameter
Returns:
The iNETWord value

fireAndHandleEvent

protected boolean fireAndHandleEvent(WordTokenizer tokenizer,
                                     SpellCheckEvent event)
This method will fire the spell check event and then handle the event action that has been selected by the user.

Parameters:
tokenizer - Description of the Parameter
event - Description of the Parameter
Returns:
Returns true if the event action is to cancel the current spell checking, false if the spell checking should continue

getSuggestions

public java.util.List getSuggestions(java.lang.String word,
                                     int threshold)

checkSpelling

public final int checkSpelling(WordTokenizer tokenizer)
This method is called to check the spelling of the words that are returned by the WordTokenizer.

For each invalid word the action listeners will be informed with a new SpellCheckEvent

Parameters:
tokenizer - Description of the Parameter
Returns:
Either SPELLCHECK_OK, SPELLCHECK_CANCEL or the number of errors found. The number of errors are those that are found BEFORE any corrections are made.