Search in sources :

Example 1 with LanguageChangeEvent

use of com.inet.jortho.LanguageChangeEvent in project freeplane by freeplane.

the class SpellCheckerController method init.

private void init() {
    if (spellCheckerInitialized == true) {
        return;
    }
    spellCheckerInitialized = true;
    final ResourceController resourceController = ResourceController.getResourceController();
    final File orthoDir = new File(resourceController.getResourceBaseDir(), "ortho");
    registerDictionaries(orthoDir);
    final File userOrthoDir = new File(resourceController.getFreeplaneUserDirectory(), "ortho");
    registerDictionaries(userOrthoDir);
    if (!spellCheckerEnabled) {
        return;
    }
    setSpellCheckOptions(resourceController);
    resourceController.addPropertyChangeListener(new IFreeplanePropertyListener() {

        public void propertyChanged(final String propertyName, final String newValue, final String oldValue) {
            if (propertyName.startsWith("spelling_opt")) {
                setSpellCheckOptions(resourceController);
            }
        }
    });
    String spellingLanguage = resourceController.getProperty(SPELLING_LANGUAGE, null);
    if (spellingLanguage == null) {
        spellingLanguage = resourceController.getLanguageCode();
    }
    if (!spellingLanguage.equals("disabled")) {
        SpellChecker.setLanguage(spellingLanguage);
    }
    languageChangeListener = new LanguageChangeListener() {

        public void languageChanged(final LanguageChangeEvent ev) {
            EventQueue.invokeLater(new Runnable() {

                public void run() {
                    final Locale currentLocale = ev.getCurrentLocale();
                    if (currentLocale == null) {
                        resourceController.setProperty(SPELLING_LANGUAGE, "disabled");
                        return;
                    }
                    resourceController.setProperty(SPELLING_LANGUAGE, currentLocale.getLanguage());
                }
            });
        }
    };
    SpellChecker.addLanguageChangeLister(languageChangeListener);
}
Also used : Locale(java.util.Locale) IFreeplanePropertyListener(org.freeplane.core.resources.IFreeplanePropertyListener) LanguageChangeListener(com.inet.jortho.LanguageChangeListener) LanguageChangeEvent(com.inet.jortho.LanguageChangeEvent) ResourceController(org.freeplane.core.resources.ResourceController) File(java.io.File)

Aggregations

LanguageChangeEvent (com.inet.jortho.LanguageChangeEvent)1 LanguageChangeListener (com.inet.jortho.LanguageChangeListener)1 File (java.io.File)1 Locale (java.util.Locale)1 IFreeplanePropertyListener (org.freeplane.core.resources.IFreeplanePropertyListener)1 ResourceController (org.freeplane.core.resources.ResourceController)1