[Schmitzm-commits] r39 - in trunk/src/skrueger: geotools i8n
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Apr 6 21:14:55 CEST 2009
Author: alfonx
Date: 2009-04-06 21:14:55 +0200 (Mon, 06 Apr 2009)
New Revision: 39
Modified:
trunk/src/skrueger/geotools/StyledMapInterface.java
trunk/src/skrueger/i8n/I8NUtil.java
trunk/src/skrueger/i8n/SwitchLanguageDialog.java
trunk/src/skrueger/i8n/Translation.java
Log:
* Some corrections in I8N withthe ISO vs. Locale language codes
Modified: trunk/src/skrueger/geotools/StyledMapInterface.java
===================================================================
--- trunk/src/skrueger/geotools/StyledMapInterface.java 2009-04-05 15:06:56 UTC (rev 38)
+++ trunk/src/skrueger/geotools/StyledMapInterface.java 2009-04-06 19:14:55 UTC (rev 39)
@@ -29,8 +29,8 @@
* <li>{@link #getKeywords() get/setKeywords()} -> {@link Translation}</li>
* <li>{@link #getTitle() set/getTitle()} -> {@link Translation} (short
* description for layer list)</li>
- * <li>{@link #getDesc() set/getDesc()} -> {@link Translation} (long
- * description for details)</li>
+ * <li>{@link #getDesc() set/getDesc()} -> {@link Translation} (long description
+ * for details)</li>
* <li>{@link #getCrs()} -> {@link CoordinateReferenceSystem}</li>
* <li>{@link #getCRSString()} -> String (readable description of CRS)</li>
* <li>{@link #getEnvelope()} -> {@link Envelope} (JTS-Envelope)</li>
@@ -48,8 +48,8 @@
* Map<Integer,AttributeMetaData></li>
* </ul>
* </li>
- * <li><b>{@link StyledRasterInterface} extends
- * {@link StyledMapInterface StyledMapInterface<GridCoverage2D>}</b>
+ * <li><b>{@link StyledRasterInterface} extends {@link StyledMapInterface
+ * StyledMapInterface<GridCoverage2D>}</b>
* <ul>
* <li>{@link StyledRasterInterface#getLegendMetaData()} ->
* {@link RasterLegendData}</li>
@@ -61,10 +61,10 @@
* <ul>
* <li>layer list only depends on {@link StyledMapInterface}</li>
* <li>methods returning {@link Translation} must not return {@code null}</li>
- * <li>methods returning {@link AttributeMetaData}-Map must not return
- * {@code null}</li>
- * <li>static helper method to get a new {@link AttributeMetaData}-map withe
- * the visible attributes only</li>
+ * <li>methods returning {@link AttributeMetaData}-Map must not return {@code
+ * null}</li>
+ * <li>static helper method to get a new {@link AttributeMetaData}-map withe the
+ * visible attributes only</li>
* <li>static helper method to create a "default" {@link AttributeMetaData}-map
* for a {@link FeatureCollection} with all attributes visible and without real
* translations, but the attribute name as description.</li>
@@ -92,8 +92,8 @@
public Envelope getEnvelope();
/**
- * @return return an ImageIcon - <code>null</code> is valid and no icon or
- * a default icon will then be shown
+ * @return return an ImageIcon - <code>null</code> is valid and no icon or a
+ * default icon will then be shown
*/
public ImageIcon getImageIcon();
@@ -136,5 +136,12 @@
/**
* If true, this layer will not be shown in the legend. Default = false
*/
- public boolean isHideInLegend();
+ /**
+ *
+ * Killed by SK: 6. April 09 because: Ein Layer soll nicht generell auf
+ * verstecken/nicht verstecken gestellt werden können. Das sind
+ * Eigenschaften der Karte, ebenso wie die Reihenfolge der Layer. Im Atlas hat dashalb die das DataPoolLayer-Referenzobjet (Klasse DpRef) diese Funktion übernommen.
+ *
+ * public boolean isHideInLegend();
+ */
}
Modified: trunk/src/skrueger/i8n/I8NUtil.java
===================================================================
--- trunk/src/skrueger/i8n/I8NUtil.java 2009-04-05 15:06:56 UTC (rev 38)
+++ trunk/src/skrueger/i8n/I8NUtil.java 2009-04-06 19:14:55 UTC (rev 39)
@@ -1,41 +1,46 @@
package skrueger.i8n;
+import java.util.Locale;
import java.util.Set;
import java.util.TreeSet;
public class I8NUtil {
-
+
private static Set<String> languageCodes = new TreeSet<String>();
static {
- for (String code : java.util.Locale.getISOLanguages()) {
- getLanguageCodes().add(code);
- }
- }
-//
-// /**
-// * @Returns an ImageIcon for a given ISO code or null.
-// * @param code ISO Country Code
-// */
-// public static ImageIcon getFlagIcon(String code) {
-//
-// String ressourcename = "resource/flags/" + code.toUpperCase() + ".gif";
-//
-// URL resourceURL = TranslationEditJPanel.class.getResource(ressourcename);
-//
-// if (resourceURL != null)
-// return new ImageIcon( resourceURL);
-//
-// return new ImageIcon();
-// }
-//
-// /**
-// * @Returns an {@link ImageIcon} flag for the language setup as Translation language
-// */
-// public static ImageIcon getFlagIcon() {
-// return getFlagIcon( Translation.getActiveLang() );
-// }
-
-
+ for (Locale locale : java.util.Locale.getAvailableLocales()) {
+ getLanguageCodes().add(locale.getLanguage());
+ }
+ // for (String code : java.util.Locale.getISOLanguages()) {
+ // getLanguageCodes().add(code);
+ // }
+ }
+
+ //
+ // /**
+ // * @Returns an ImageIcon for a given ISO code or null.
+ // * @param code ISO Country Code
+ // */
+ // public static ImageIcon getFlagIcon(String code) {
+ //
+ // String ressourcename = "resource/flags/" + code.toUpperCase() + ".gif";
+ //
+ // URL resourceURL = TranslationEditJPanel.class.getResource(ressourcename);
+ //
+ // if (resourceURL != null)
+ // return new ImageIcon( resourceURL);
+ //
+ // return new ImageIcon();
+ // }
+ //
+ // /**
+ // * @Returns an {@link ImageIcon} flag for the language setup as
+ // Translation language
+ // */
+ // public static ImageIcon getFlagIcon() {
+ // return getFlagIcon( Translation.getActiveLang() );
+ // }
+
/**
* @author Stefan Alfons Krüger
* @param code
@@ -45,12 +50,27 @@
return getLanguageCodes().contains(code);
}
-
/**
- * @return All language codes available in java.util.Locale.getISOLanguages() without duplicates.
+ * @return All language codes available in
+ * java.util.Locale.getISOLanguages() without duplicates.
*/
public static Set<String> getLanguageCodes() {
return languageCodes;
}
+
+ /**
+ * @param code
+ * A two-letter language code.
+ * @return <code>null</code> or one (of many possible) {@link Locale} that
+ * uses this language.
+ */
+ public static Locale getLocaleFor(String code) {
+ for (Locale l : Locale.getAvailableLocales()) {
+ System.out.println(l.getLanguage()+" not = "+code);
+ if (l.getLanguage().toLowerCase().equals(code.toLowerCase())) {
+ return l;
+ }
+ }
+ return null;
+ }
}
-
Modified: trunk/src/skrueger/i8n/SwitchLanguageDialog.java
===================================================================
--- trunk/src/skrueger/i8n/SwitchLanguageDialog.java 2009-04-05 15:06:56 UTC (rev 38)
+++ trunk/src/skrueger/i8n/SwitchLanguageDialog.java 2009-04-06 19:14:55 UTC (rev 39)
@@ -212,12 +212,7 @@
String[] langNames = new String[languages.size() + 1];
for (int i = 0; i < languages.size(); i++) {
- Locale locale = null;
- for (Locale l : Locale.getAvailableLocales()) {
- if (l.getLanguage().equals(languages.get(i))) {
- locale = l;
- }
- }
+ Locale locale = I8NUtil.getLocaleFor(languages.get(i));
langNames[i] = locale.getDisplayLanguage(locale) + " / "
+ locale.getDisplayLanguage() + " / "
Modified: trunk/src/skrueger/i8n/Translation.java
===================================================================
--- trunk/src/skrueger/i8n/Translation.java 2009-04-05 15:06:56 UTC (rev 38)
+++ trunk/src/skrueger/i8n/Translation.java 2009-04-06 19:14:55 UTC (rev 39)
@@ -1,4 +1,5 @@
package skrueger.i8n;
+
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
@@ -11,33 +12,36 @@
import org.apache.log4j.Logger;
/**
- * Represents a {@link HashMap} of translations.
- * toString() returns the appropriate translation
- *
- * @author @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Krüger</a>
+ * Represents a {@link HashMap} of translations. toString() returns the
+ * appropriate translation
+ *
+ * @author @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+ * Krüger</a>
*/
-public class Translation extends HashMap<String, String>{
+public class Translation extends HashMap<String, String> {
public static final String LOCALECHANGE_PROPERTY = "localechange";
public static final String NO_TRANSLATION = "NO TRANSLATION";
public static final String DEFAULT_KEY = "default";
- static final Logger log = Logger.getLogger( Translation.class );
+ static final Logger log = Logger.getLogger(Translation.class);
static String activeLang = "fr";
static protected List<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>();
-
+
static {
-
- //TODO default aus Locale auslesen und mit möglichen vergleichen... mmm.. vor laden von atlasml immer DEFAULT_KEY, also hier nicht
- // Get default locale
- Locale locale = Locale.getDefault();
+ // TODO default aus Locale auslesen und mit möglichen vergleichen...
+ // mmm.. vor laden von atlasml immer DEFAULT_KEY, also hier nicht
+
+ // Get default locale
+ Locale locale = Locale.getDefault();
setActiveLang(locale.getLanguage());
}
-
+
@Override
- /**
- * @comment To make a copy of a translation see methods toOneLine() and fromOneLine()
+ /*
+ * @comment To make a copy of a translation see methods toOneLine() and
+ * fromOneLine()
*/
public Translation clone() {
return (Translation) super.clone();
@@ -51,46 +55,52 @@
}
/**
- * Set up the {@link Translation}-system to use language. If a change is performed, events are fired to listeners. Nothing is done if the new language equals the old language.
+ * Set up the {@link Translation}-system to use language. If a change is
+ * performed, events are fired to listeners. Nothing is done if the new
+ * language equals the old language.
*
- * @param newLang The ISO Code of the new active language
+ * @param newLang
+ * The ISO Code of the new active language
*/
public static void setActiveLang(String newLang) {
if (getActiveLang().equals(newLang)) {
return;
}
-
+
if (!I8NUtil.isValidISOLangCode(newLang)) {
- throw new IllegalArgumentException("'"+newLang+"' is not a valid ISO language code.");
+ throw new IllegalArgumentException("'" + newLang
+ + "' is not a valid ISO language code.");
}
Locale newLocale = new Locale(newLang);
Locale.setDefault(newLocale);
-
+
/**
- * Setting default locale for Swing JComponents to work around bug
+ * Setting default locale for Swing JComponents to work around bug
* http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4884480
*/
JComponent.setDefaultLocale(newLocale);
-
+
Translation.activeLang = newLang;
-
+
fireChangeEvents();
-
- log.info("skrueger.i8n.Translation switched ActiveLang to "+newLang);
+
+ log.info("skrueger.i8n.Translation switched ActiveLang to " + newLang);
}
/**
- * Initializes a new {@link Translation} with a default translation.
- * Other translations may be added later.
- *
+ * Initializes a new {@link Translation} with a default translation. Other
+ * translations may be added later.
+ *
* @param defaultTranslation
- *
- * @deprecated SK: The concept of the default translation doesn't seem so nice to me anymore..
- * I would prefer the default translation to be set for all valid languages.
- *
- * @see public Translation(List<String> languages, String defaultTranslation) {
- *
+ *
+ * @deprecated SK: The concept of the default translation doesn't seem so
+ * nice to me anymore.. I would prefer the default translation
+ * to be set for all valid languages.
+ *
+ * @see public Translation(List<String> languages, String
+ * defaultTranslation) {
+ *
*/
public Translation(String defaultTranslation) {
put(DEFAULT_KEY, defaultTranslation);
@@ -99,19 +109,19 @@
/**
* Initializes a new {@link Translation}, an uses the given String to
* initialize the {@link Translation} for all languages codes passed.
- *
+ *
* The translations can be changed later
*/
public Translation(List<String> languages, String defaultTranslation) {
// put(DEFAULT_KEY, defaultTranslation);
if (languages == null) {
put(DEFAULT_KEY, defaultTranslation);
- }
- else for (String code : languages){
- if (code.equals(getActiveLang())) {
- put(code, defaultTranslation);
+ } else
+ for (String code : languages) {
+ if (code.equals(getActiveLang())) {
+ put(code, defaultTranslation);
+ }
}
- }
}
/**
@@ -126,79 +136,85 @@
* Format of {@link String} is: "de{Baum}en{tree}"
* <p>
* <ul>
- * <li> If <code>oneLineCoded</code> is empty or null, NO TRANSLATION is set.
- * <li> If format can't be recognized, the {@link String} is interpreted as the translation in the <code>{@value #DEFAULT_KEY}</code> language
- *
+ * <li>If <code>oneLineCoded</code> is empty or null, NO TRANSLATION is set.
+ * <li>If format can't be recognized, the {@link String} is interpreted as
+ * the translation in the <code>{@value #DEFAULT_KEY}</code> language
+ *
* @author Stefan Alfons Krüger
*/
- public void fromOneLine( final String oneLineCoded) {
+ public void fromOneLine(final String oneLineCoded) {
clear();
- if ( (oneLineCoded == null) || (oneLineCoded.equals("")) ) {
- put(DEFAULT_KEY,NO_TRANSLATION);
+ if ((oneLineCoded == null) || (oneLineCoded.equals(""))) {
+ put(DEFAULT_KEY, NO_TRANSLATION);
return;
}
if (oneLineCoded.indexOf("}") == -1) {
- // log.warn("The String '"+oneLineCoded+"' is not in oneLine coded => put(DEFAULT_KEY,oneLineCoded);");
- put(DEFAULT_KEY,oneLineCoded);
+ // log.warn("The String '"+oneLineCoded+"' is not in oneLine coded => put(DEFAULT_KEY,oneLineCoded);");
+ put(DEFAULT_KEY, oneLineCoded);
}
String eatUp = oneLineCoded;
- while ( eatUp.indexOf("}") != -1) {
+ while (eatUp.indexOf("}") != -1) {
String substring = eatUp.substring(0, eatUp.indexOf("}"));
-// log.debug("substring = "+substring);
- String key = substring.substring(0, substring.indexOf("{") );
- String value = substring.substring(substring.indexOf("{")+1, substring.length() );
-// log.debug("key="+key);
-// log.debug("value="+value);
- put(key,value);
- eatUp = eatUp.substring(eatUp.indexOf("}")+1);
+ // log.debug("substring = "+substring);
+ String key = substring.substring(0, substring.indexOf("{"));
+ String value = substring.substring(substring.indexOf("{") + 1,
+ substring.length());
+ // log.debug("key="+key);
+ // log.debug("value="+value);
+ put(key, value);
+ eatUp = eatUp.substring(eatUp.indexOf("}") + 1);
}
}
/**
* Exports the Translations to a String of the Format: "de{Baum}en{tree}"
+ *
* @author Stefan Alfons Krüger
*/
- public String toOneLine(){
+ public String toOneLine() {
StringBuffer oneLine = new StringBuffer();
- for (String key: keySet()) {
- oneLine.append(key+"{"+ get(key) + "}");
+ for (String key : keySet()) {
+ oneLine.append(key + "{" + get(key) + "}");
}
return oneLine.toString();
}
/**
- * Returns the right translation by using the {@link #activeLang} field.
- * If no translation is set, an ugly String {@link #NO_TRANSLATION} will re returned. This might be changed for the final release.
- * If the correct language was not found, any entry in the {@link Translation} {@link HashMap} will be returned, that contains
- * more than an empty string.
+ * Returns the right translation by using the {@link #activeLang} field. If
+ * no translation is set, an ugly String {@link #NO_TRANSLATION} will re
+ * returned. This might be changed for the final release. If the correct
+ * language was not found, any entry in the {@link Translation}
+ * {@link HashMap} will be returned, that contains more than an empty
+ * string.
*/
@Override
- public String toString(){
- if ( get(activeLang) != null ) {
+ public String toString() {
+ if (get(activeLang) != null) {
return get(activeLang);
}
- //****************************************************************************
- // MS: The ISDSS needs the concept of the default lang!! So I took the
- // following in again!!
- //****************************************************************************
-// else return "";
-// //****************************************************************************
-// // The following is commented out.. the concept of the default lang seems to be bad....
-// //****************************************************************************
- // MS:
+ // ****************************************************************************
+ // MS: The ISDSS needs the concept of the default lang!! So I took the
+ // following in again!!
+ // ****************************************************************************
+ // else return "";
+ // //****************************************************************************
+ // // The following is commented out.. the concept of the default lang
+ // seems to be bad....
+ // //****************************************************************************
+ // MS:
else {
- if ( get(DEFAULT_KEY) != null ) {
-// log.debug("default lng returned, cuz the translation to "+activeLang+" was not found. Schmeiss raus martin, wenn du das mit der default trans geklärt hast.");
+ if (get(DEFAULT_KEY) != null) {
+ // log.debug("default lng returned, cuz the translation to "+activeLang+" was not found. Schmeiss raus martin, wenn du das mit der default trans geklärt hast.");
return get(DEFAULT_KEY);
}
// log.debug("return first best <> '' ");
if (size() > 0)
- for ( String s : values() ) {
- if ( (s != null) && (s.trim().length()>0) )
+ for (String s : values()) {
+ if ((s != null) && (s.trim().length() > 0))
return s;
}
}
@@ -207,36 +223,39 @@
}
/**
- * Copy this {@link Translation} to another {@link Translation}
- * e.g. for editing
- *
+ * 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) );
+ if (backup == null)
+ throw new IllegalArgumentException(
+ "Target translation may not be null.");
+ for (String s : keySet()) {
+ backup.put(s, get(s));
}
return backup;
}
-
-
+
/**
* {@link PropertyChangeListener} can be registered to be informed when the
* {@link Locale} changed.
*
* @param propertyChangeListener
*/
- public static void addLocaleChangeListener(PropertyChangeListener propertyChangeListener) {
+ public static void addLocaleChangeListener(
+ PropertyChangeListener propertyChangeListener) {
listeners.add(propertyChangeListener);
}
/**
- * Informs all registered {@link PropertyChangeListener}s about a change of the
- * the {@link Locale}.
+ * Informs all registered {@link PropertyChangeListener}s about a change of
+ * the the {@link Locale}.
*/
public static void fireChangeEvents() {
- PropertyChangeEvent pce = new PropertyChangeEvent(new Translation(new ArrayList<String>(), "fakeSource"), LOCALECHANGE_PROPERTY,
+ PropertyChangeEvent pce = new PropertyChangeEvent(new Translation(
+ new ArrayList<String>(), "fakeSource"), LOCALECHANGE_PROPERTY,
null, getActiveLang());
for (PropertyChangeListener pcl : listeners) {
if (pcl != null)
More information about the Schmitzm-commits
mailing list