[Schmitzm-commits] r572 - branches/1.0-gt2-2.6/src/skrueger/i8n

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Nov 25 08:03:59 CET 2009


Author: alfonx
Date: 2009-11-25 08:03:58 +0100 (Wed, 25 Nov 2009)
New Revision: 572

Modified:
   branches/1.0-gt2-2.6/src/skrueger/i8n/Translation.java
Log:
Translation is keeping the LocaleChangeListeners in a WeakHashSet now

Modified: branches/1.0-gt2-2.6/src/skrueger/i8n/Translation.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/i8n/Translation.java	2009-11-24 18:16:18 UTC (rev 571)
+++ branches/1.0-gt2-2.6/src/skrueger/i8n/Translation.java	2009-11-25 07:03:58 UTC (rev 572)
@@ -39,6 +39,7 @@
 import java.util.List;
 import java.util.Locale;
 import java.util.Random;
+import java.util.WeakHashMap;
 
 import javax.swing.JComponent;
 
@@ -64,7 +65,8 @@
 	static final Logger LOGGER = Logger.getLogger(Translation.class);
 	static String activeLang = Locale.getDefault().getLanguage();
 
-	static protected List<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>();
+	static protected WeakHashSet<PropertyChangeListener> listeners = new WeakHashSet<PropertyChangeListener>(
+			PropertyChangeListener.class);
 
 	static {
 
@@ -143,7 +145,8 @@
 
 		fireLocaleChangeEvents();
 
-		LOGGER.info("skrueger.i8n.Translation switched ActiveLang to " + newLang);
+		LOGGER.info("skrueger.i8n.Translation switched ActiveLang to "
+				+ newLang);
 	}
 
 	/**
@@ -284,9 +287,13 @@
 
 	/**
 	 * {@link PropertyChangeListener} can be registered to be informed when the
-	 * {@link Locale} changed.
+	 * {@link Locale} changed.<br>
+	 * The listeners are kept in a {@link WeakHashMap}, so you have to keep a
+	 * reference to the listener or it will be removed!
 	 * 
 	 * @param propertyChangeListener
+	 *            A {@link PropertyChangeListener} that will be called when
+	 *            {@link #setActiveLang(String)} changes the language.
 	 */
 	public static void addLocaleChangeListener(
 			PropertyChangeListener propertyChangeListener) {
@@ -313,7 +320,8 @@
 	 */
 	public void addTranslationChangeListener(ActionListener actionListener) {
 		if (actionListeners.add(actionListener)) {
-			LOGGER.debug("registering a new translationChangeActionListener in the WeakHashSet");
+			LOGGER
+					.debug("registering a new translationChangeActionListener in the WeakHashSet");
 		}
 	}
 



More information about the Schmitzm-commits mailing list