39 |
import java.util.List; |
import java.util.List; |
40 |
import java.util.Locale; |
import java.util.Locale; |
41 |
import java.util.Random; |
import java.util.Random; |
42 |
|
import java.util.WeakHashMap; |
43 |
|
|
44 |
import javax.swing.JComponent; |
import javax.swing.JComponent; |
45 |
|
|
65 |
static final Logger LOGGER = Logger.getLogger(Translation.class); |
static final Logger LOGGER = Logger.getLogger(Translation.class); |
66 |
static String activeLang = Locale.getDefault().getLanguage(); |
static String activeLang = Locale.getDefault().getLanguage(); |
67 |
|
|
68 |
static protected List<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>(); |
static protected WeakHashSet<PropertyChangeListener> listeners = new WeakHashSet<PropertyChangeListener>( |
69 |
|
PropertyChangeListener.class); |
70 |
|
|
71 |
static { |
static { |
72 |
|
|
145 |
|
|
146 |
fireLocaleChangeEvents(); |
fireLocaleChangeEvents(); |
147 |
|
|
148 |
LOGGER.info("skrueger.i8n.Translation switched ActiveLang to " + newLang); |
LOGGER.info("skrueger.i8n.Translation switched ActiveLang to " |
149 |
|
+ newLang); |
150 |
} |
} |
151 |
|
|
152 |
/** |
/** |
287 |
|
|
288 |
/** |
/** |
289 |
* {@link PropertyChangeListener} can be registered to be informed when the |
* {@link PropertyChangeListener} can be registered to be informed when the |
290 |
* {@link Locale} changed. |
* {@link Locale} changed.<br> |
291 |
|
* The listeners are kept in a {@link WeakHashMap}, so you have to keep a |
292 |
|
* reference to the listener or it will be removed! |
293 |
* |
* |
294 |
* @param propertyChangeListener |
* @param propertyChangeListener |
295 |
|
* A {@link PropertyChangeListener} that will be called when |
296 |
|
* {@link #setActiveLang(String)} changes the language. |
297 |
*/ |
*/ |
298 |
public static void addLocaleChangeListener( |
public static void addLocaleChangeListener( |
299 |
PropertyChangeListener propertyChangeListener) { |
PropertyChangeListener propertyChangeListener) { |
301 |
} |
} |
302 |
|
|
303 |
/** |
/** |
304 |
|
* {@link PropertyChangeListener} can be registered to be informed when the |
305 |
|
* {@link Locale} changed.<br> |
306 |
|
* The listeners are kept in a {@link WeakHashMap}, so you have to keep a |
307 |
|
* reference to the listener or it will be removed! |
308 |
|
* |
309 |
|
* @param propertyChangeListener |
310 |
|
* A {@link PropertyChangeListener} that will be called when |
311 |
|
* {@link #setActiveLang(String)} changes the language. |
312 |
|
*/ |
313 |
|
public static boolean removeLocaleChangeListener( |
314 |
|
PropertyChangeListener propertyChangeListener) { |
315 |
|
return listeners.remove(propertyChangeListener); |
316 |
|
} |
317 |
|
|
318 |
|
/** |
319 |
* Informs all registered {@link PropertyChangeListener}s about a change of |
* Informs all registered {@link PropertyChangeListener}s about a change of |
320 |
* the the {@link Locale}. |
* the the {@link Locale}. |
321 |
*/ |
*/ |
335 |
*/ |
*/ |
336 |
public void addTranslationChangeListener(ActionListener actionListener) { |
public void addTranslationChangeListener(ActionListener actionListener) { |
337 |
if (actionListeners.add(actionListener)) { |
if (actionListeners.add(actionListener)) { |
338 |
LOGGER.debug("registering a new translationChangeActionListener in the WeakHashSet"); |
LOGGER |
339 |
|
.debug("registering a new translationChangeActionListener in the WeakHashSet"); |
340 |
} |
} |
341 |
} |
} |
342 |
|
|