2 |
* Copyright (c) 2009 Martin O. J. Schmitz. |
* Copyright (c) 2009 Martin O. J. Schmitz. |
3 |
* |
* |
4 |
* This file is part of the SCHMITZM library - a collection of utility |
* This file is part of the SCHMITZM library - a collection of utility |
5 |
* classes based on Java 1.6, focussing (not only) on Java Swing |
* classes based on Java 1.6, focusing (not only) on Java Swing |
6 |
* and the Geotools library. |
* and the Geotools library. |
7 |
* |
* |
8 |
* The SCHMITZM project is hosted at: |
* The SCHMITZM project is hosted at: |
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; |
|
import javax.swing.JTable; |
|
43 |
|
|
44 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
45 |
|
import org.opengis.util.InternationalString; |
46 |
|
|
47 |
/** |
/** |
48 |
* Represents a {@link HashMap} of translations. toString() returns the |
* Represents a {@link HashMap} of translations. toString() returns the |
57 |
public static final String NO_TRANSLATION = "NO TRANSLATION"; |
public static final String NO_TRANSLATION = "NO TRANSLATION"; |
58 |
public static final String DEFAULT_KEY = "default"; |
public static final String DEFAULT_KEY = "default"; |
59 |
static final Logger log = Logger.getLogger(Translation.class); |
static final Logger log = Logger.getLogger(Translation.class); |
60 |
static String activeLang = "fr"; |
static String activeLang = Locale.getDefault().getLanguage(); |
61 |
|
|
62 |
static protected List<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>(); |
static protected List<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>(); |
63 |
|
|
71 |
setActiveLang(locale.getLanguage()); |
setActiveLang(locale.getLanguage()); |
72 |
} |
} |
73 |
|
|
74 |
|
private List<ActionListener> actionListeners = new ArrayList<ActionListener>(); |
75 |
|
|
76 |
@Override |
@Override |
77 |
/* |
/* |
78 |
* @comment To make a copy of a translation see methods toOneLine() and |
* @comment To make a copy of a translation see methods toOneLine() and |
193 |
*/ |
*/ |
194 |
public void fromOneLine(final String oneLineCoded) { |
public void fromOneLine(final String oneLineCoded) { |
195 |
clear(); |
clear(); |
196 |
|
|
197 |
if ((oneLineCoded == null) || (oneLineCoded.equals(""))) { |
if ((oneLineCoded == null) || (oneLineCoded.equals(""))) { |
198 |
put(DEFAULT_KEY, ""); |
put(DEFAULT_KEY, ""); |
199 |
return; |
return; |
309 |
} |
} |
310 |
} |
} |
311 |
|
|
312 |
|
public void addTranslationChangeListener(ActionListener actionListener) { |
313 |
|
actionListeners.add(actionListener); |
314 |
|
} |
315 |
|
|
316 |
|
public boolean removeTranslationChangeListener(ActionListener actionListener) { |
317 |
|
return actionListeners.remove(actionListener); |
318 |
|
} |
319 |
|
|
320 |
|
public void fireTranslationChangedEvents(String lang) { |
321 |
|
ActionEvent ae = new ActionEvent(this, new Random().nextInt(), lang); |
322 |
|
|
323 |
|
for (ActionListener al : actionListeners) { |
324 |
|
al.actionPerformed( ae); |
325 |
|
} |
326 |
|
} |
327 |
|
|
328 |
|
@Override |
329 |
|
public String put(String lang, String value) { |
330 |
|
String result = super.put(lang, value); |
331 |
|
fireTranslationChangedEvents(lang); |
332 |
|
return result; |
333 |
|
} |
334 |
|
|
335 |
|
public void fromOneLine(InternationalString iString) { |
336 |
|
if (iString != null) |
337 |
|
fromOneLine(iString.toString()); |
338 |
|
else |
339 |
|
fromOneLine((String)null); |
340 |
|
} |
341 |
|
|
342 |
|
|
343 |
} |
} |