danger.util
Class SpellCheck

java.lang.Object
  extended by danger.util.SpellCheck


public class SpellCheck
extends Object

This static class provides methods to access and modify the global spell check setting, as well as methods to check spelling and correct mistakes.

Spell checking is done independently of any AutoText replacements. For AutoText, see ShortcutRules.

To access the user's spell check dictionary, see SpellCheckUserDictionary.

Since:
4.5

Method Summary
static String correctMistake(String text, SpellCheckUserDictionary extraDictionary)
          Finds a word to automatically replace the given misspelling.
static String correctMistake(String text, String[] replacements)
          Given a list of possible replacements, finds a word to automatically replace the given misspelling.
static String[] findReplacements(String text, SpellCheckUserDictionary extraDictionary)
          Returns an array of up to 10 possible spelling corrections.
static SpellCheckUserDictionary getUserDictionary()
          Get the user's spell check dictionary.
static boolean isAutoCorrectionEnabled()
          Determine whether the auto-correction is enabled, via setAutoCorrectionEnabled(boolean).
static boolean isHighlightEnabled()
          Determine whether the global highlight setting is turned on.
static boolean isSlangDictionaryEnabled()
          Determine whether the slang dictionary is used while spell checking.
static boolean isSpellCheckEnabled()
          Determine if highlighting or auto-correction is enabled.
static void setAutoCorrectionEnabled(boolean flag)
          Set the global auto-correction setting.
static void setHighlightEnabled(boolean flag)
          Set the global highlight setting.
static void setSlangDictionaryEnabled(boolean flag)
          Specify whether the slang dictionary should be used.
static boolean spelledCorrectly(String text, SpellCheckUserDictionary extraDictionary)
          Determine if a word is spelled correctly.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getUserDictionary

public static SpellCheckUserDictionary getUserDictionary()
Get the user's spell check dictionary.


isSpellCheckEnabled

public static boolean isSpellCheckEnabled()
Determine if highlighting or auto-correction is enabled. Returns true if isHighlightEnabled() or isAutoCorrectionEnabled() is true.


isHighlightEnabled

public static boolean isHighlightEnabled()
Determine whether the global highlight setting is turned on. If true, misspelled words are automatically underlined.


setHighlightEnabled

public static void setHighlightEnabled(boolean flag)
Set the global highlight setting. If true, misspelled words are automatically underlined.

Parameters:
flag - if true, highlighting is turned on.

setAutoCorrectionEnabled

public static void setAutoCorrectionEnabled(boolean flag)
Set the global auto-correction setting. If true, the system will try to automatically correct misspelled words. Auto-correction only occurs if spell check is enabled (see setHighlightEnabled(boolean)).

Parameters:
flag - if true, auto-correct is turned on.

isAutoCorrectionEnabled

public static boolean isAutoCorrectionEnabled()

Determine whether the auto-correction is enabled, via setAutoCorrectionEnabled(boolean).


isSlangDictionaryEnabled

public static boolean isSlangDictionaryEnabled()

Determine whether the slang dictionary is used while spell checking.

Note that the slang dictionary is currently only supported in English and Spanish.


setSlangDictionaryEnabled

public static void setSlangDictionaryEnabled(boolean flag)

Specify whether the slang dictionary should be used.

Note that the slang dictionary is currently only supported in English and Spanish.

Parameters:
flag - if true, the "slang dictionary" is used.

spelledCorrectly

public static boolean spelledCorrectly(String text,
                                       SpellCheckUserDictionary extraDictionary)

Determine if a word is spelled correctly. Returns true if the word is spelled correctly.

Any text with a number in it is considered correct unless it is an incorrect use of an ordinal (for example, "32st").

Text that is considered a URL is considered correct.

All 1-letter words are considered correct.

Parameters:
text - the text to check.
extraDictionary - a dictionary to use in addition to the built-in, slang, and main user dictionaries. Use null if no additional dictionary should be used.

correctMistake

public static String correctMistake(String text,
                                    SpellCheckUserDictionary extraDictionary)
Finds a word to automatically replace the given misspelling. Returns null if no good single correction was found.

Parameters:
text - the word to correct.

correctMistake

public static String correctMistake(String text,
                                    String[] replacements)
Given a list of possible replacements, finds a word to automatically replace the given misspelling. Returns null if no good single correction was found. You would normally use correctMistake(String,SpellCheckUserDictionary) instead, but might want to use this if you've already called findReplacements(java.lang.String, danger.util.SpellCheckUserDictionary) for another reason. correctMistake(String,SpellCheckUserDictionary) simply calls findReplacements(java.lang.String, danger.util.SpellCheckUserDictionary) and this method.

Parameters:
text - the word to correct.

findReplacements

public static String[] findReplacements(String text,
                                        SpellCheckUserDictionary extraDictionary)
Returns an array of up to 10 possible spelling corrections. Returns an empty array if no corrections could be found. The array is sorted, with the first element being the most likely candidate.

Parameters:
text - the word to find replacements for.
extraDictionary - a dictionary to use in addition to the built-in, slang, and main user dictionaries. Use null if no additional dictionary should be used.