29 |
******************************************************************************/ |
******************************************************************************/ |
30 |
package skrueger.i8n; |
package skrueger.i8n; |
31 |
|
|
32 |
|
import java.awt.event.ActionEvent; |
33 |
|
import java.awt.event.ActionListener; |
34 |
import java.beans.PropertyChangeEvent; |
import java.beans.PropertyChangeEvent; |
35 |
import java.beans.PropertyChangeListener; |
import java.beans.PropertyChangeListener; |
36 |
import java.util.ArrayList; |
import java.util.ArrayList; |
37 |
import java.util.HashMap; |
import java.util.HashMap; |
38 |
import java.util.List; |
import java.util.List; |
39 |
import java.util.Locale; |
import java.util.Locale; |
40 |
|
import java.util.Random; |
41 |
|
|
42 |
import javax.swing.JComponent; |
import javax.swing.JComponent; |
43 |
|
|
56 |
public static final String NO_TRANSLATION = "NO TRANSLATION"; |
public static final String NO_TRANSLATION = "NO TRANSLATION"; |
57 |
public static final String DEFAULT_KEY = "default"; |
public static final String DEFAULT_KEY = "default"; |
58 |
static final Logger log = Logger.getLogger(Translation.class); |
static final Logger log = Logger.getLogger(Translation.class); |
59 |
static String activeLang = "fr"; |
static String activeLang = Locale.getDefault().getLanguage(); |
60 |
|
|
61 |
static protected List<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>(); |
static protected List<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>(); |
62 |
|
|
70 |
setActiveLang(locale.getLanguage()); |
setActiveLang(locale.getLanguage()); |
71 |
} |
} |
72 |
|
|
73 |
|
private List<ActionListener> actionListeners = new ArrayList<ActionListener>(); |
74 |
|
|
75 |
@Override |
@Override |
76 |
/* |
/* |
77 |
* @comment To make a copy of a translation see methods toOneLine() and |
* @comment To make a copy of a translation see methods toOneLine() and |
307 |
} |
} |
308 |
} |
} |
309 |
|
|
310 |
|
public void addTranslationChangeListener(ActionListener actionListener) { |
311 |
|
actionListeners.add(actionListener); |
312 |
|
} |
313 |
|
|
314 |
|
public boolean removeTranslationChangeListener(ActionListener actionListener) { |
315 |
|
return actionListeners.remove(actionListener); |
316 |
|
} |
317 |
|
|
318 |
|
public void fireTranslationChangedEvents() { |
319 |
|
ActionEvent ae = new ActionEvent(this, new Random().nextInt(), ""); |
320 |
|
|
321 |
|
for (ActionListener al : actionListeners) { |
322 |
|
al.actionPerformed( ae); |
323 |
|
} |
324 |
|
} |
325 |
|
|
326 |
|
@Override |
327 |
|
public String put(String key, String value) { |
328 |
|
String result = super.put(key, value); |
329 |
|
fireTranslationChangedEvents(); |
330 |
|
return result; |
331 |
|
} |
332 |
|
|
333 |
|
|
334 |
} |
} |