/[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 419 by alfonx, Fri Sep 18 15:00:29 2009 UTC revision 420 by alfonx, Thu Oct 1 20:22:48 2009 UTC
# Line 44  import javax.swing.JComponent; Line 44  import javax.swing.JComponent;
44  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
45  import org.opengis.util.InternationalString;  import org.opengis.util.InternationalString;
46    
47    import skrueger.geotools.Copyable;
48    
49  /**  /**
50   * Represents a {@link HashMap} of translations. toString() returns the   * Represents a {@link HashMap} of translations. toString() returns the
51   * appropriate translation   * appropriate translation
# Line 52  import org.opengis.util.InternationalStr Line 54  import org.opengis.util.InternationalStr
54   *         Kr&uuml;ger</a>   *         Kr&uuml;ger</a>
55   */   */
56    
57  public class Translation extends HashMap<String, String> {  public class Translation extends HashMap<String, String> implements Copyable<Translation>{
58          public static final String LOCALECHANGE_PROPERTY = "localechange";          public static final String LOCALECHANGE_PROPERTY = "localechange";
59          public static final String NO_TRANSLATION = "NO TRANSLATION";          public static final String NO_TRANSLATION = "NO TRANSLATION";
60          public static final String DEFAULT_KEY = "default";          public static final String DEFAULT_KEY = "default";
# Line 79  public class Translation extends HashMap Line 81  public class Translation extends HashMap
81           * fromOneLine()           * fromOneLine()
82           */           */
83          public Translation clone() {          public Translation clone() {
84                  return (Translation) super.clone();                  throw new RuntimeException("use copy()");
85    //              return (Translation) super.clone();
86          }          }
87    
88          /**          /**
# Line 192  public class Translation extends HashMap Line 195  public class Translation extends HashMap
195           * @author Stefan Alfons Krüger           * @author Stefan Alfons Krüger
196           */           */
197          public void fromOneLine(final String oneLineCoded) {          public void fromOneLine(final String oneLineCoded) {
198    
199                  clear();                  clear();
200                                    
201                    try {
202                            
203                  if ((oneLineCoded == null) || (oneLineCoded.equals(""))) {                  if ((oneLineCoded == null) || (oneLineCoded.equals(""))) {
204                          put(DEFAULT_KEY, "");                          put(DEFAULT_KEY, "");
205                          return;                          return;
# Line 217  public class Translation extends HashMap Line 223  public class Translation extends HashMap
223                          put(key, value);                          put(key, value);
224                          eatUp = eatUp.substring(eatUp.indexOf("}") + 1);                          eatUp = eatUp.substring(eatUp.indexOf("}") + 1);
225                  }                  }
226                    } catch (Exception e) {
227                            log.warn("Error while reading the oneLineCode '"+oneLineCoded+"'", e);
228                            log.warn("Translation will be empty!");
229                    }
230          }          }
231    
232          /**          /**
# Line 253  public class Translation extends HashMap Line 263  public class Translation extends HashMap
263                  // MS:                  // MS:
264                  else {                  else {
265                          if (get(DEFAULT_KEY) != null) {                          if (get(DEFAULT_KEY) != null) {
                                 // log.debug("default lang returned, cuz the translation to "+activeLang+" was not found. Schmeiss raus martin, wenn du das mit der default trans geklärt hast.");  
266                                  return get(DEFAULT_KEY);                                  return get(DEFAULT_KEY);
267                          }                          }
268    
# Line 268  public class Translation extends HashMap Line 277  public class Translation extends HashMap
277                  return NO_TRANSLATION;                  return NO_TRANSLATION;
278          }          }
279    
         /**  
          * Copy this {@link Translation} to another {@link Translation} e.g. for  
          * editing  
          *  
          * @return the destination {@link Translation}  
          */  
         public Translation copy(Translation backup) {  
                 if (backup == null)  
                         throw new IllegalArgumentException(  
                                         "Target translation may not be null.");  
                 for (String s : keySet()) {  
                         backup.put(s, get(s));  
                 }  
                 return backup;  
         }  
280    
281          /**          /**
282           * {@link PropertyChangeListener} can be registered to be informed when the           * {@link PropertyChangeListener} can be registered to be informed when the
# Line 339  public class Translation extends HashMap Line 333  public class Translation extends HashMap
333                          fromOneLine((String)null);                          fromOneLine((String)null);
334          }          }
335                    
336            /**
337             * Copy this {@link Translation} to another {@link Translation} e.g. for
338             * editing
339             *
340             * @return the destination {@link Translation}
341             */
342            @Override
343            public Translation copyTo(Translation translation2) {
344                    
345                    if (translation2 == null)
346                            throw new IllegalArgumentException(
347                                            "Target translation may not be null.");
348                    for (String s : keySet()) {
349                            translation2.put(s, get(s));
350                    }
351                    
352                    return translation2;
353            }
354            
355    
356            @Override
357            public Translation copy() {
358                    return copyTo(new Translation());
359            }
360    
361            /**
362             * Checks if the {@link String}s stored in the {@link Translation} are all valid.
363             * @return <code>true</code> if all good
364             */
365            public static boolean checkValid(Translation translationToCheck) {
366                    
367                    for (String l : translationToCheck.values()) {
368                            
369                            if (l.contains("{") || l.contains("}")) {
370                    
371                                    return false;
372                            }
373                    }
374                    return true;
375            }
376            
377                    
378  }  }

Legend:
Removed from v.419  
changed lines
  Added in v.420

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26