Commit | Line | Data |
---|---|---|
6dd70280 JL |
1 | package com.swabunga.spell.event;\r\r |
2 | \r\r | |
3 | import java.util.*;\r\r | |
4 | \r\r | |
5 | /** This event is fired off by the SpellChecker and is passed to the\r\r | |
6 | * registered SpellCheckListeners\r\r | |
7 | *\r\r | |
8 | * @author Jason Height (jheight@chariot.net.au)\r\r | |
9 | */\r\r | |
10 | class BasicSpellCheckEvent implements SpellCheckEvent {\r\r | |
11 | /**The list holding the suggested Word objects for the misspelt word*/\r\r | |
12 | private List suggestions;\r\r | |
13 | /**The misspelt word*/\r\r | |
14 | private String invalidWord;\r\r | |
15 | /**The action to be done when the event returns*/\r\r | |
16 | private short action = INITIAL;\r\r | |
17 | /**Contains the word to be replaced if the action is REPLACE or REPLACEALL*/\r\r | |
18 | private String replaceWord = null;\r\r | |
19 | \r\r | |
20 | private String context;\r\r | |
21 | private int startPosition;\r\r | |
22 | \r\r | |
23 | \r\r | |
24 | /**Consructs the SpellCheckEvent\r\r | |
25 | * @param String invalidWord The word that is misspelt\r\r | |
26 | * @param List suggestions A list of Word objects that are suggested to replace the currently mispelt word\r\r | |
27 | * @param WordTokenizer tokenizer The reference to the tokenizer that caused this\r\r | |
28 | * event to fire.\r\r | |
29 | */\r\r | |
30 | public BasicSpellCheckEvent(String invalidWord, List suggestions, WordTokenizer tokenizer) {\r\r | |
31 | this.invalidWord = invalidWord;\r\r | |
32 | this.suggestions = suggestions;\r\r | |
33 | this.context = tokenizer.getContext();\r\r | |
34 | this.startPosition = tokenizer.getCurrentWordPosition();\r\r | |
35 | }\r\r | |
36 | \r\r | |
37 | /** Returns the list of suggested Word objects*/\r\r | |
38 | public List getSuggestions() {\r\r | |
39 | return suggestions;\r\r | |
40 | }\r\r | |
41 | \r\r | |
42 | /** Returns the currently misspelt word*/\r\r | |
43 | public String getInvalidWord() {\r\r | |
44 | return invalidWord;\r\r | |
45 | }\r\r | |
46 | \r\r | |
47 | public String getWordContext() {\r\r | |
48 | //JMH TBD\r\r | |
49 | return null;\r\r | |
50 | }\r\r | |
51 | \r\r | |
52 | /** Returns the start position of the misspelt word in the context*/\r\r | |
53 | public int getWordContextPosition() {\r\r | |
54 | return startPosition;\r\r | |
55 | }\r\r | |
56 | \r\r | |
57 | public short getAction() {\r\r | |
58 | return action;\r\r | |
59 | }\r\r | |
60 | \r\r | |
61 | public String getReplaceWord() {\r\r | |
62 | return replaceWord;\r\r | |
63 | }\r\r | |
64 | \r\r | |
65 | /** Set the action to replace the currently misspelt word with the new word\r\r | |
66 | * @param String newWord The word to replace the currently misspelt word\r\r | |
67 | * @param boolean replaceAll If set to true, the SpellChecker will replace all\r\r | |
68 | * further occurances of the misspelt word without firing a SpellCheckEvent.\r\r | |
69 | */\r\r | |
70 | public void replaceWord(String newWord, boolean replaceAll) {\r\r | |
71 | if (action != INITIAL)\r\r | |
72 | throw new IllegalStateException("The action can can only be set once");\r\r | |
73 | if (replaceAll)\r\r | |
74 | action = REPLACEALL;\r\r | |
75 | else action = REPLACE;\r\r | |
76 | replaceWord = newWord;\r\r | |
77 | }\r\r | |
78 | \r\r | |
79 | /** Set the action it ignore the currently misspelt word.\r\r | |
80 | * @param boolean ignoreAll If set to true, the SpellChecker will replace all\r\r | |
81 | * further occurances of the misspelt word without firing a SpellCheckEvent.\r\r | |
82 | */\r\r | |
83 | public void ignoreWord(boolean ignoreAll) {\r\r | |
84 | if (action != INITIAL)\r\r | |
85 | throw new IllegalStateException("The action can can only be set once");\r\r | |
86 | if (ignoreAll)\r\r | |
87 | action = IGNOREALL;\r\r | |
88 | else action = IGNORE;\r\r | |
89 | }\r\r | |
90 | \r\r | |
91 | /** Set the action to add a new word into the dictionary. This will also replace the\r\r | |
92 | * currently misspelt word.\r\r | |
93 | */\r\r | |
94 | public void addToDictionary(String newWord) {\r\r | |
95 | if (action != INITIAL)\r\r | |
96 | throw new IllegalStateException("The action can can only be set once");\r\r | |
97 | action = ADDTODICT;\r\r | |
98 | replaceWord = newWord;\r\r | |
99 | }\r\r | |
100 | \r\r | |
101 | public void cancel() {\r\r | |
102 | if (action != INITIAL)\r\r | |
103 | throw new IllegalStateException("The action can can only be set once");\r\r | |
104 | action = CANCEL;\r\r | |
105 | }\r\r | |
106 | } |