RapidSpell Desktop


com.keyoti.rapidSpell
Class RapidSpellGUI

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
                    |
                    +--java.awt.Frame
                          |
                          +--javax.swing.JFrame
                                |
                                +--com.keyoti.rapidSpell.RapidSpellGUI
All Implemented Interfaces:
Accessible, ActionListener, EventListener, FocusListener, ImageObserver, ItemListener, MenuContainer, RootPaneContainer, Runnable, Serializable, WindowConstants

public class RapidSpellGUI
extends JFrame
implements ActionListener, ItemListener, Runnable, FocusListener

Multi-threaded GUI for user to spell check any JTextComponent (eg, JEditorPane, JTextArea, JTextField).

To use this GUI bean component as an integral part of your application simply instantiate it, set the JTextComponent you wish this GUI to spell check and call check(), which will bring up this component in a new JFrame allowing the user to correct their document in the JTextComponent.

Example 1. Complete trivial application using the RapidSpell GUI.



import com.keyoti.rapidSpell.*;
import javax.swing.*;
import java.awt.event.*;

public class TestGUI extends JFrame {

	JTextArea box = new JTextArea("This is sume text to check.", 20, 60);
	RapidSpellGUI rapidGUI = new RapidSpellGUI();

	public TestGUI() {
		//put the text box in the JFrame
		getContentPane().add(box);

		//pack and display the JFrame
		pack(); 
		setVisible(true);

		//open the GUI spell checker and begin checking the text box.
		rapidGUI.check( box );
	}

	public static void main(String[] args) {
		TestGUI t = new TestGUI();
	}
}

	

You may wish to customise this GUI yourself, in which case simply extend this class, override buildGUI() and use the protected fields as you wish. For example

Example 2. Custom GUI for this component (see CustomGUI.java for more).


import com.keyoti.rapidSpell.RapidSpellGUI;
import javax.swing.*;
import java.awt.*;

public class CustomGUI extends RapidSpellGUI
{
	public CustomGUI()
	{
		super();
	}
	
	// VERY SIMPLE, BUT UGLY LOOKING EXAMPLE
	public void buildGUI()
	{
		Box myBox = Box.createVerticalBox();

		//define the protected fields as I want
		ignoreButton.setText("Ignore");
		ignoreAllButton.setText("Ignore All");
		changeButton.setText("Change");
		changeAllButton.setText("Change All");
		cancelButton.setText("Cancel");

		//add all the protected fields I want to use and layout as I wish
		myBox.add(notInDictionaryLabel);
		myBox.add(queryWordPane);
		myBox.add(ignoreButton);
		myBox.add(ignoreAllButton);
		myBox.add(new JScrollPane(suggestionsList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED ));
		myBox.add(changeButton);
		myBox.add(changeAllButton);
		myBox.add(cancelButton);
		
		getContentPane().add(myBox);
	}
}
 

Version:
2.0.0
Author:
Keyoti
See Also:
Serialized Form

Inner classes inherited from class javax.swing.JFrame
JFrame.AccessibleJFrame
 
Inner classes inherited from class java.awt.Frame
Frame.AccessibleAWTFrame
 
Inner classes inherited from class java.awt.Window
Window.AccessibleAWTWindow
 
Inner classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
Component.AccessibleAWTComponent
 
Field Summary
protected  JButton addButton
          Function button - adds word in query pane to user dictionary if specified.
protected  JButton cancelButton
          Function button - cancels the search and disposes of this JFrame.
protected  JButton changeAllButton
          Function button - changes every occurance of bad word in document.
protected  JButton changeButton
          Function button - changes bad word in document to selected suggestion or amended query pane word.
protected  boolean findSuggestions
          Whether this should look up suggestions for misspelt words or not
static int HASHING_SUGGESTIONS
          Indicator for suggestion method (Hashing is default).
protected  JButton ignoreAllButton
          Function button - ignores all occurances of current bad word.
protected  JButton ignoreButton
          Function button - ignores current bad word and continues checking document.
protected  JLabel notInDictionaryLabel
          JLabel marking the not in dictionary query pane.
static int PHONETIC_SUGGESTIONS
          Indicator for suggestion method (Hashing is default).
protected  JTextArea queryWordPane
          JTextArea where not in dictionary (bad words) are queried and replacements can be entered.
protected  JCheckBox suggestionFinderCheckBox
          Check box - enables/disables the suggestion finder
protected  JLabel suggestionsLabel
          JLabel marking the suggestions JList, is changed to "Finding Suggestions..." periodically.
protected  JList suggestionsList
          JList where suggestions are loaded.
protected  ICheckerEngine theSpellChecker
          The spell checker component being used
protected  JTextComponent theTextComponent
          The text component being checked
 
Fields inherited from class javax.swing.JFrame
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
RapidSpellGUI()
          Construct this GUI component - this will NOT open a new JFrame, call check() to do that.
 
Method Summary
 void actionPerformed(ActionEvent e)
          Listen to GUI events and perform actions depending on the button sending the event.
 void addSpellCheckListener(SpellCheckListener l)
          Adds a SpellCheckListener.
protected  void buildGUI()
          Constructs the GUI - This should be over-ridden by sub-classes that wish to use their own layout.
 void check()
          Bring up the spell checker JFrame and start checking the component set by setJTextComponentToCheck().
 void check(JTextComponent textComponent)
          Bring up the spell checker JFrame and start checking the JTextComponent textComponent.
 void focusGained(FocusEvent e)
          Called when objects whose focus this is listening to gain focus.
 void focusLost(FocusEvent e)
          Empty
 ICheckerEngine getCheckerEngine()
          Gets the checker engine to use, this object must implement the ICheckerEngine interface, allows customization or replacement of the spell checker.
 String getDictFilePath()
          The file to be used as the main dictionary, if this is null then the RapidSpellMDict jar is used.
 Color getHighlightColor()
          Gets the color of the highlight used in the JTextComponent when misspelt words are found.
 boolean getIgnoreCapitalizedWords()
          Gets whether to ignore words that start with capital letters.
 boolean getIgnoreXML()
          Whether to ignore XML/HTML tags, should be set true for 'rich HTML text box' support, false by default.
 boolean getIncludeUserDictionaryInSuggestions()
          Gets whether the user dictionary should be used in finding suggestions for misspelt words.
 boolean getSeparateHyphenWords()
          Gets whether to treat hyphenated (-) words as separate words, default is false.
 SpellCheckListener[] getSpellCheckListeners()
          Gets all SpellCheckListeners.
 int getSuggestionsMethod()
          Gets the suggestions method to use.
 boolean isShowFinishedMessageBox()
          Returns whether a JOptionPane message box should be opened when the spell check is complete.
 void itemStateChanged(ItemEvent e)
          Listen to GUI events and perform actions.
 void removeSpellCheckListener(SpellCheckListener l)
          Removes a SpellCheckListener.
 void run()
          Called by the constructor in a new thread, to setup document parameters and check the text while the GUI components instantiate.
 void setCheckerEngine(ICheckerEngine value)
          Sets the checker engine to use, this object must implement the ICheckerEngine interface, allows customization or replacement of the spell checker.
 void setDictFilePath(String value)
          The file to be used as the main dictionary, if this is null then the RapidSpellMDict jar is used.
 void setHighlightColor(Color c)
          Sets the color of the highlight used in the JTextComponent when misspelt words are found.
 void setIgnoreCapitalizedWords(boolean v)
          Sets whether to ignore words that start with capital letters.
 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 v)
          Sets whether the user dictionary should be used in finding suggestions for misspelt words.
 void setJTextComponentToCheck(JTextComponent textComponent)
          Set the JTextComponent (eg; JTextArea etc) that this GUI will spell check.
 void setSeparateHyphenWords(boolean f)
          Sets whether to treat hyphenated (-) words as separate words, default is false.
 void setShowFinishedMessageBox(boolean b)
          Sets whether a JOptionPane message box should be opened when the spell check is complete.
 void setSuggestionsMethod(int method)
          Sets the suggestions method to use.
 void setUserDictionaryFile(File userDictionaryFile)
          Set the user dictionary file, if this file doesn't exist it will be created.
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isRootPaneCheckingEnabled, paramString, processKeyEvent, processWindowEvent, remove, setContentPane, setDefaultCloseOperation, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.awt.Frame
addNotify, finalize, getCursorType, getFrames, getIconImage, getMenuBar, getState, getTitle, isResizable, remove, removeNotify, setCursor, setIconImage, setMenuBar, setResizable, setState, setTitle
 
Methods inherited from class java.awt.Window
addWindowListener, applyResourceBundle, applyResourceBundle, dispose, getFocusOwner, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getOwnedWindows, getOwner, getToolkit, getWarningString, hide, isShowing, pack, postEvent, processEvent, removeWindowListener, setCursor, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setFont, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseMotionEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

theSpellChecker

protected ICheckerEngine theSpellChecker
The spell checker component being used

theTextComponent

protected JTextComponent theTextComponent
The text component being checked

findSuggestions

protected boolean findSuggestions
Whether this should look up suggestions for misspelt words or not

changeButton

protected JButton changeButton
Function button - changes bad word in document to selected suggestion or amended query pane word.

ignoreButton

protected JButton ignoreButton
Function button - ignores current bad word and continues checking document.

ignoreAllButton

protected JButton ignoreAllButton
Function button - ignores all occurances of current bad word.

addButton

protected JButton addButton
Function button - adds word in query pane to user dictionary if specified.

changeAllButton

protected JButton changeAllButton
Function button - changes every occurance of bad word in document.

cancelButton

protected JButton cancelButton
Function button - cancels the search and disposes of this JFrame.

suggestionFinderCheckBox

protected JCheckBox suggestionFinderCheckBox
Check box - enables/disables the suggestion finder

queryWordPane

protected final JTextArea queryWordPane
JTextArea where not in dictionary (bad words) are queried and replacements can be entered.

suggestionsList

protected final JList suggestionsList
JList where suggestions are loaded.

PHONETIC_SUGGESTIONS

public static int PHONETIC_SUGGESTIONS
Indicator for suggestion method (Hashing is default).

HASHING_SUGGESTIONS

public static int HASHING_SUGGESTIONS
Indicator for suggestion method (Hashing is default).

suggestionsLabel

protected JLabel suggestionsLabel
JLabel marking the suggestions JList, is changed to "Finding Suggestions..." periodically.

notInDictionaryLabel

protected JLabel notInDictionaryLabel
JLabel marking the not in dictionary query pane.
Constructor Detail

RapidSpellGUI

public RapidSpellGUI()
Construct this GUI component - this will NOT open a new JFrame, call check() to do that.
Method Detail

actionPerformed

public void actionPerformed(ActionEvent e)
Listen to GUI events and perform actions depending on the button sending the event.
Specified by:
actionPerformed in interface ActionListener

check

public void check()
           throws NullJTextComponentException
Bring up the spell checker JFrame and start checking the component set by setJTextComponentToCheck().
Throws:
NullJTextComponentException - if setJTextComponentToCheck() hasn't be called first with a JTextComponent object.

check

public void check(JTextComponent textComponent)
           throws NullPointerException
Bring up the spell checker JFrame and start checking the JTextComponent textComponent.
Throws:
NullPointerException - if textComponent parameteris null.

setShowFinishedMessageBox

public void setShowFinishedMessageBox(boolean b)
Sets whether a JOptionPane message box should be opened when the spell check is complete.
Parameters:
b - boolean indicating if the message box should be opened.
Since:
v1.1

isShowFinishedMessageBox

public boolean isShowFinishedMessageBox()
Returns whether a JOptionPane message box should be opened when the spell check is complete.
Since:
v1.1

setJTextComponentToCheck

public void setJTextComponentToCheck(JTextComponent textComponent)
                              throws NullPointerException
Set the JTextComponent (eg; JTextArea etc) that this GUI will spell check.
Parameters:
textComponent - the JTextComponent that this will spell check.
Throws:
NullPointerException - if textComponent parameter is null.

setHighlightColor

public void setHighlightColor(Color c)
                       throws NullPointerException
Sets the color of the highlight used in the JTextComponent when misspelt words are found.
Parameters:
c - new highlight color.
Throws:
NullPointerException - if c is null.
Since:
v1.1

getHighlightColor

public Color getHighlightColor()
Gets the color of the highlight used in the JTextComponent when misspelt words are found.
Since:
v1.1

setUserDictionaryFile

public void setUserDictionaryFile(File userDictionaryFile)
                           throws NullPointerException
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.

getDictFilePath

public 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(String value)
The file to be used as the main dictionary, if this is null then the RapidSpellMDict jar is used.

setCheckerEngine

public void setCheckerEngine(ICheckerEngine value)
Sets the checker engine to use, this object must implement the ICheckerEngine interface, allows customization or replacement of the spell checker.

Use this property to replace the object used to perform checking, it is not necessary to replace this with a spell checker, any type of word parser can be used. For example an abbreviations checker could be written to replace common words with abbreviations.


getCheckerEngine

public ICheckerEngine getCheckerEngine()
Gets the checker engine to use, this object must implement the ICheckerEngine interface, allows customization or replacement of the spell checker.

Use this property to replace the object used to perform checking, it is not necessary to replace this with a spell checker, any type of word parser can be used. For example an abbreviations checker could be written to replace common words with abbreviations.


setSuggestionsMethod

public void setSuggestionsMethod(int method)
Sets the suggestions method to use. Either PHONETIC_SUGGESTIONS or HASHING_SUGGESTIONS

getSuggestionsMethod

public int getSuggestionsMethod()
Gets the suggestions method to use. Either PHONETIC_SUGGESTIONS or HASHING_SUGGESTIONS

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.


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.

itemStateChanged

public void itemStateChanged(ItemEvent e)
Listen to GUI events and perform actions.
Specified by:
itemStateChanged in interface ItemListener

buildGUI

protected void buildGUI()
                 throws Exception
Constructs the GUI - This should be over-ridden by sub-classes that wish to use their own layout.

Note, the only requirements are as follows:

1. whatever is constructed is added to the contentPane from here, eg;

this.getContentPane().add(myMainJPanel);

2. the queryWordPane and suggestionsList should be used for 'not in dictionary' words and suggestions respectively, these may not be over-ridden.

Returns:
void
Throws:
Exception - if any problems occur
See Also:
suggestionsList, queryWordPane

focusGained

public void focusGained(FocusEvent e)
Called when objects whose focus this is listening to gain focus.
Specified by:
focusGained in interface FocusListener

focusLost

public void focusLost(FocusEvent e)
Empty
Specified by:
focusLost in interface FocusListener

setIncludeUserDictionaryInSuggestions

public void setIncludeUserDictionaryInSuggestions(boolean v)
Sets whether the user dictionary should be used in finding suggestions for misspelt words.

getIncludeUserDictionaryInSuggestions

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

setIgnoreCapitalizedWords

public void setIgnoreCapitalizedWords(boolean v)
Sets whether to ignore words that start with capital letters.

getIgnoreCapitalizedWords

public boolean getIgnoreCapitalizedWords()
Gets whether to ignore words that start with capital letters.

addSpellCheckListener

public void addSpellCheckListener(SpellCheckListener l)
Adds a SpellCheckListener.
Since:
v1.1

removeSpellCheckListener

public void removeSpellCheckListener(SpellCheckListener l)
Removes a SpellCheckListener.
Since:
v1.1

getSpellCheckListeners

public SpellCheckListener[] getSpellCheckListeners()
Gets all SpellCheckListeners.
Since:
v1.1

run

public void run()
Called by the constructor in a new thread, to setup document parameters and check the text while the GUI components instantiate.
Specified by:
run in interface Runnable

RapidSpell Desktop


Copyright © 2002-2003 Keyoti All Rights Reserved.