source: branches/2.2/jabberit_messenger/java_source/src/com/swabunga/spell/event/BasicSpellCheckEvent.java @ 3102

Revision 3102, 3.3 KB checked in by amuller, 14 years ago (diff)

Ticket #986 - Efetuado merge para o Branch 2.2( atualizacao do modulo)

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