|
RapidSpell Desktop |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--java.awt.Window | +--java.awt.Frame | +--javax.swing.JFrame | +--com.keyoti.rapidSpell.RapidSpellGUI
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);
}
}
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.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.awt.MenuContainer |
getFont, postEvent |
Field Detail |
protected ICheckerEngine theSpellChecker
protected JTextComponent theTextComponent
protected boolean findSuggestions
protected JButton changeButton
protected JButton ignoreButton
protected JButton ignoreAllButton
protected JButton addButton
protected JButton changeAllButton
protected JButton cancelButton
protected JCheckBox suggestionFinderCheckBox
protected final JTextArea queryWordPane
protected final JList suggestionsList
public static int PHONETIC_SUGGESTIONS
public static int HASHING_SUGGESTIONS
protected JLabel suggestionsLabel
protected JLabel notInDictionaryLabel
Constructor Detail |
public RapidSpellGUI()
Method Detail |
public void actionPerformed(ActionEvent e)
actionPerformed
in interface ActionListener
public void check() throws NullJTextComponentException
NullJTextComponentException
- if setJTextComponentToCheck() hasn't be called first with a JTextComponent object.public void check(JTextComponent textComponent) throws NullPointerException
textComponent
.NullPointerException
- if textComponent parameteris null.public void setShowFinishedMessageBox(boolean b)
b
- boolean indicating if the message box should be opened.public boolean isShowFinishedMessageBox()
public void setJTextComponentToCheck(JTextComponent textComponent) throws NullPointerException
textComponent
- the JTextComponent that this will spell check.NullPointerException
- if textComponent parameter is null.public void setHighlightColor(Color c) throws NullPointerException
c
- new highlight color.NullPointerException
- if c is null.public Color getHighlightColor()
public void setUserDictionaryFile(File userDictionaryFile) throws NullPointerException
userDictionaryFile
- the File to use as a user dictionary.public String getDictFilePath()
public void setDictFilePath(String value)
public void setCheckerEngine(ICheckerEngine value)
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.
public ICheckerEngine getCheckerEngine()
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.
public void setSuggestionsMethod(int method)
public int getSuggestionsMethod()
public void setSeparateHyphenWords(boolean f)
Also see setLookIntoHyphenatedText.
public boolean getSeparateHyphenWords()
Also see setLookIntoHyphenatedText.
public boolean getIgnoreXML()
public void setIgnoreXML(boolean value)
public void itemStateChanged(ItemEvent e)
itemStateChanged
in interface ItemListener
protected void buildGUI() throws Exception
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.
Exception
- if any problems occursuggestionsList
,
queryWordPane
public void focusGained(FocusEvent e)
focusGained
in interface FocusListener
public void focusLost(FocusEvent e)
focusLost
in interface FocusListener
public void setIncludeUserDictionaryInSuggestions(boolean v)
public boolean getIncludeUserDictionaryInSuggestions()
public void setIgnoreCapitalizedWords(boolean v)
public boolean getIgnoreCapitalizedWords()
public void addSpellCheckListener(SpellCheckListener l)
public void removeSpellCheckListener(SpellCheckListener l)
public SpellCheckListener[] getSpellCheckListeners()
public void run()
run
in interface Runnable
|
RapidSpell Desktop |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |