|
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.desktop.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.desktop.*;
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.desktop.*;
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 |
javax.swing.JFrame.AccessibleJFrame |
Field Summary | |
protected javax.swing.JButton |
addButton
Function button - adds word in query pane to user dictionary if specified. |
protected javax.swing.JButton |
cancelButton
Function button - cancels the search and disposes of this JFrame. |
protected javax.swing.JButton |
changeAllButton
Function button - changes every occurance of bad word in document. |
protected javax.swing.JButton |
changeButton
Function button - changes bad word in document to selected suggestion or amended query pane word. |
boolean |
disposeAtEnd
Whether to dispose of this frame when checking is finished |
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 javax.swing.JButton |
ignoreAllButton
Function button - ignores all occurances of current bad word. |
protected javax.swing.JButton |
ignoreButton
Function button - ignores current bad word and continues checking document. |
protected javax.swing.JLabel |
notInDictionaryLabel
JLabel marking the not in dictionary query pane. |
static int |
PHONETIC_SUGGESTIONS
Indicator for suggestion method (Hashing is default). |
protected javax.swing.JTextArea |
queryWordPane
JTextArea where not in dictionary (bad words) are queried and replacements can be entered. |
protected javax.swing.JCheckBox |
suggestionFinderCheckBox
Check box - enables/disables the suggestion finder |
protected javax.swing.JLabel |
suggestionsLabel
JLabel marking the suggestions JList, is changed to "Finding Suggestions..." periodically. |
protected javax.swing.JList |
suggestionsList
JList where suggestions are loaded. |
protected ICheckerEngine |
theSpellChecker
The spell checker component being used |
protected java.lang.ref.WeakReference |
theTextComponentRef
Weak reference to the text component being checked |
Fields inherited from class javax.swing.JFrame |
accessibleContext,
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 |
Constructor Summary | |
RapidSpellGUI()
Construct this GUI component - this will NOT open a new JFrame, call check() to do that. |
Method Summary | |
void |
actionPerformed(java.awt.event.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(javax.swing.text.JTextComponent textComponent)
Bring up the spell checker JFrame and start checking the JTextComponent textComponent . |
void |
dispose()
Frees up resources. |
void |
focusGained(java.awt.event.FocusEvent e)
Called when objects whose focus this is listening to gain focus. |
void |
focusLost(java.awt.event.FocusEvent e)
Empty |
boolean |
getCheckCompoundWords()
Whether to check if words are made of compound forms - to be used in languages which use compounds, such as German. |
ICheckerEngine |
getCheckerEngine()
Gets the checker engine to use, this object must implement the ICheckerEngine interface, allows customization or replacement of the spell checker. |
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.awt.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 |
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()
Gets 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. |
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 |
getSuggestSplitWords()
Whether to check for joined words when looking for suggestions. |
boolean |
isCancelled()
Whether the spell check was cancelled |
boolean |
isShowFinishedMessageBox()
Returns whether a JOptionPane message box should be opened when the spell check is complete. |
void |
itemStateChanged(java.awt.event.ItemEvent e)
Listen to GUI events and perform actions. |
protected java.lang.String |
makeChange(boolean inChangeAllProcess)
Changes the current bad word for one selected from the suggestions list or entered in the query pane returns the word used. |
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 |
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 |
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(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 |
setHighlightColor(java.awt.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 |
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 v)
Sets whether the user dictionary should be used in finding suggestions for misspelt words. |
void |
setJTextComponentToCheck(javax.swing.text.JTextComponent textComponent)
Set the JTextComponent (eg; JTextArea etc) that this GUI will spell check. |
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 |
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 |
setSuggestSplitWords(boolean value)
Whether to check for joined words when looking for suggestions. |
void |
setUserDictionaryFile(java.io.File userDictionaryFile)
Set the user dictionary file, if this file doesn't exist it will be created. |
protected boolean |
shouldEnableAddButton()
|
protected javax.swing.text.JTextComponent |
theTextComponent()
Returns the instance of the text component being checked, from the WeakReference held |
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,
getFocusOwner,
getInputContext,
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,
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,
processInputMethodEvent,
processMouseEvent,
processMouseMotionEvent,
removeComponentListener,
removeFocusListener,
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 |
Field Detail |
protected ICheckerEngine theSpellChecker
protected java.lang.ref.WeakReference theTextComponentRef
protected boolean findSuggestions
protected javax.swing.JButton changeButton
protected javax.swing.JButton ignoreButton
protected javax.swing.JButton ignoreAllButton
protected javax.swing.JButton addButton
protected javax.swing.JButton changeAllButton
protected javax.swing.JButton cancelButton
protected javax.swing.JCheckBox suggestionFinderCheckBox
protected final javax.swing.JTextArea queryWordPane
protected final javax.swing.JList suggestionsList
public static int PHONETIC_SUGGESTIONS
public static int HASHING_SUGGESTIONS
protected javax.swing.JLabel suggestionsLabel
protected javax.swing.JLabel notInDictionaryLabel
public boolean disposeAtEnd
Constructor Detail |
public RapidSpellGUI()
Method Detail |
protected javax.swing.text.JTextComponent theTextComponent()
public void actionPerformed(java.awt.event.ActionEvent e)
public void check() throws NullJTextComponentException
public void check(javax.swing.text.JTextComponent textComponent) throws java.lang.NullPointerException
textComponent
.public boolean isCancelled()
public void setShowFinishedMessageBox(boolean b)
b
- boolean indicating if the message box should be opened.public boolean isShowFinishedMessageBox()
public void setJTextComponentToCheck(javax.swing.text.JTextComponent textComponent)
textComponent
- the JTextComponent that this will spell check.public void setHighlightColor(java.awt.Color c) throws java.lang.NullPointerException
c
- new highlight color.public java.awt.Color getHighlightColor()
public void setUserDictionaryFile(java.io.File userDictionaryFile) throws java.lang.NullPointerException
userDictionaryFile
- the File to use as a user dictionary.public java.lang.String getDictFilePath()
public void setDictFilePath(java.lang.String value)
public boolean getCheckCompoundWords()
public void setCheckCompoundWords(boolean value)
public boolean getSuggestSplitWords()
public void setSuggestSplitWords(boolean value)
public boolean getIgnoreWordsWithDigits()
public void setIgnoreWordsWithDigits(boolean 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 boolean getLookIntoHyphenatedText()
public void setLookIntoHyphenatedText(boolean value)
public int getLanguageParser()
Eg. If the dictionary is set to French, you should use the French parser.
LanguageType
public void setLanguageParser(int language)
Eg. If the dictionary is set to French, you should use the French parser.
LanguageType
public int getGUILanguage()
public void setGUILanguage(int value)
public void dispose()
public void itemStateChanged(java.awt.event.ItemEvent e)
protected boolean shouldEnableAddButton()
protected void buildGUI() throws java.lang.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.
suggestionsList
,
queryWordPane
public void focusGained(java.awt.event.FocusEvent e)
public void focusLost(java.awt.event.FocusEvent e)
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()
protected java.lang.String makeChange(boolean inChangeAllProcess)
|
RapidSpell Desktop |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |