public class SpellChecker
extends java.lang.Object
SpellChecker.registerDictionaries( new URL("file", null, ""), "en,de", "de" );
and in an applet this will look like:
SpellChecker.registerDictionaries( getCodeBase(), "en,de", "en" );
After this you can register your text component that should have the spell checker features
(Highlighter, context menu, spell checking dialog).
This looks like:
JTextPane text = new JTextPane();
SpellChecker.register( text );
Modifier and Type | Method and Description |
---|---|
static void |
addLanguageChangeLister(LanguageChangeListener listener)
Adds a LanguageChangeListener.
|
static javax.swing.JMenu |
createCheckerMenu()
Creates a menu item "Orthography" (or the equivalent depending on the user language) with a
sub-menu that includes suggestions for a correct spelling.
|
static javax.swing.JMenu |
createCheckerMenu(SpellCheckerOptions options)
Creates a menu item "Orthography" (or the equivalent depending on the user language) with a
sub-menu that includes suggestions for a correct spelling.
|
static javax.swing.JPopupMenu |
createCheckerPopup()
Create a dynamic JPopupMenu with a list of suggestion.
|
static javax.swing.JPopupMenu |
createCheckerPopup(SpellCheckerOptions options)
Create a dynamic JPopupMenu with a list of suggestion.
|
static javax.swing.JMenu |
createLanguagesMenu()
Creates a menu item "Languages" (or the equivalent depending on the user language) with a sub-menu
that lists all available dictionary languages.
|
static javax.swing.JMenu |
createLanguagesMenu(SpellCheckerOptions options)
Creates a menu item "Languages" (or the equivalent depending on the user language) with a sub-menu
that lists all available dictionary languages.
|
static void |
enableAutoSpell(javax.swing.text.JTextComponent text,
boolean enable)
Enable or disable the auto spell checking feature (red zigzag line) for a text component.
|
static void |
enableAutoSpell(javax.swing.text.JTextComponent text,
boolean enable,
SpellCheckerOptions options)
Enable or disable the auto spell checking feature (red zigzag line) for a text component.
|
static void |
enablePopup(javax.swing.text.JTextComponent text,
boolean enable,
boolean submenu)
Enable or disable the popup menu with the menu item "Orthography" and "Languages" or only suggestion.
|
static void |
enableShortKey(javax.swing.text.JTextComponent text,
boolean enable)
Enable or disable the F7 key.
|
static void |
enableShortKey(javax.swing.text.JTextComponent text,
boolean enable,
SpellCheckerOptions options)
Enable or disable the F7 key.
|
static java.lang.String |
getApplicationName()
Get the title of your application.
|
static java.util.Locale |
getCurrentLocale()
Gets the current
Locale . |
static CustomDictionaryProvider |
getCustomDictionaryProvider()
Gets the currently set CustomDictionaryProvider.
|
static CustomUIProvider |
getCustomUIProvider()
Gets the currently set CustomUIProvider.
|
static MessageHandler |
getMessageHandler()
Gets the currently set message handler.
|
static SpellCheckerOptions |
getOptions()
Get the default SpellCheckerOptions.
|
static UserDictionaryProvider |
getUserDictionaryProvider()
Gets the currently set UserDictionaryProvider.
|
static boolean |
isDictionaryLoaded()
If currently a Dictionary is loaded.
|
static void |
register(javax.swing.text.JTextComponent text)
Activate the spell checker for the given
JTextComponent . |
static void |
register(javax.swing.text.JTextComponent text,
boolean hasPopup,
boolean submenu,
boolean hasShortKey,
boolean hasAutoSpell)
Activates the spell checker for the given
JTextComponent . |
static void |
registerDictionaries(java.net.URL baseURL,
java.lang.String activeLocale)
Registers the available dictionaries.
|
static void |
registerDictionaries(java.net.URL baseURL,
java.lang.String availableLocales,
java.lang.String activeLocale)
Registers the available dictionaries.
|
static void |
registerDictionaries(java.net.URL baseURL,
java.lang.String availableLocales,
java.lang.String activeLocale,
java.lang.String extension)
Registers the available dictionaries.
|
static void |
removeLanguageChangeLister(LanguageChangeListener listener)
Removes the LanguageChangeListener.
|
static void |
setApplicationName(java.lang.String name)
Set the title of your application.
|
static void |
setCurrentLocale(java.util.Locale locale)
Set the current
Locale . |
static void |
setCustomDictionaryProvider(CustomDictionaryProvider customDictionaryProvider)
Set a CustomDictionaryProvider.
|
static void |
setCustomUIProvider(CustomUIProvider customUIProvider)
Set a CustomUIProvider.
|
static void |
setMessageHandler(MessageHandler messageHandler)
Set the message handler used for handling errors and information messages.
|
static void |
setUserDictionaryProvider(UserDictionaryProvider userDictionaryProvider)
Sets the UserDictionaryProvider.
|
static void |
showSpellCheckerDialog(javax.swing.text.JTextComponent text,
SpellCheckerOptions options)
Show the Spell Checker dialog for the given JTextComponent.
|
static void |
unregister(javax.swing.text.JTextComponent text)
Removes all spell checker features from the JTextComponent.
|
public static void setUserDictionaryProvider(UserDictionaryProvider userDictionaryProvider)
registerDictionaries(URL, String, String)
.userDictionaryProvider
- the new UserDictionaryProvider or nullsetCustomDictionaryProvider(CustomDictionaryProvider)
,
getUserDictionaryProvider()
,
registerDictionaries(URL, String, String)
public static UserDictionaryProvider getUserDictionaryProvider()
public static void setCustomDictionaryProvider(CustomDictionaryProvider customDictionaryProvider)
customDictionaryProvider
- the new CustomDictionaryProvider or nullsetUserDictionaryProvider(UserDictionaryProvider)
,
registerDictionaries(URL, String, String)
public static CustomDictionaryProvider getCustomDictionaryProvider()
public static void setMessageHandler(MessageHandler messageHandler)
messageHandler
- the new MessageHandler or null (DefaultMessageHandler will be used)public static MessageHandler getMessageHandler()
setMessageHandler(MessageHandler)
public static void setCustomUIProvider(CustomUIProvider customUIProvider)
customUIProvider
- the new CustomUIProvider or nullpublic static CustomUIProvider getCustomUIProvider()
public static void registerDictionaries(java.net.URL baseURL, java.lang.String activeLocale)
// Load the configuration and dictionaries from the current working directory and use the current locale or the first language as default
SpellChecker.registerDictionaries( null, null );
// Load the configuration and dictionaries from the sub directory "dict"
SpellChecker.registerDictionaries( new URL( "file", null, "dict" ), null );
// Load the configuration and dictionaries from a web server and activate English as language
SpellChecker.registerDictionaries( new URL( "http://MyWebServer/dictionries/" ), "en" );
// Load the configuration and dictionaries from the same web location like the applet and use the German dictionary as default
SpellChecker.registerDictionaries( myApplet.getCodeBase(), "de" );
// Sample content from a file dictionaries.cnf
extension=.ortho
languages=de,en,it,fr,es,ru
baseURL
- the base URL where the dictionaries and configuration file can be found. If null then first in the classloader root is searched.
After it the URL("file", null, "") is used which is equals to the current working directory.activeLocale
- the locale that should be loaded and made active. If null or empty then the default locale is used.setUserDictionaryProvider(UserDictionaryProvider)
,
registerDictionaries(URL, String, String)
,
registerDictionaries(URL, String, String, String)
public static void registerDictionaries(java.net.URL baseURL, java.lang.String availableLocales, java.lang.String activeLocale)
Samples:
// Load the dictionaries from the current working directory and use the current locale or the first language as default
SpellChecker.registerDictionaries( null, "de,en", null );
// Load the dictionaries from the sub directory "dict"
SpellChecker.registerDictionaries( new URL( "file", null, "dict" ), "de,en", null );
// Load the dictionaries from a web server and activate English as language
SpellChecker.registerDictionaries( new URL( "http://MyWebServer/dictionries/" ), "de,en", "en" );
// Load the dictionaries from the same web location like the applet and use the German dictionary as default
SpellChecker.registerDictionaries( myApplet.getCodeBase(), "de,en", "de" );
baseURL
- the base URL where the dictionaries can be found. If null then URL("file", null, "") is used.availableLocales
- a comma separated list of localesactiveLocale
- the locale that should be loaded and made active. If null or empty then the default locale is used.setUserDictionaryProvider(UserDictionaryProvider)
,
registerDictionaries(URL, String)
,
registerDictionaries(URL, String, String, String)
public static void registerDictionaries(java.net.URL baseURL, java.lang.String availableLocales, java.lang.String activeLocale, java.lang.String extension)
Samples:
// Load the dictionaries from the current working directory
// and use the current locale or the first language as default.
// The dictionaries must be named dictionary_de.ortho and dictionary_en.ortho
SpellChecker.registerDictionaries( null, "de,en", null, ".ortho" );
// Load the dictionaries from the sub directory "dict"
// and use the current locale or the first language as default.
// The dictionaries must be named dict/dictionary_de.ortho and dict/dictionary_en.ortho
SpellChecker.registerDictionaries( new URL( "file", null, "dict" ), "de,en", null, ".ortho" );
// Load the dictionaries from a web server and activate English as language
// The dictionaries must be named http://MyWebServer/dictionries/dictionary_de.bin and http://MyWebServer/dictionries/dictionary_en.bin
SpellChecker.registerDictionaries( new URL( "http://MyWebServer/dictionries/" ), "de,en", "en", ".bin" );
// Load the configuration from the same web location like the applet and use the German dictionary as default
// The dictionaries must be named dictionary_de.bin and dictionary_en.bin in the codebase
SpellChecker.registerDictionaries( myApplet.getCodeBase(), "de,en", "de", ".bin" );
baseURL
- the base URL where the dictionaries can be found. If null then URL("file", null, "") is used.availableLocales
- a comma separated list of localesactiveLocale
- the locale that should be loaded and made active. If null or empty then the default locale is used.extension
- the file extension of the dictionaries. Some web server like the IIS6 does not support the default ".ortho".setUserDictionaryProvider(UserDictionaryProvider)
,
registerDictionaries(URL, String)
,
registerDictionaries(URL, String, String)
public static void register(javax.swing.text.JTextComponent text) throws java.lang.NullPointerException
JTextComponent
. The call is equal to register( text,
true, true ).text
- the JTextComponentjava.lang.NullPointerException
- if text is nullpublic static void register(javax.swing.text.JTextComponent text, boolean hasPopup, boolean submenu, boolean hasShortKey, boolean hasAutoSpell) throws java.lang.NullPointerException
JTextComponent
. You do not need to unregister if the
JTextComponent is not needed anymore.text
- the JTextComponenthasPopup
- if true, the JTextComponent is to have a popup menu with the menu item "Orthography" and "Languages".submenu
- if true, the popup has a sub menuhasShortKey
- if true, pressing the F7 key will display the spell check dialog.hasAutoSpell
- if true, the JTextComponent has a auto spell checking.java.lang.NullPointerException
- if text is nullpublic static void unregister(javax.swing.text.JTextComponent text)
text
- the JTextComponentpublic static void enableShortKey(javax.swing.text.JTextComponent text, boolean enable)
text
- the JTextComponent that should changeenable
- true, enable the feature.public static void enableShortKey(javax.swing.text.JTextComponent text, boolean enable, SpellCheckerOptions options)
text
- the JTextComponent that should changeenable
- true, enable the feature.options
- override the default options for this menu.public static void showSpellCheckerDialog(javax.swing.text.JTextComponent text, SpellCheckerOptions options)
Action action = text.getActionMap().get("spell-checking");
The action is only available if you have enable the short key (F7).text
- JTextComponent to checkoptions
- override the default options for this menu.public static void enablePopup(javax.swing.text.JTextComponent text, boolean enable, boolean submenu)
text
- the JTextComponent that should changesubmenu
- true, menu item "Orthography" and "Languages"; false, only suggestionsenable
- true, enable the feature.public static void enableAutoSpell(javax.swing.text.JTextComponent text, boolean enable)
text
- the JTextComponent that should changeenable
- true, enable the feature.public static void enableAutoSpell(javax.swing.text.JTextComponent text, boolean enable, SpellCheckerOptions options)
text
- the JTextComponent that should changeenable
- true, enable the feature.options
- override the default options for this menu.public static void addLanguageChangeLister(LanguageChangeListener listener)
listener
- listener to addLanguageChangeListener
public static void removeLanguageChangeLister(LanguageChangeListener listener)
listener
- listener to removepublic static javax.swing.JMenu createCheckerMenu()
public static javax.swing.JMenu createCheckerMenu(SpellCheckerOptions options)
options
- override the default options for this menu.public static javax.swing.JPopupMenu createCheckerPopup()
JPopupMenu popup = SpellChecker.createCheckerPopup();
text.addMouseListener( new PopupListener(popup) );
createCheckerMenu()
public static javax.swing.JPopupMenu createCheckerPopup(SpellCheckerOptions options)
JPopupMenu popup = SpellChecker.createCheckerPopup( null );
text.addMouseListener( new PopupListener(popup) );
createCheckerMenu(SpellCheckerOptions)
public static javax.swing.JMenu createLanguagesMenu()
JPopupMenu popup = new JPopupMenu();
popup.add( SpellChecker.createLanguagesMenu() );
public static javax.swing.JMenu createLanguagesMenu(SpellCheckerOptions options)
JPopupMenu popup = new JPopupMenu();
popup.add( SpellChecker.createLanguagesMenu() );
options
- override the default options for this menu.public static java.util.Locale getCurrentLocale()
Locale
. The current Locale will be set if the user selects
one, or when calling Locale
or null if none is set.registerDictionaries(URL, String, String)
,
isDictionaryLoaded()
public static void setCurrentLocale(java.util.Locale locale) throws java.lang.IllegalArgumentException
Locale
. The call is asynchronous.locale
- the new locale, must be registered.java.lang.IllegalArgumentException
- if the locale was not registered as available.registerDictionaries(URL, String, String)
,
isDictionaryLoaded()
,
getCurrentLocale()
public static boolean isDictionaryLoaded()
public static void setApplicationName(java.lang.String name)
public static java.lang.String getApplicationName()
public static SpellCheckerOptions getOptions()
Copyright © 2005 - 2013 i-net software. All Rights Reserved.