/[schmitzm]/trunk/src/skrueger/i8n/Translation.java
ViewVC logotype

Diff of /trunk/src/skrueger/i8n/Translation.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

branches/1.0-gt2-2.6/src/skrueger/i8n/Translation.java revision 486 by alfonx, Tue Oct 20 16:25:26 2009 UTC trunk/src/skrueger/i8n/Translation.java revision 888 by alfonx, Thu Jun 3 10:48:43 2010 UTC
# Line 25  Line 25 
25   *   *
26   * Contributors:   * Contributors:
27   *     Martin O. J. Schmitz - initial API and implementation   *     Martin O. J. Schmitz - initial API and implementation
28   *     Stefan A. Krüger - additional utility classes   *     Stefan A. Tzeggai - additional utility classes
29   ******************************************************************************/   ******************************************************************************/
30  package skrueger.i8n;  package skrueger.i8n;
31    
# Line 33  import java.awt.event.ActionEvent; Line 33  import java.awt.event.ActionEvent;
33  import java.awt.event.ActionListener;  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.io.Serializable;
37  import java.util.ArrayList;  import java.util.ArrayList;
38  import java.util.HashMap;  import java.util.HashMap;
39  import java.util.Iterator;  import java.util.Iterator;
40  import java.util.List;  import java.util.List;
41  import java.util.Locale;  import java.util.Locale;
42  import java.util.Random;  import java.util.Random;
43    import java.util.WeakHashMap;
44    
45  import javax.swing.JComponent;  import javax.swing.JComponent;
46    
# Line 53  import skrueger.geotools.Copyable; Line 55  import skrueger.geotools.Copyable;
55   * appropriate translation   * appropriate translation
56   *   *
57   * @author @author <a href="mailto:[email protected]">Stefan Alfons   * @author @author <a href="mailto:[email protected]">Stefan Alfons
58   *         Kr&uuml;ger</a>   *         Tzeggai</a>
59   */   */
60    
61  public class Translation extends HashMap<String, String> implements  public class Translation extends HashMap<String, String> implements
62                  Copyable<Translation> {                  Copyable<Translation>, Serializable {
63            
64            private static final long serialVersionUID = -347702744122305245L;
65            
66          public static final String LOCALECHANGE_PROPERTY = "localechange";          public static final String LOCALECHANGE_PROPERTY = "localechange";
67          public static final String NO_TRANSLATION = "NO TRANSLATION";          public static final String NO_TRANSLATION = "NO TRANSLATION";
68          public static final String DEFAULT_KEY = "default";          public static final String DEFAULT_KEY = "default";
69          static final Logger LOGGER = Logger.getLogger(Translation.class);          static final Logger LOGGER = Logger.getLogger(Translation.class);
70          static String activeLang = Locale.getDefault().getLanguage();          static String activeLang = Locale.getDefault().getLanguage();
71    
72          static protected List<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>();          static protected WeakHashSet<PropertyChangeListener> listeners = new WeakHashSet<PropertyChangeListener>(
73                            PropertyChangeListener.class);
74    
75          static {          static {
76    
# Line 75  public class Translation extends HashMap Line 81  public class Translation extends HashMap
81                  Locale locale = Locale.getDefault();                  Locale locale = Locale.getDefault();
82                  setActiveLang(locale.getLanguage());                  setActiveLang(locale.getLanguage());
83          }          }
84            
85            
86    
87          private WeakHashSet<ActionListener> actionListeners = new WeakHashSet<ActionListener>(          private WeakHashSet<ActionListener> actionListeners = new WeakHashSet<ActionListener>(
88                          ActionListener.class);                          ActionListener.class);
# Line 143  public class Translation extends HashMap Line 151  public class Translation extends HashMap
151    
152                  fireLocaleChangeEvents();                  fireLocaleChangeEvents();
153    
154                  LOGGER.info("skrueger.i8n.Translation switched ActiveLang to " + newLang);                  LOGGER.info("skrueger.i8n.Translation switched ActiveLang to "
155                                    + newLang);
156          }          }
157    
158          /**          /**
# Line 175  public class Translation extends HashMap Line 184  public class Translation extends HashMap
184                          put(DEFAULT_KEY, defaultTranslation);                          put(DEFAULT_KEY, defaultTranslation);
185                  } else                  } else
186                          for (String code : languages) {                          for (String code : languages) {
187                                  if (code.equals(getActiveLang())) {  //                              if (code.equals(getActiveLang())) {
188                                          put(code, defaultTranslation);                                          put(code, defaultTranslation);
189                                  }  //                              }
190                          }                          }
191          }          }
192    
# Line 196  public class Translation extends HashMap Line 205  public class Translation extends HashMap
205           * <li>If format can't be recognized, the {@link String} is interpreted as           * <li>If format can't be recognized, the {@link String} is interpreted as
206           * the translation in the <code>{@value #DEFAULT_KEY}</code> language           * the translation in the <code>{@value #DEFAULT_KEY}</code> language
207           *           *
208           * @author Stefan Alfons Krüger           * @author Stefan Alfons Tzeggai
209           */           */
210          public void fromOneLine(final String oneLineCoded) {          public void fromOneLine(final String oneLineCoded) {
211    
# Line 237  public class Translation extends HashMap Line 246  public class Translation extends HashMap
246          /**          /**
247           * Exports the Translations to a String of the Format: "de{Baum}en{tree}"           * Exports the Translations to a String of the Format: "de{Baum}en{tree}"
248           *           *
249           * @author Stefan Alfons Krüger           * @author Stefan Alfons Tzeggai
250           */           */
251          public String toOneLine() {          public String toOneLine() {
252                  return I8NUtil.toOneLine(this);                  return I8NUtil.toOneLine(this);
# Line 284  public class Translation extends HashMap Line 293  public class Translation extends HashMap
293    
294          /**          /**
295           * {@link PropertyChangeListener} can be registered to be informed when the           * {@link PropertyChangeListener} can be registered to be informed when the
296           * {@link Locale} changed.           * {@link Locale} changed.<br>
297             * The listeners are kept in a {@link WeakHashMap}, so you have to keep a
298             * reference to the listener or it will be removed!
299           *           *
300           * @param propertyChangeListener           * @param propertyChangeListener
301             *            A {@link PropertyChangeListener} that will be called when
302             *            {@link #setActiveLang(String)} changes the language.
303           */           */
304          public static void addLocaleChangeListener(          public static void addLocaleChangeListener(
305                          PropertyChangeListener propertyChangeListener) {                          PropertyChangeListener propertyChangeListener) {
# Line 294  public class Translation extends HashMap Line 307  public class Translation extends HashMap
307          }          }
308    
309          /**          /**
310             * {@link PropertyChangeListener} can be registered to be informed when the
311             * {@link Locale} changed.<br>
312             * The listeners are kept in a {@link WeakHashMap}, so you have to keep a
313             * reference to the listener or it will be removed!
314             *
315             * @param propertyChangeListener
316             *            A {@link PropertyChangeListener} that will be called when
317             *            {@link #setActiveLang(String)} changes the language.
318             */
319            public static boolean removeLocaleChangeListener(
320                            PropertyChangeListener propertyChangeListener) {
321                    return listeners.remove(propertyChangeListener);
322            }
323    
324            /**
325           * Informs all registered {@link PropertyChangeListener}s about a change of           * Informs all registered {@link PropertyChangeListener}s about a change of
326           * the the {@link Locale}.           * the the {@link Locale}.
327           */           */
# Line 313  public class Translation extends HashMap Line 341  public class Translation extends HashMap
341           */           */
342          public void addTranslationChangeListener(ActionListener actionListener) {          public void addTranslationChangeListener(ActionListener actionListener) {
343                  if (actionListeners.add(actionListener)) {                  if (actionListeners.add(actionListener)) {
344                          LOGGER.debug("registering a new translationChangeActionListener in the WeakHashSet");  //                      LOGGER
345    //                                      .debug("registering a new translationChangeActionListener in the WeakHashSet");
346                  }                  }
347          }          }
348    

Legend:
Removed from v.486  
changed lines
  Added in v.888

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26