X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/spelling/SpellCheckEngine.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/spelling/SpellCheckEngine.java index 568f1d7..2f8a304 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/spelling/SpellCheckEngine.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/spelling/SpellCheckEngine.java @@ -35,23 +35,22 @@ import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; - - /** * Spell check engine for Java source spell checking. * * @since 3.0 */ -public class SpellCheckEngine implements ISpellCheckEngine, IPropertyChangeListener { +public class SpellCheckEngine implements ISpellCheckEngine, + IPropertyChangeListener { /** The dictionary location */ - public static final String DICTIONARY_LOCATION= "dictionaries/"; //$NON-NLS-1$ + public static final String DICTIONARY_LOCATION = "dictionaries/"; //$NON-NLS-1$ /** The singleton spell checker instance */ - private static ISpellChecker fChecker= null; + private static ISpellChecker fChecker = null; /** The singleton engine instance */ - private static ISpellCheckEngine fEngine= null; + private static ISpellCheckEngine fEngine = null; /** * Returns the available locales for this spell check engine. @@ -60,23 +59,26 @@ public class SpellCheckEngine implements ISpellCheckEngine, IPropertyChangeListe */ public static Set getAvailableLocales() { - URL url= null; - Locale locale= null; - InputStream stream= null; + URL url = null; + Locale locale = null; + InputStream stream = null; - final Set result= new HashSet(); + final Set result = new HashSet(); try { - final URL location= getDictionaryLocation(); - final Locale[] locales= Locale.getAvailableLocales(); + final URL location = getDictionaryLocation(); + final Locale[] locales = Locale.getAvailableLocales(); - for (int index= 0; index < locales.length; index++) { + for (int index = 0; index < locales.length; index++) { - locale= locales[index]; - url= new URL(location, locale.toString().toLowerCase() + "." + PHPUIMessages.getString("Spelling.dictionary.file.extension")); //$NON-NLS-1$ //$NON-NLS-2$ + locale = locales[index]; + url = new URL( + location, + locale.toString().toLowerCase() + + "." + PHPUIMessages.getString("Spelling.dictionary.file.extension")); //$NON-NLS-1$ //$NON-NLS-2$ try { - stream= url.openStream(); + stream = url.openStream(); if (stream != null) { try { result.add(locale); @@ -109,13 +111,13 @@ public class SpellCheckEngine implements ISpellCheckEngine, IPropertyChangeListe * Returns the dictionary location. * * @throws MalformedURLException - * if the URL could not be created + * if the URL could not be created * @return The dictionary location, or null iff the location - * is not known + * is not known */ public static URL getDictionaryLocation() throws MalformedURLException { - final PHPeclipsePlugin plugin= PHPeclipsePlugin.getDefault(); + final PHPeclipsePlugin plugin = PHPeclipsePlugin.getDefault(); if (plugin != null) return plugin.getBundle().getEntry("/" + DICTIONARY_LOCATION); //$NON-NLS-1$ @@ -130,25 +132,25 @@ public class SpellCheckEngine implements ISpellCheckEngine, IPropertyChangeListe public static final synchronized ISpellCheckEngine getInstance() { if (fEngine == null) - fEngine= new SpellCheckEngine(); + fEngine = new SpellCheckEngine(); return fEngine; } /** The registered locale insenitive dictionaries */ - private final Set fGlobalDictionaries= new HashSet(); + private final Set fGlobalDictionaries = new HashSet(); /** The current locale */ - private Locale fLocale= null; + private Locale fLocale = null; /** The registered locale sensitive dictionaries */ - private final Map fLocaleDictionaries= new HashMap(); + private final Map fLocaleDictionaries = new HashMap(); /** The preference store where to listen */ - private IPreferenceStore fPreferences= null; + private IPreferenceStore fPreferences = null; /** The user dictionary */ - private ISpellDictionary fUserDictionary= null; + private ISpellDictionary fUserDictionary = null; /** * Creates a new spell check manager. @@ -161,13 +163,15 @@ public class SpellCheckEngine implements ISpellCheckEngine, IPropertyChangeListe try { - Locale locale= null; - final URL location= getDictionaryLocation(); + Locale locale = null; + final URL location = getDictionaryLocation(); - for (final Iterator iterator= getAvailableLocales().iterator(); iterator.hasNext();) { + for (final Iterator iterator = getAvailableLocales().iterator(); iterator + .hasNext();) { - locale= (Locale)iterator.next(); - fLocaleDictionaries.put(locale, new SpellReconcileDictionary(locale, location)); + locale = (Locale) iterator.next(); + fLocaleDictionaries.put(locale, new SpellReconcileDictionary( + locale, location)); } } catch (MalformedURLException exception) { @@ -178,39 +182,41 @@ public class SpellCheckEngine implements ISpellCheckEngine, IPropertyChangeListe /* * @see net.sourceforge.phpdt.ui.text.spelling.engine.ISpellCheckEngine#createSpellChecker(java.util.Locale,org.eclipse.jface.preference.IPreferenceStore) */ - public final synchronized ISpellChecker createSpellChecker(final Locale locale, final IPreferenceStore store) { + public final synchronized ISpellChecker createSpellChecker( + final Locale locale, final IPreferenceStore store) { if (fLocale != null && fLocale.equals(locale)) return fChecker; if (fChecker == null) { - fChecker= new DefaultSpellChecker(store); + fChecker = new DefaultSpellChecker(store); store.addPropertyChangeListener(this); - fPreferences= store; + fPreferences = store; - ISpellDictionary dictionary= null; - for (Iterator iterator= fGlobalDictionaries.iterator(); iterator.hasNext();) { + ISpellDictionary dictionary = null; + for (Iterator iterator = fGlobalDictionaries.iterator(); iterator + .hasNext();) { - dictionary= (ISpellDictionary)iterator.next(); + dictionary = (ISpellDictionary) iterator.next(); fChecker.addDictionary(dictionary); } } - ISpellDictionary dictionary= null; + ISpellDictionary dictionary = null; if (fLocale != null) { - dictionary= (ISpellDictionary)fLocaleDictionaries.get(fLocale); + dictionary = (ISpellDictionary) fLocaleDictionaries.get(fLocale); if (dictionary != null) { fChecker.removeDictionary(dictionary); dictionary.unload(); } } - fLocale= locale; + fLocale = locale; - dictionary= (ISpellDictionary)fLocaleDictionaries.get(locale); + dictionary = (ISpellDictionary) fLocaleDictionaries.get(locale); if (dictionary == null) { if (!getDefaultLocale().equals(locale)) { @@ -218,15 +224,20 @@ public class SpellCheckEngine implements ISpellCheckEngine, IPropertyChangeListe if (fPreferences != null) fPreferences.removePropertyChangeListener(this); - fChecker= null; - fLocale= null; + fChecker = null; + fLocale = null; } } else fChecker.addDictionary(dictionary); if (fPreferences != null) - propertyChange(new PropertyChangeEvent(this, ISpellCheckPreferenceKeys.SPELLING_USER_DICTIONARY, null, fPreferences.getString(ISpellCheckPreferenceKeys.SPELLING_USER_DICTIONARY))); + propertyChange(new PropertyChangeEvent( + this, + ISpellCheckPreferenceKeys.SPELLING_USER_DICTIONARY, + null, + fPreferences + .getString(ISpellCheckPreferenceKeys.SPELLING_USER_DICTIONARY))); return fChecker; } @@ -243,24 +254,26 @@ public class SpellCheckEngine implements ISpellCheckEngine, IPropertyChangeListe */ public final void propertyChange(final PropertyChangeEvent event) { - if (fChecker != null && event.getProperty().equals(ISpellCheckPreferenceKeys.SPELLING_USER_DICTIONARY)) { + if (fChecker != null + && event.getProperty().equals( + ISpellCheckPreferenceKeys.SPELLING_USER_DICTIONARY)) { if (fUserDictionary != null) { fChecker.removeDictionary(fUserDictionary); - fUserDictionary= null; + fUserDictionary = null; } - final String file= (String)event.getNewValue(); + final String file = (String) event.getNewValue(); if (file.length() > 0) { try { - final URL url= new URL("file", null, file); //$NON-NLS-1$ - InputStream stream= url.openStream(); + final URL url = new URL("file", null, file); //$NON-NLS-1$ + InputStream stream = url.openStream(); if (stream != null) { try { - fUserDictionary= new PersistentSpellDictionary(url); + fUserDictionary = new PersistentSpellDictionary(url); fChecker.addDictionary(fUserDictionary); } finally { stream.close(); @@ -278,7 +291,8 @@ public class SpellCheckEngine implements ISpellCheckEngine, IPropertyChangeListe /* * @see net.sourceforge.phpdt.ui.text.spelling.engine.ISpellCheckEngine#registerDictionary(net.sourceforge.phpdt.ui.text.spelling.engine.ISpellDictionary) */ - public synchronized final void registerDictionary(final ISpellDictionary dictionary) { + public synchronized final void registerDictionary( + final ISpellDictionary dictionary) { fGlobalDictionaries.add(dictionary); @@ -289,7 +303,8 @@ public class SpellCheckEngine implements ISpellCheckEngine, IPropertyChangeListe /* * @see net.sourceforge.phpdt.ui.text.spelling.engine.ISpellCheckEngine#registerDictionary(java.util.Locale,net.sourceforge.phpdt.ui.text.spelling.engine.ISpellDictionary) */ - public synchronized final void registerDictionary(final Locale locale, final ISpellDictionary dictionary) { + public synchronized final void registerDictionary(final Locale locale, + final ISpellDictionary dictionary) { fLocaleDictionaries.put(locale, dictionary); @@ -302,30 +317,33 @@ public class SpellCheckEngine implements ISpellCheckEngine, IPropertyChangeListe */ public synchronized final void unload() { - ISpellDictionary dictionary= null; - for (final Iterator iterator= fGlobalDictionaries.iterator(); iterator.hasNext();) { + ISpellDictionary dictionary = null; + for (final Iterator iterator = fGlobalDictionaries.iterator(); iterator + .hasNext();) { - dictionary= (ISpellDictionary)iterator.next(); + dictionary = (ISpellDictionary) iterator.next(); dictionary.unload(); } - for (final Iterator iterator= fLocaleDictionaries.values().iterator(); iterator.hasNext();) { + for (final Iterator iterator = fLocaleDictionaries.values().iterator(); iterator + .hasNext();) { - dictionary= (ISpellDictionary)iterator.next(); + dictionary = (ISpellDictionary) iterator.next(); dictionary.unload(); } if (fPreferences != null) fPreferences.removePropertyChangeListener(this); - fUserDictionary= null; - fChecker= null; + fUserDictionary = null; + fChecker = null; } /* * @see net.sourceforge.phpdt.ui.text.spelling.engine.ISpellCheckEngine#unregisterDictionary(net.sourceforge.phpdt.ui.text.spelling.engine.ISpellDictionary) */ - public synchronized final void unregisterDictionary(final ISpellDictionary dictionary) { + public synchronized final void unregisterDictionary( + final ISpellDictionary dictionary) { fGlobalDictionaries.remove(dictionary); fLocaleDictionaries.values().remove(dictionary);