1 |
package skrueger.i8n; |
package skrueger.i8n; |
2 |
|
import java.beans.PropertyChangeEvent; |
3 |
|
import java.beans.PropertyChangeListener; |
4 |
|
import java.util.ArrayList; |
5 |
import java.util.HashMap; |
import java.util.HashMap; |
6 |
import java.util.List; |
import java.util.List; |
7 |
import java.util.Locale; |
import java.util.Locale; |
8 |
|
|
|
import javax.swing.JColorChooser; |
|
9 |
import javax.swing.JComponent; |
import javax.swing.JComponent; |
|
import javax.swing.JFileChooser; |
|
|
import javax.swing.JOptionPane; |
|
10 |
|
|
11 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
12 |
|
|
17 |
* @author @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
* @author @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
18 |
*/ |
*/ |
19 |
|
|
20 |
public class Translation extends HashMap<String, String> { |
public class Translation extends HashMap<String, String>{ |
21 |
|
public static final String LOCALECHANGE_PROPERTY = "localechange"; |
22 |
public static final String NO_TRANSLATION = "NO TRANSLATION"; |
public static final String NO_TRANSLATION = "NO TRANSLATION"; |
23 |
public static final String DEFAULT_KEY = "default"; |
public static final String DEFAULT_KEY = "default"; |
24 |
static final Logger log = Logger.getLogger( Translation.class ); |
static final Logger log = Logger.getLogger( Translation.class ); |
25 |
static String activeLang = "fr"; |
static String activeLang = "fr"; |
26 |
|
|
27 |
|
static protected List<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>(); |
28 |
|
|
29 |
static { |
static { |
30 |
|
|
31 |
//TODO default aus Locale auslesen und mit möglichen vergleichen... mmm.. vor laden von atlasml immer DEFAULT_KEY, also hier nicht |
//TODO default aus Locale auslesen und mit möglichen vergleichen... mmm.. vor laden von atlasml immer DEFAULT_KEY, also hier nicht |
36 |
} |
} |
37 |
|
|
38 |
@Override |
@Override |
39 |
|
/** |
40 |
|
* @comment To make a copy of a translation see methods toOneLine() and fromOneLine() |
41 |
|
*/ |
42 |
public Translation clone() { |
public Translation clone() { |
43 |
return (Translation) super.clone(); |
return (Translation) super.clone(); |
44 |
} |
} |
69 |
JComponent.setDefaultLocale(newLocale); |
JComponent.setDefaultLocale(newLocale); |
70 |
|
|
71 |
Translation.activeLang = activeLang; |
Translation.activeLang = activeLang; |
72 |
log.info("Translation-system switched to "+activeLang); |
|
73 |
|
fireChangeEvents(); |
74 |
|
|
75 |
|
log.info("skrueger.i8n.Translation switched ActiveLang to "+activeLang); |
76 |
} |
} |
77 |
|
|
78 |
/** |
/** |
79 |
* Initilises a new {@link Translation} with a default translation. |
* Initializes a new {@link Translation} with a default translation. |
80 |
* Other translations may be added later. |
* Other translations may be added later. |
81 |
* |
* |
82 |
* @param defaultTranslation |
* @param defaultTranslation |
92 |
} |
} |
93 |
|
|
94 |
/** |
/** |
95 |
* Initilises a new {@link Translation}, an uses the given String to |
* Initializes a new {@link Translation}, an uses the given String to |
96 |
* initialise the {@link Translation} for all languages codes passed. |
* initialize the {@link Translation} for all languages codes passed. |
97 |
* |
* |
98 |
* The translations can be cahnged later |
* The translations can be changed later |
99 |
*/ |
*/ |
100 |
public Translation(List<String> languages, String defaultTranslation) { |
public Translation(List<String> languages, String defaultTranslation) { |
101 |
// put(DEFAULT_KEY, defaultTranslation); |
// put(DEFAULT_KEY, defaultTranslation); |
212 |
} |
} |
213 |
return backup; |
return backup; |
214 |
} |
} |
215 |
|
|
216 |
|
|
217 |
|
/** |
218 |
|
* {@link PropertyChangeListener} can be registered to be informed when the |
219 |
|
* {@link Locale} changed. |
220 |
|
* |
221 |
|
* @param propertyChangeListener |
222 |
|
*/ |
223 |
|
public static void addLocaleChangeListener(PropertyChangeListener propertyChangeListener) { |
224 |
|
listeners.add(propertyChangeListener); |
225 |
|
} |
226 |
|
|
227 |
|
/** |
228 |
|
* Informs all registered {@link PropertyChangeListener}s about a change of the |
229 |
|
* the {@link Locale}. |
230 |
|
*/ |
231 |
|
public static void fireChangeEvents() { |
232 |
|
PropertyChangeEvent pce = new PropertyChangeEvent(new Translation(new ArrayList<String>(), "fakeSource"), LOCALECHANGE_PROPERTY, |
233 |
|
null, getActiveLang()); |
234 |
|
for (PropertyChangeListener pcl : listeners) { |
235 |
|
if (pcl != null) |
236 |
|
pcl.propertyChange(pce); |
237 |
|
} |
238 |
|
} |
239 |
|
|
240 |
|
|
241 |
} |
} |