RapidSpell Desktop


com.keyoti.rapidSpell.desktop
Class RapidSpellAsYouType

java.lang.Object
  |
  +--com.keyoti.rapidSpell.desktop.RapidSpellAsYouType

public class RapidSpellAsYouType
extends java.lang.Object
implements java.awt.event.FocusListener, javax.swing.event.DocumentListener, java.awt.event.MouseListener, java.awt.event.ActionListener, java.awt.event.KeyListener

RapidSpell Desktop As-You-Type Control, spell checks text boxes as the user types. This class works with any JTextComponent derived classes. This class not only checks as the user types, but also follows any text modifying actions, such as; Cut, paste, selection delete etc.

To use this component in an application, just instantiate it and set setTextComponent to a JTextComponent (or sub-class of).

Example.


	RapidSpellAsYouType rapidAYT;
	JTextComponent jTextComponent;
		....
		jTextComponent = new JTextComponent();
		rapidAYT = new RapidSpellAsYouType();
		rapidAYT.setTextComponent(jTextComponent);


Constructor Summary
RapidSpellAsYouType()
          Default constructor.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
           
 void changedUpdate(javax.swing.event.DocumentEvent e)
          Gives notification that an attribute or set of attributes changed.
 void clearAllHighlights()
          Clears all spell check highlights (underlines) from the whole document (all text boxes).
protected  TextBoxUtilityAdapter createNewTextBoxUtilityAdapter(javax.swing.text.JTextComponent textBox)
          Returns a new instance of a TextBoxUtilityAdapter, for 'textBox'.
protected  void deHighlightText(BadWord theBadWord)
          Removes a highlight from a bad word in the text component The word specified by theBadWord does not necessarily have to have been identified as "bad", before this method is called.
 void dispose()
          Frees up resources.
protected  void finalize()
          Clears up references to text boxes
 void focusGained(java.awt.event.FocusEvent e)
           
 void focusLost(java.awt.event.FocusEvent e)
           
 void forceCheckAll()
          Forces a check of the whole document.
 java.lang.String getAddMenuText()
          Add button text.
 boolean getCheckAsYouType()
          Whether to spell check words as the user types/modifies text.
 boolean getCheckCompoundWords()
          Whether to check if words are made of compound forms - to be used in languages which use compounds, such as German.
 int getConsiderationRange()
          Sets the factor for words to consider for suggestions, lower values are faster but consider less words for suggestions.
 java.lang.String getDictFilePath()
          The file to be used as the main dictionary, if this is null then the RapidSpellMDict jar is used.
 int getGUILanguage()
          The language to show the UI in.
 java.lang.String getIgnoreAllMenuText()
          Ignore All button text.
 boolean getIgnoreCapitalizedWords()
          Whether to ignore words with capital letters.
 boolean getIgnoreWordsWithDigits()
          Whether to ignore words with digits in them.
 boolean getIgnoreXML()
          Whether to ignore XML/HTML tags, should be set true for 'rich HTML text box' support, false by default.
 boolean getIncludeUserDictionaryInSuggestions()
          Whether the user dictionary should be used in finding suggestions for misspelt words.
 int getLanguageParser()
          Gets the type of language parsing to use.
 boolean getLookIntoHyphenatedText()
          Whether to 'look into' text with hyphens (-), if the word has hyphens in it and LookIntoHyphenatedText is set true (default), the parts of the text around the hyphens will be checked individually.
 RapidSpellChecker getRapidSpellChecker()
          The core spell checker object
 boolean getSeparateHyphenWords()
          Gets whether to treat hyphenated (-) words as separate words, default is false.
 boolean getShowAddMenuOption()
          Whether to show the Add option in the context menu.
 boolean getShowSuggestionsContextMenu()
          Whether to show a context menu with suggestions when a misspelt word is right clicked, has no effect on developer set context menu.
 javax.swing.JMenuItem[] getSuggestions()
          Returns suggestions menu items for the last right clicked word.
 int getSuggestionsMethod()
          The suggestions method to use.
 boolean getSuggestSplitWords()
          Whether to check for joined words when looking for suggestions.
 javax.swing.text.JTextComponent getTextComponent()
          The JTextComponent to check as the user types/modifies text.
 javax.swing.text.JTextComponent[] getTextComponents()
          The JTextComponents to check as the user types/modifies text.
 java.awt.Color getUnderlineColor()
          The underline color to use with mis-spelt words.
 int getUnderlineStyle()
          The underline style to use with mis-spelt words.
protected  void highlightText(BadWord theBadWord)
          Highlights a bad word in the text component The location of theBadWord must be relative to the checkFromPosition.
protected  int[] IdentifyChange()
          Returns the start and end indices in the current RTF text of the changed text (must later be adjusted for word start and end) note that end index is on right side of last character.
 void insertUpdate(javax.swing.event.DocumentEvent e)
          Gives notification that there was an insert into the document.
protected  boolean isInIgnorePos(int pos)
          Whether to ignore words starting at this position.
 void keyPressed(java.awt.event.KeyEvent e)
          Invoked when a key has been pressed.
 void keyReleased(java.awt.event.KeyEvent e)
          Invoked when a key has been pressed.
 void keyTyped(java.awt.event.KeyEvent e)
          Invoked when a key has been pressed.
 void mouseClicked(java.awt.event.MouseEvent e)
          Invoked when the mouse has been clicked on a component.
 void mouseEntered(java.awt.event.MouseEvent e)
          Invoked when the mouse enters a component.
 void mouseExited(java.awt.event.MouseEvent e)
          Invoked when the mouse exits a component.
 void mousePressed(java.awt.event.MouseEvent e)
          Invoked when a mouse button has been pressed on a component.
 void mouseReleased(java.awt.event.MouseEvent e)
          Invoked when a mouse button has been released on a component.
protected  void OnFocus(java.awt.Component sender)
          Called when text box is focused
protected  void OnPopup(java.awt.event.MouseEvent e)
          Called when context menu is popped up.
protected  void OnTextChanged()
          Called when text in text box changes
 void removeUpdate(javax.swing.event.DocumentEvent e)
           
 void setAddMenuText(java.lang.String value)
          Add button text.
 void setCheckAsYouType(boolean value)
          Whether to spell check words as the user types/modifies text.
 void setCheckCompoundWords(boolean value)
          Whether to check if words are made of compound forms - to be used in languages which use compounds, such as German.
 void setConsiderationRange(int value)
          Sets the factor for words to consider for suggestions, lower values are faster but consider less words for suggestions.
 void setDictFilePath(java.lang.String value)
          The file to be used as the main dictionary, if this is null then the RapidSpellMDict jar is used.
 void setGUILanguage(int value)
          The language to show the UI in.
 void setIgnoreAllMenuText(java.lang.String value)
          Ignore All button text.
 void setIgnoreCapitalizedWords(boolean value)
          Whether to ignore words with capital letters.
 void setIgnoreWordsWithDigits(boolean value)
          Whether to ignore words with digits in them.
 void setIgnoreXML(boolean value)
          Whether to ignore XML/HTML tags, should be set true for 'rich HTML text box' support, false by default.
 void setIncludeUserDictionaryInSuggestions(boolean value)
          Whether the user dictionary should be used in finding suggestions for misspelt words.
 void setLanguageParser(int language)
          The type of language parsing to use.
 void setLookIntoHyphenatedText(boolean value)
          Whether to 'look into' text with hyphens (-), if the word has hyphens in it and LookIntoHyphenatedText is set true (default), the parts of the text around the hyphens will be checked individually.
 void setRapidSpellChecker(RapidSpellChecker value)
          The core spell checker object
 void setSeparateHyphenWords(boolean f)
          Sets whether to treat hyphenated (-) words as separate words, default is false.
 void setShowAddMenuOption(boolean value)
          Whether to show the Add option in the context menu.
 void setShowSuggestionsContextMenu(boolean value)
          Whether to show a context menu with suggestions when a misspelt word is right clicked, has no effect on developer set context menu.
 void setSuggestionsMethod(int value)
          The suggestions method to use.
 void setSuggestSplitWords(boolean value)
          Whether to check for joined words when looking for suggestions.
 void setTextComponent(javax.swing.text.JTextComponent value)
          The JTextComponent to check as the user types/modifies text.
 void setTextComponents(javax.swing.text.JTextComponent[] value)
          The JTextComponents to check as the user types/modifies text.
 void setUnderlineColor(java.awt.Color value)
          The underline color to use with mis-spelt words.
 void setUnderlineStyle(int value)
          The underline style to use with mis-spelt words.
 void setUserDictionaryFile(java.io.File userDictionaryFile)
          Set the user dictionary file, if this file doesn't exist it will be created.
 void SetUserDictionaryFile(java.io.File userDictionaryFile)
          Set the user dictionary file, if this file doesn't exist it will be created.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RapidSpellAsYouType

public RapidSpellAsYouType()
Default constructor.
Method Detail

getRapidSpellChecker

public RapidSpellChecker getRapidSpellChecker()
The core spell checker object

setRapidSpellChecker

public void setRapidSpellChecker(RapidSpellChecker value)
The core spell checker object

getSuggestionsMethod

public int getSuggestionsMethod()
The suggestions method to use.

setSuggestionsMethod

public void setSuggestionsMethod(int value)
The suggestions method to use.

getShowAddMenuOption

public boolean getShowAddMenuOption()
Whether to show the Add option in the context menu.

setShowAddMenuOption

public void setShowAddMenuOption(boolean value)
Whether to show the Add option in the context menu.

getIgnoreXML

public boolean getIgnoreXML()
Whether to ignore XML/HTML tags, should be set true for 'rich HTML text box' support, false by default.

setIgnoreXML

public void setIgnoreXML(boolean value)
Whether to ignore XML/HTML tags, should be set true for 'rich HTML text box' support, false by default.

getCheckCompoundWords

public boolean getCheckCompoundWords()
Whether to check if words are made of compound forms - to be used in languages which use compounds, such as German.

setCheckCompoundWords

public void setCheckCompoundWords(boolean value)
Whether to check if words are made of compound forms - to be used in languages which use compounds, such as German.

getSuggestSplitWords

public boolean getSuggestSplitWords()
Whether to check for joined words when looking for suggestions.

setSuggestSplitWords

public void setSuggestSplitWords(boolean value)
Whether to check for joined words when looking for suggestions.

getIgnoreWordsWithDigits

public boolean getIgnoreWordsWithDigits()
Whether to ignore words with digits in them.

setIgnoreWordsWithDigits

public void setIgnoreWordsWithDigits(boolean value)
Whether to ignore words with digits in them.

setUserDictionaryFile

public void setUserDictionaryFile(java.io.File userDictionaryFile)
Set the user dictionary file, if this file doesn't exist it will be created. Use of a user dictionary is optional.
Parameters:
userDictionaryFile - the File to use as a user dictionary.

setSeparateHyphenWords

public void setSeparateHyphenWords(boolean f)
Sets whether to treat hyphenated (-) words as separate words, default is false. For eg. if this is true text like "cheap-deals" will be treated as two words "cheap" and "deals", otherwise this will be treated as one word "cheap-deals".

Also see setLookIntoHyphenatedText.


getSeparateHyphenWords

public boolean getSeparateHyphenWords()
Gets whether to treat hyphenated (-) words as separate words, default is false. For eg. if this is true text like "cheap-deals" will be treated as two words "cheap" and "deals", otherwise this will be treated as one word "cheap-deals".

Also see setLookIntoHyphenatedText.


getShowSuggestionsContextMenu

public boolean getShowSuggestionsContextMenu()
Whether to show a context menu with suggestions when a misspelt word is right clicked, has no effect on developer set context menu. When this property is false a context menu with suggestions is NOT shown (any existing developer set context menu is shown). When this property is true a context menu with suggestions is shown when the user's right click is on a misspelt word. A developer set context menu is always shown when a right click is off a misspelt word.

setShowSuggestionsContextMenu

public void setShowSuggestionsContextMenu(boolean value)
Whether to show a context menu with suggestions when a misspelt word is right clicked, has no effect on developer set context menu. When this property is false a context menu with suggestions is NOT shown (any existing developer set context menu is shown). When this property is true a context menu with suggestions is shown when the user's right click is on a misspelt word. A developer set context menu is always shown when a right click is off a misspelt word.

getDictFilePath

public java.lang.String getDictFilePath()
The file to be used as the main dictionary, if this is null then the RapidSpellMDict jar is used.

setDictFilePath

public void setDictFilePath(java.lang.String value)
The file to be used as the main dictionary, if this is null then the RapidSpellMDict jar is used.

getLookIntoHyphenatedText

public boolean getLookIntoHyphenatedText()
Whether to 'look into' text with hyphens (-), if the word has hyphens in it and LookIntoHyphenatedText is set true (default), the parts of the text around the hyphens will be checked individually. Eg. "socio-economic" will be checked as "socio" and "economic".

setLookIntoHyphenatedText

public void setLookIntoHyphenatedText(boolean value)
Whether to 'look into' text with hyphens (-), if the word has hyphens in it and LookIntoHyphenatedText is set true (default), the parts of the text around the hyphens will be checked individually. Eg. "socio-economic" will be checked as "socio" and "economic".

getLanguageParser

public int getLanguageParser()
Gets the type of language parsing to use.

Eg. If the dictionary is set to French, you should use the French parser.

Returns:
int identifier corresponding to LanguageType.XXXX
See Also:
LanguageType

setLanguageParser

public void setLanguageParser(int language)
The type of language parsing to use.

Eg. If the dictionary is set to French, you should use the French parser.

See Also:
LanguageType

getGUILanguage

public int getGUILanguage()
The language to show the UI in.

setGUILanguage

public void setGUILanguage(int value)
The language to show the UI in.

getIgnoreAllMenuText

public java.lang.String getIgnoreAllMenuText()
Ignore All button text.

setIgnoreAllMenuText

public void setIgnoreAllMenuText(java.lang.String value)
Ignore All button text.

getAddMenuText

public java.lang.String getAddMenuText()
Add button text.

dispose

public void dispose()
Frees up resources.

setAddMenuText

public void setAddMenuText(java.lang.String value)
Add button text.

getIncludeUserDictionaryInSuggestions

public boolean getIncludeUserDictionaryInSuggestions()
Whether the user dictionary should be used in finding suggestions for misspelt words.

setIncludeUserDictionaryInSuggestions

public void setIncludeUserDictionaryInSuggestions(boolean value)
Whether the user dictionary should be used in finding suggestions for misspelt words.

setIgnoreCapitalizedWords

public void setIgnoreCapitalizedWords(boolean value)
Whether to ignore words with capital letters.

getIgnoreCapitalizedWords

public boolean getIgnoreCapitalizedWords()
Whether to ignore words with capital letters.

getConsiderationRange

public int getConsiderationRange()
Sets the factor for words to consider for suggestions, lower values are faster but consider less words for suggestions. Default is 5000. If w <= 1 this method won't do anything.

setConsiderationRange

public void setConsiderationRange(int value)
Sets the factor for words to consider for suggestions, lower values are faster but consider less words for suggestions. Default is 5000. If w <= 1 this method won't do anything.

getCheckAsYouType

public boolean getCheckAsYouType()
Whether to spell check words as the user types/modifies text. True turns spell checking on, false turns it off. If a change of state occurs then either SpellCheckStarted or SpellCheckFinished events are fired.

setCheckAsYouType

public void setCheckAsYouType(boolean value)
Whether to spell check words as the user types/modifies text. True turns spell checking on, false turns it off. If a change of state occurs then either SpellCheckStarted or SpellCheckFinished events are fired.

getTextComponent

public javax.swing.text.JTextComponent getTextComponent()
The JTextComponent to check as the user types/modifies text.

setTextComponent

public void setTextComponent(javax.swing.text.JTextComponent value)
The JTextComponent to check as the user types/modifies text.

finalize

protected void finalize()
                 throws java.lang.Throwable
Clears up references to text boxes
Overrides:
finalize in class java.lang.Object

getTextComponents

public javax.swing.text.JTextComponent[] getTextComponents()
The JTextComponents to check as the user types/modifies text.

setTextComponents

public void setTextComponents(javax.swing.text.JTextComponent[] value)
The JTextComponents to check as the user types/modifies text.

getUnderlineStyle

public int getUnderlineStyle()
The underline style to use with mis-spelt words.

setUnderlineStyle

public void setUnderlineStyle(int value)
The underline style to use with mis-spelt words.

getUnderlineColor

public java.awt.Color getUnderlineColor()
The underline color to use with mis-spelt words.

setUnderlineColor

public void setUnderlineColor(java.awt.Color value)
The underline color to use with mis-spelt words.

forceCheckAll

public void forceCheckAll()
Forces a check of the whole document. This method is used internally, but may be of some use.

clearAllHighlights

public void clearAllHighlights()
Clears all spell check highlights (underlines) from the whole document (all text boxes).

SetUserDictionaryFile

public void SetUserDictionaryFile(java.io.File userDictionaryFile)
Set the user dictionary file, if this file doesn't exist it will be created. Use of a user dictionary is optional.
Parameters:
userDictionaryFile - the File to use as a user dictionary.

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Invoked when the mouse has been clicked on a component.
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Invoked when the mouse enters a component.
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Invoked when the mouse exits a component.
Specified by:
mouseExited in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Invoked when a mouse button has been pressed on a component.
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Invoked when a mouse button has been released on a component.
Specified by:
mouseReleased in interface java.awt.event.MouseListener

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Specified by:
actionPerformed in interface java.awt.event.ActionListener

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Invoked when a key has been pressed.
Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Invoked when a key has been pressed.
Specified by:
keyReleased in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Invoked when a key has been pressed.
Specified by:
keyTyped in interface java.awt.event.KeyListener

highlightText

protected void highlightText(BadWord theBadWord)
Highlights a bad word in the text component The location of theBadWord must be relative to the checkFromPosition.

deHighlightText

protected void deHighlightText(BadWord theBadWord)
Removes a highlight from a bad word in the text component The word specified by theBadWord does not necessarily have to have been identified as "bad", before this method is called. The location of theBadWord must be relative to the checkFromPosition.

getSuggestions

public javax.swing.JMenuItem[] getSuggestions()
Returns suggestions menu items for the last right clicked word. Null if none. Note: it is IMPERATIVE that any mouse listeners that you wish to add to the text box, are added AFTER you have called RapidSpellAsYouType.setTextComponent. Otherwise calling this method will result in suggestions being returned for the previous error, not the current error.

OnPopup

protected void OnPopup(java.awt.event.MouseEvent e)
Called when context menu is popped up.

changedUpdate

public void changedUpdate(javax.swing.event.DocumentEvent e)
Gives notification that an attribute or set of attributes changed.
Specified by:
changedUpdate in interface javax.swing.event.DocumentListener

insertUpdate

public void insertUpdate(javax.swing.event.DocumentEvent e)
Gives notification that there was an insert into the document.
Specified by:
insertUpdate in interface javax.swing.event.DocumentListener

removeUpdate

public void removeUpdate(javax.swing.event.DocumentEvent e)
Specified by:
removeUpdate in interface javax.swing.event.DocumentListener

OnTextChanged

protected void OnTextChanged()
Called when text in text box changes

focusGained

public void focusGained(java.awt.event.FocusEvent e)
Specified by:
focusGained in interface java.awt.event.FocusListener

focusLost

public void focusLost(java.awt.event.FocusEvent e)
Specified by:
focusLost in interface java.awt.event.FocusListener

OnFocus

protected void OnFocus(java.awt.Component sender)
Called when text box is focused

IdentifyChange

protected int[] IdentifyChange()
Returns the start and end indices in the current RTF text of the changed text (must later be adjusted for word start and end) note that end index is on right side of last character. eg. "cat" ^ ^ 0 3

isInIgnorePos

protected boolean isInIgnorePos(int pos)
Whether to ignore words starting at this position.

createNewTextBoxUtilityAdapter

protected TextBoxUtilityAdapter createNewTextBoxUtilityAdapter(javax.swing.text.JTextComponent textBox)
Returns a new instance of a TextBoxUtilityAdapter, for 'textBox'.

RapidSpell Desktop


Copyright © 2002-2005 Keyoti Inc. All Rights Reserved.