/[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

revision 1097 by alfonx, Sun Oct 10 21:14:05 2010 UTC revision 1105 by alfonx, Thu Oct 14 10:35:55 2010 UTC
# Line 65  public class Translation extends HashMap Line 65  public class Translation extends HashMap
65    
66          private static final long serialVersionUID = -347702744122305245L;          private static final long serialVersionUID = -347702744122305245L;
67    
68          public static final String LOCALECHANGE_PROPERTY = "localechange";          public static final String LOCALE_CHANGE_PROPERTY = "localechange";
69          public static final String ACTIVELANG_CHANGE_PROPERTY = "activelangchange";          public static final String ACTIVELANG_CHANGE_PROPERTY = "activelangchange";
70          public static final String NO_TRANSLATION = "NO TRANSLATION";          public static final String NO_TRANSLATION = "NO TRANSLATION";
71          public static final String DEFAULT_KEY = "default";          public static final String DEFAULT_KEY = "default";
# Line 160  public class Translation extends HashMap Line 160  public class Translation extends HashMap
160                  Locale newLocale = new Locale(newLang);                  Locale newLocale = new Locale(newLang);
161                  if (setDefaultLocale) {                  if (setDefaultLocale) {
162    
163                          Locale.setDefault(newLocale);                          setDefaultLocale(newLocale);
                         /**  
                          * Setting default locale for Swing JComponents to work around bug  
                          * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4884480  
                          */  
                         JComponent.setDefaultLocale(newLocale);  
   
                         fireLocaleChangeEvents();  
164    
165                          LOGGER.info(Translation.class.getName()                          LOGGER.info(Translation.class.getName()
166                                          + " switched ActiveLang and Locale to " + newLang);                                          + " switched ActiveLang and Locale to " + newLang);
# Line 380  public class Translation extends HashMap Line 373  public class Translation extends HashMap
373    
374          /**          /**
375           * Informs all registered {@link PropertyChangeListener}s about a change of           * Informs all registered {@link PropertyChangeListener}s about a change of
376           * the the {@link Locale}.           * type LOCALE_CHANGE_PROPERTY the the {@link Locale}.
377           */           */
378          public static void fireLocaleChangeEvents() {          public static void fireLocaleChangeEvents() {
379                  PropertyChangeEvent pce = new PropertyChangeEvent(new Translation(                  PropertyChangeEvent pce = new PropertyChangeEvent(new Translation(
380                                  new ArrayList<String>(), "fakeSource"), LOCALECHANGE_PROPERTY,                                  new ArrayList<String>(), "fakeSource"), LOCALE_CHANGE_PROPERTY,
381                                  null, getActiveLang());                                  null, getActiveLang());
382                  for (PropertyChangeListener pcl : listenersLocaleChange) {                  for (PropertyChangeListener pcl : listenersLocaleChange) {
383                          if (pcl != null)                          if (pcl != null)
# Line 394  public class Translation extends HashMap Line 387  public class Translation extends HashMap
387    
388          /**          /**
389           * Informs all registered {@link PropertyChangeListener}s about a change of           * Informs all registered {@link PropertyChangeListener}s about a change of
390           * the the {@link Locale}.           * type ACTIVELANG_CHANGE_PROPERTY the the {@link Locale}.
391           */           */
392          public static void fireActiveLangChangeEvents() {          public static void fireActiveLangChangeEvents() {
393                  PropertyChangeEvent pce = new PropertyChangeEvent(new Translation(                  PropertyChangeEvent pce = new PropertyChangeEvent(new Translation(
# Line 527  public class Translation extends HashMap Line 520  public class Translation extends HashMap
520          public String toString(String lang) {          public String toString(String lang) {
521                  return get(lang);                  return get(lang);
522          }          }
523    
524            /**
525             * Will set the default Locale (if not already equal) and fire Locale change
526             * events.
527             *
528             * @param if <code>null</code> will do nothing.
529             */
530            public static void setDefaultLocale(Locale locale) {
531    
532                    if (locale == null)
533                            return;
534    
535                    if (Locale.getDefault().equals(locale))
536                            return;
537                    Locale.setDefault(locale);
538                    /**
539                     * Setting default locale for Swing JComponents to work around bug
540                     * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4884480
541                     */
542                    JComponent.setDefaultLocale(locale);
543    
544                    fireLocaleChangeEvents();
545            }
546    
547  }  }

Legend:
Removed from v.1097  
changed lines
  Added in v.1105

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26