/[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 482 by alfonx, Tue Oct 20 13:51:11 2009 UTC trunk/src/skrueger/i8n/Translation.java revision 685 by alfonx, Wed Feb 10 15:04:02 2010 UTC
# Line 39  import java.util.Iterator; Line 39  import java.util.Iterator;
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    
# Line 61  public class Translation extends HashMap Line 62  public class Translation extends HashMap
62          public static final String LOCALECHANGE_PROPERTY = "localechange";          public static final String LOCALECHANGE_PROPERTY = "localechange";
63          public static final String NO_TRANSLATION = "NO TRANSLATION";          public static final String NO_TRANSLATION = "NO TRANSLATION";
64          public static final String DEFAULT_KEY = "default";          public static final String DEFAULT_KEY = "default";
65          static final Logger log = 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    
# Line 143  public class Translation extends HashMap Line 145  public class Translation extends HashMap
145    
146                  fireLocaleChangeEvents();                  fireLocaleChangeEvents();
147    
148                  log.info("skrueger.i8n.Translation switched ActiveLang to " + newLang);                  LOGGER.info("skrueger.i8n.Translation switched ActiveLang to "
149                                    + newLang);
150          }          }
151    
152          /**          /**
# Line 175  public class Translation extends HashMap Line 178  public class Translation extends HashMap
178                          put(DEFAULT_KEY, defaultTranslation);                          put(DEFAULT_KEY, defaultTranslation);
179                  } else                  } else
180                          for (String code : languages) {                          for (String code : languages) {
181                                  if (code.equals(getActiveLang())) {  //                              if (code.equals(getActiveLang())) {
182                                          put(code, defaultTranslation);                                          put(code, defaultTranslation);
183                                  }  //                              }
184                          }                          }
185          }          }
186    
# Line 228  public class Translation extends HashMap Line 231  public class Translation extends HashMap
231                                  eatUp = eatUp.substring(eatUp.indexOf("}") + 1);                                  eatUp = eatUp.substring(eatUp.indexOf("}") + 1);
232                          }                          }
233                  } catch (Exception e) {                  } catch (Exception e) {
234                          log.warn("Error while reading the oneLineCode '" + oneLineCoded                          LOGGER.warn("Error while reading the oneLineCode '" + oneLineCoded
235                                          + "'", e);                                          + "'", e);
236                          log.warn("Translation will be empty!");                          LOGGER.warn("Translation will be empty!");
237                  }                  }
238          }          }
239    
# Line 284  public class Translation extends HashMap Line 287  public class Translation extends HashMap
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) {
# Line 294  public class Translation extends HashMap Line 301  public class Translation extends HashMap
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           */           */
# Line 312  public class Translation extends HashMap Line 334  public class Translation extends HashMap
334           * reference as long as you need the listener.           * reference as long as you need the listener.
335           */           */
336          public void addTranslationChangeListener(ActionListener actionListener) {          public void addTranslationChangeListener(ActionListener actionListener) {
337                  actionListeners.add(actionListener);                  if (actionListeners.add(actionListener)) {
338                            LOGGER
339                                            .debug("registering a new translationChangeActionListener in the WeakHashSet");
340                    }
341          }          }
342    
343          /**          /**

Legend:
Removed from v.482  
changed lines
  Added in v.685

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26