/[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 888 by alfonx, Thu Jun 3 10:48:43 2010 UTC revision 905 by alfonx, Thu Jun 10 08:00:37 2010 UTC
# Line 40  import java.util.Iterator; Line 40  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.Set;
44  import java.util.WeakHashMap;  import java.util.WeakHashMap;
45    
46  import javax.swing.JComponent;  import javax.swing.JComponent;
# Line 48  import org.apache.log4j.Logger; Line 49  import org.apache.log4j.Logger;
49  import org.geotools.util.WeakHashSet;  import org.geotools.util.WeakHashSet;
50  import org.opengis.util.InternationalString;  import org.opengis.util.InternationalString;
51    
52    import schmitzm.lang.ResourceProvider;
53    import schmitzm.lang.SortableVector;
54  import skrueger.geotools.Copyable;  import skrueger.geotools.Copyable;
55    
56  /**  /**
# Line 60  import skrueger.geotools.Copyable; Line 63  import skrueger.geotools.Copyable;
63    
64  public class Translation extends HashMap<String, String> implements  public class Translation extends HashMap<String, String> implements
65                  Copyable<Translation>, Serializable {                  Copyable<Translation>, Serializable {
66            
67          private static final long serialVersionUID = -347702744122305245L;          private static final long serialVersionUID = -347702744122305245L;
68            
69          public static final String LOCALECHANGE_PROPERTY = "localechange";          public static final String LOCALECHANGE_PROPERTY = "localechange";
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 81  public class Translation extends HashMap Line 84  public class Translation extends HashMap
84                  Locale locale = Locale.getDefault();                  Locale locale = Locale.getDefault();
85                  setActiveLang(locale.getLanguage());                  setActiveLang(locale.getLanguage());
86          }          }
           
           
87    
88          private WeakHashSet<ActionListener> actionListeners = new WeakHashSet<ActionListener>(          private WeakHashSet<ActionListener> actionListeners = new WeakHashSet<ActionListener>(
89                          ActionListener.class);                          ActionListener.class);
# Line 107  public class Translation extends HashMap Line 108  public class Translation extends HashMap
108          /**          /**
109           * Set up the {@link Translation}-system to use language. If a change is           * Set up the {@link Translation}-system to use language. If a change is
110           * performed, events are fired to listeners. Nothing is done if the new           * performed, events are fired to listeners. Nothing is done if the new
111           * language equals the old language. The system's default locale is changed.           * language equals the old language. The system's default {@link Locale} is changed.
112           *           *
113           * @param newLang           * @param newLang
114           *            The ISO Code of the new active language           *            The ISO Code of the new active language
# Line 184  public class Translation extends HashMap Line 185  public class Translation extends HashMap
185                          put(DEFAULT_KEY, defaultTranslation);                          put(DEFAULT_KEY, defaultTranslation);
186                  } else                  } else
187                          for (String code : languages) {                          for (String code : languages) {
188  //                              if (code.equals(getActiveLang())) {                                  // if (code.equals(getActiveLang())) {
189                                          put(code, defaultTranslation);                                  put(code, defaultTranslation);
190  //                              }                                  // }
191                          }                          }
192          }          }
193    
# Line 341  public class Translation extends HashMap Line 342  public class Translation extends HashMap
342           */           */
343          public void addTranslationChangeListener(ActionListener actionListener) {          public void addTranslationChangeListener(ActionListener actionListener) {
344                  if (actionListeners.add(actionListener)) {                  if (actionListeners.add(actionListener)) {
345  //                      LOGGER                          // LOGGER
346  //                                      .debug("registering a new translationChangeActionListener in the WeakHashSet");                          // .debug("registering a new translationChangeActionListener in the WeakHashSet");
347                  }                  }
348          }          }
349    
# Line 422  public class Translation extends HashMap Line 423  public class Translation extends HashMap
423                  return true;                  return true;
424          }          }
425    
426            /**
427             * Goes through the available languages of the FIRST registered {@link ResourceProvider} and set the active locale to the fist match.
428             *
429             * @param fireChangeEvent if <code>true</code>, a Translation.fireLocaleChangeEvents() is issued.
430    
431             * @return
432             */
433            public static boolean setFirstmatchingLanguage(List<String> languages,
434                            boolean fireChangeEvent) {
435    
436                    SortableVector<ResourceProvider> registeredResourceProvider = ResourceProvider
437                                    .getRegisteredResourceProvider();
438                    Set<Locale> available = ResourceProvider.getAvailableLocales(
439                                    registeredResourceProvider.get(0), true);
440    
441                    for (String l : languages) {
442                            for (Locale loc : available) {
443                                    if (loc.getLanguage().equals(l)) {
444                                            Translation.setActiveLang(l);
445                                            if (fireChangeEvent)
446                                                    Translation.fireLocaleChangeEvents();
447                                            return true;
448                                    }
449                            }
450                    }
451    
452                    return false;
453    
454            }
455  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26