Initial revision
[old-projects.git] / ekit / com / swabunga / spell / event / BasicSpellCheckEvent.java
diff --git a/ekit/com/swabunga/spell/event/BasicSpellCheckEvent.java b/ekit/com/swabunga/spell/event/BasicSpellCheckEvent.java
new file mode 100644 (file)
index 0000000..d199fc6
--- /dev/null
@@ -0,0 +1,106 @@
+package com.swabunga.spell.event;\r\r
+\r\r
+import java.util.*;\r\r
+\r\r
+/** This event is fired off by the SpellChecker and is passed to the\r\r
+ *  registered SpellCheckListeners\r\r
+ *\r\r
+ * @author Jason Height (jheight@chariot.net.au)\r\r
+ */\r\r
+class BasicSpellCheckEvent implements SpellCheckEvent {\r\r
+  /**The list holding the suggested Word objects for the misspelt word*/\r\r
+  private List suggestions;\r\r
+  /**The misspelt word*/\r\r
+  private String invalidWord;\r\r
+  /**The action to be done when the event returns*/\r\r
+  private short action = INITIAL;\r\r
+  /**Contains the word to be replaced if the action is REPLACE or REPLACEALL*/\r\r
+  private String replaceWord = null;\r\r
+\r\r
+  private String context;\r\r
+  private int startPosition;\r\r
+\r\r
+\r\r
+  /**Consructs the SpellCheckEvent\r\r
+   * @param String invalidWord The word that is misspelt\r\r
+   * @param List suggestions A list of Word objects that are suggested to replace the currently mispelt word\r\r
+   * @param WordTokenizer tokenizer The reference to the tokenizer that caused this\r\r
+   * event to fire.\r\r
+   */\r\r
+  public BasicSpellCheckEvent(String invalidWord, List suggestions, WordTokenizer tokenizer) {\r\r
+    this.invalidWord = invalidWord;\r\r
+    this.suggestions = suggestions;\r\r
+    this.context = tokenizer.getContext();\r\r
+    this.startPosition = tokenizer.getCurrentWordPosition();\r\r
+  }\r\r
+\r\r
+  /** Returns the list of suggested Word objects*/\r\r
+  public List getSuggestions() {\r\r
+    return suggestions;\r\r
+  }\r\r
+\r\r
+  /** Returns the currently misspelt word*/\r\r
+  public String getInvalidWord() {\r\r
+    return invalidWord;\r\r
+  }\r\r
+\r\r
+  public String getWordContext() {\r\r
+    //JMH TBD\r\r
+    return null;\r\r
+  }\r\r
+\r\r
+  /** Returns the start position of the misspelt word in the context*/\r\r
+  public int getWordContextPosition() {\r\r
+    return startPosition;\r\r
+  }\r\r
+\r\r
+  public short getAction() {\r\r
+    return action;\r\r
+  }\r\r
+\r\r
+  public String getReplaceWord() {\r\r
+    return replaceWord;\r\r
+  }\r\r
+\r\r
+  /** Set the action to replace the currently misspelt word with the new word\r\r
+   *  @param String newWord The word to replace the currently misspelt word\r\r
+   *  @param boolean replaceAll If set to true, the SpellChecker will replace all\r\r
+   *  further occurances of the misspelt word without firing a SpellCheckEvent.\r\r
+   */\r\r
+  public void replaceWord(String newWord, boolean replaceAll) {\r\r
+    if (action != INITIAL)\r\r
+      throw new IllegalStateException("The action can can only be set once");\r\r
+    if (replaceAll)\r\r
+      action = REPLACEALL;\r\r
+    else action = REPLACE;\r\r
+    replaceWord = newWord;\r\r
+  }\r\r
+\r\r
+  /** Set the action it ignore the currently misspelt word.\r\r
+   *  @param boolean ignoreAll If set to true, the SpellChecker will replace all\r\r
+   *  further occurances of the misspelt word without firing a SpellCheckEvent.\r\r
+   */\r\r
+  public void ignoreWord(boolean ignoreAll) {\r\r
+    if (action != INITIAL)\r\r
+      throw new IllegalStateException("The action can can only be set once");\r\r
+    if (ignoreAll)\r\r
+      action = IGNOREALL;\r\r
+    else action = IGNORE;\r\r
+  }\r\r
+\r\r
+  /** Set the action to add a new word into the dictionary. This will also replace the\r\r
+   *  currently misspelt word.\r\r
+   */\r\r
+  public void addToDictionary(String newWord) {\r\r
+    if (action != INITIAL)\r\r
+      throw new IllegalStateException("The action can can only be set once");\r\r
+    action = ADDTODICT;\r\r
+    replaceWord = newWord;\r\r
+  }\r\r
+\r\r
+  public void cancel() {\r\r
+    if (action != INITIAL)\r\r
+      throw new IllegalStateException("The action can can only be set once");\r\r
+    action = CANCEL;\r\r
+  }\r\r
+}
\ No newline at end of file