1 package com
.swabunga
.spell
.event
;
5 /** This event is fired off by the SpellChecker and is passed to the
6 * registered SpellCheckListeners
8 * @author Jason Height (jheight@chariot.net.au)
10 class BasicSpellCheckEvent
implements SpellCheckEvent
{
11 /**The list holding the suggested Word objects for the misspelt word*/
12 private List suggestions
;
13 /**The misspelt word*/
14 private String invalidWord
;
15 /**The action to be done when the event returns*/
16 private short action
= INITIAL
;
17 /**Contains the word to be replaced if the action is REPLACE or REPLACEALL*/
18 private String replaceWord
= null
;
20 private String context
;
21 private int startPosition
;
24 /**Consructs the SpellCheckEvent
25 * @param String invalidWord The word that is misspelt
26 * @param List suggestions A list of Word objects that are suggested to replace the currently mispelt word
27 * @param WordTokenizer tokenizer The reference to the tokenizer that caused this
30 public BasicSpellCheckEvent(String invalidWord
, List suggestions
, WordTokenizer tokenizer
) {
31 this.invalidWord
= invalidWord
;
32 this.suggestions
= suggestions
;
33 this.context
= tokenizer
.getContext();
34 this.startPosition
= tokenizer
.getCurrentWordPosition();
37 /** Returns the list of suggested Word objects*/
38 public List
getSuggestions() {
42 /** Returns the currently misspelt word*/
43 public String
getInvalidWord() {
47 public String
getWordContext() {
52 /** Returns the start position of the misspelt word in the context*/
53 public int getWordContextPosition() {
57 public short getAction() {
61 public String
getReplaceWord() {
65 /** Set the action to replace the currently misspelt word with the new word
66 * @param String newWord The word to replace the currently misspelt word
67 * @param boolean replaceAll If set to true, the SpellChecker will replace all
68 * further occurances of the misspelt word without firing a SpellCheckEvent.
70 public void replaceWord(String newWord
, boolean replaceAll
) {
71 if (action
!= INITIAL
)
72 throw new IllegalStateException("The action can can only be set once");
75 else action
= REPLACE
;
76 replaceWord
= newWord
;
79 /** Set the action it ignore the currently misspelt word.
80 * @param boolean ignoreAll If set to true, the SpellChecker will replace all
81 * further occurances of the misspelt word without firing a SpellCheckEvent.
83 public void ignoreWord(boolean ignoreAll
) {
84 if (action
!= INITIAL
)
85 throw new IllegalStateException("The action can can only be set once");
91 /** Set the action to add a new word into the dictionary. This will also replace the
92 * currently misspelt word.
94 public void addToDictionary(String newWord
) {
95 if (action
!= INITIAL
)
96 throw new IllegalStateException("The action can can only be set once");
98 replaceWord
= newWord
;
101 public void cancel() {
102 if (action
!= INITIAL
)
103 throw new IllegalStateException("The action can can only be set once");