|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.wintertree.ssce.StringWordParser
com.jivesoftware.spark.component.spelling.JTextComponentWordParser
Parse words from a Swing JTextComponent. In addition to parsing, this class can also delete words, replace words, and detect doubled words. JTextComponentWordParser maintains a cursor which points to the start of the current word. The current word is always selected in the JTextComponent to show context. This class is part of the Sentry Java SDK examples.
The text in the JTextComponent is read when the JTextComponentWordParser is constructed. If the contents of the JTextComponent change, the updateText method must be called.
If the JTextComponent can contain text with HTML markups, extend this class from HTMLStringWordParser instead of StringWordParser.
Field Summary | |
protected javax.swing.text.JTextComponent |
component
The JTextComponent being parsed. |
Fields inherited from class com.wintertree.ssce.StringWordParser |
cachedWord, cursor, is1stWord, isHyphenDelimiter, nReplacements, nWords, subWordLength, theString |
Constructor Summary | |
JTextComponentWordParser(javax.swing.text.JTextComponent component,
boolean isHyphenDelim,
boolean selectCurWord)
Construct a JTextComponentWordParser to parse words from the contents of a JTextComponent. |
Method Summary | |
void |
deleteText(int numChars)
Delete a specified number of characters from the text starting at the current cursor position. |
void |
highlightWord()
Highlight the current word in the text area. |
void |
insertText(int pos,
java.lang.String newText)
Insert text at a specified position. |
void |
replaceWord(java.lang.String newWord)
Replace the word at the current position with a new word. |
void |
updateText()
Report that the contents of the TextArea have changed. |
Methods inherited from class com.wintertree.ssce.StringWordParser |
deleteWord, deleteWord, findWordStart, getCursor, getNumReplacements, getNumWords, getPrevWord, getWord, hasMoreElements, includeCharInWord, includeCharInWord, is1stWordChar, isDoubledWord, isFirstWord, isWordChar, nextElement, nextWord, setCursor, setText, setWordLength, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected javax.swing.text.JTextComponent component
Constructor Detail |
public JTextComponentWordParser(javax.swing.text.JTextComponent component, boolean isHyphenDelim, boolean selectCurWord)
component
- The JTextComponent to parse.isHyphenDelim
- true if a hyphen is to be considered a word
delimiter, false if it's part of a wordselectCurWord
- true if each word should be selected in the
component to show context. Enabling this option degrades performance.Method Detail |
public void deleteText(int numChars) throws java.util.NoSuchElementException
numChars
- The number of characters to delete.
java.util.NoSuchElementException
- Attempt to delete beyond the end of
the string.public void highlightWord()
public void insertText(int pos, java.lang.String newText)
pos
- The position at which new text is to be inserted.newText
- The text to insert.public void replaceWord(java.lang.String newWord) throws java.util.NoSuchElementException
newWord
- The word to replace the word at the current position.
java.util.NoSuchElementException
- The cursor is positioned at the end
of the string.public void updateText()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |