[Schmitzm-commits] r1425 - in trunk: schmitzm-core/src/main/java/de/schmitzm schmitzm-core/src/main/java/de/schmitzm/i18n schmitzm-core/src/main/java/de/schmitzm/i8n schmitzm-core/src/main/java/de/schmitzm/swing schmitzm-core/src/main/java/de/schmitzm/xml schmitzm-core/src/test/java/de/schmitzm schmitzm-core/src/test/java/de/schmitzm/i18n schmitzm-gt/src/main/java/de/schmitzm/geotools schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd schmitzm-gt/src/main/java/de/schmitzm/geotools/data/rld schmitzm-gt/src/main/java/de/schmitzm/geotools/gui schmitzm-gt/src/main/java/de/schmitzm/geotools/styling schmitzm-jfree/src/main/java/de/schmitzm/jfree/chart/style schmitzm-jfree/src/main/java/de/schmitzm/jfree/table/style
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Jan 27 12:52:59 CET 2011
Author: alfonx
Date: 2011-01-27 12:52:53 +0100 (Thu, 27 Jan 2011)
New Revision: 1425
Added:
trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/
trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/I18NUtil.java
trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/LanguagesComboBox.java
trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/PropertiesLocale.java
trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/SwitchLanguageDialog.java
trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/Translation.java
trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/Utf8ResourceBundle.java
trunk/schmitzm-core/src/test/java/de/schmitzm/i18n/
trunk/schmitzm-core/src/test/java/de/schmitzm/i18n/I18NUtilTest.java
trunk/schmitzm-core/src/test/java/de/schmitzm/i18n/SwitchLanguageDialogTest.java
trunk/schmitzm-core/src/test/java/de/schmitzm/i18n/TranslationTest.java
Removed:
trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/I8NUtil.java
trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/LanguagesComboBox.java
trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/PropertiesLocale.java
trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/SwitchLanguageDialog.java
trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/Translation.java
trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/TranslationTool.java
trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/Utf8ResourceBundle.java
Modified:
trunk/schmitzm-core/src/main/java/de/schmitzm/swing/TranslationEditJPanel.java
trunk/schmitzm-core/src/main/java/de/schmitzm/swing/TranslationJTextField.java
trunk/schmitzm-core/src/main/java/de/schmitzm/swing/TranslationsAskJPanel.java
trunk/schmitzm-core/src/main/java/de/schmitzm/xml/XMLUtil.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/MapContextManagerInterface.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AbstractAttributeMetadata.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetaDataAttributeTypeFilter.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataImpl.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataImplMap.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataInterface.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataMap.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/rld/RasterLegendData.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/AtlasFeatureLayerFilterDialog.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/CrsLabel.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/MapPaneStatusBar.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/MapPaneToolBar.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/MapView.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/XMapPane.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/XMapPaneTool.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/AbstractStyledLayer.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFS.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeatureCollection.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverage.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverageReader.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerInterface.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerUtil.java
trunk/schmitzm-jfree/src/main/java/de/schmitzm/jfree/chart/style/ChartAxisStyle.java
trunk/schmitzm-jfree/src/main/java/de/schmitzm/jfree/chart/style/ChartLabelStyle.java
trunk/schmitzm-jfree/src/main/java/de/schmitzm/jfree/table/style/TableChartAxisStyle.java
Log:
Copied: trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/I18NUtil.java (from rev 1423, trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/I8NUtil.java)
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/I8NUtil.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/I18NUtil.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -0,0 +1,287 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+package de.schmitzm.i18n;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.log4j.Logger;
+
+public class I18NUtil {
+ static final Logger LOGGER = Logger.getLogger(I18NUtil.class);
+
+ public static final HashMap<String, PropertiesLocale> propLocales = new HashMap<String, PropertiesLocale>();
+
+ private static Set<String> languageCodes = new TreeSet<String>();
+ static {
+ for (final Locale locale : java.util.Locale.getAvailableLocales()) {
+ languageCodes.add(locale.getLanguage());
+ }
+ for (String code : java.util.Locale.getISOLanguages()) {
+ languageCodes.add(code);
+ }
+ for (String lang : getPropertiesLanguages()) {
+ languageCodes.add(lang);
+ }
+ }
+
+ /**
+ * Creates a {@link Translation}<br/>
+ * <p>
+ * <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 Tzeggai
+ */
+ public static Translation createFromOneLine(final String oneLineCoded) {
+ final Translation result = new Translation();
+ result.fromOneLine(oneLineCoded);
+ return result;
+ }
+
+ /**
+ * A list of Locales defined in a <code>locales.properties</code> File on
+ * the classpath.
+ */
+ static Set<String> getPropertiesLanguages() {
+
+ // TODO read these definitions from a text file
+ // URL resource = I18NUtil.class.getResource("/gplocales.properties");
+
+ Locale oshikwanya = new Locale("ok", "na");
+ PropertiesLocale plo1 = new PropertiesLocale(oshikwanya, new Locale(
+ "kj", "na"), "Oshikwanya");
+ propLocales.put(plo1.getLanguage(), plo1);
+
+ Locale oshindonga = new Locale("od", "na");
+ PropertiesLocale plo2 = new PropertiesLocale(oshindonga, new Locale(
+ "kj", "na"), "Oshindonga");
+ propLocales.put(plo2.getLanguage(), plo2);
+
+ return propLocales.keySet();
+ }
+
+ /**
+ * Returns the Translation to a String of the Format: "de{Baum}en{tree}" <br/>
+ *
+ *
+ * @author Stefan Alfons Tzeggai
+ */
+ public static String toOneLine(final Translation source) {
+ final StringBuffer oneLine = new StringBuffer();
+ for (final String key : source.keySet()) {
+ oneLine.append(key + "{" + source.get(key) + "}");
+ }
+ return oneLine.toString();
+ }
+
+ /**
+ * @author Stefan Alfons Tzeggai
+ * @param code
+ * @return true if the code paramter is a valid ISO Language code
+ */
+ public static boolean isValidISOLangCode(final String code) {
+ return Arrays.asList(java.util.Locale.getISOLanguages()).contains(code);
+ }
+
+ /**
+ * @author Stefan Alfons Tzeggai
+ * @param code
+ * @return true if the code paramter is a valid ISO Language code
+ */
+ public static boolean isValidLangCode(final String code) {
+ return getLanguageCodes().contains(code);
+ }
+
+ /**
+ * @return All language codes available in
+ * java.util.Locale.getISOLanguages() without duplicates.
+ */
+ public static Set<String> getLanguageCodes() {
+ return languageCodes;
+ }
+
+ /**
+ * Lookup {@link Locale} where they speak the 2 letter code language.
+ *
+ * @param code
+ * A two-letter language code.
+ * @return <code>null</code> or one (of many possible) {@link Locale} that
+ * uses this language.
+ */
+ public static List<Locale> getLocalesForLang(final String code) {
+
+ final ArrayList<Locale> locales = new ArrayList<Locale>();
+
+ for (final Locale l : Locale.getAvailableLocales()) {
+ if (l.getLanguage().equals(code.toLowerCase())) {
+ locales.add(l);
+ }
+ }
+
+ return locales;
+ }
+
+ /**
+ * Lookup first country where they speak the 2 letter code language.
+ *
+ * @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 getFirstLocaleForLang(final String code) {
+
+ List<Locale> locales = getLocalesForLang(code);
+
+ if (locales.size() > 0)
+ return locales.get(0);
+
+ Locale l = new Locale(code);
+ // LOGGER.error("Can't find Locale for code " + code
+ // + "! Returning a selfmade locale");
+ return l;
+
+ // return Locale.getDefault();
+ }
+
+ /**
+ * A convenience method that checks if the {@link Translation} object
+ * contains a translation for the active language. A {@link String}
+ * containing only spaces will return <code>false</code>.
+ *
+ * @param trans
+ * {@link Translation} to check.
+ */
+ public static boolean isEmpty(final Translation trans) {
+ if (trans == null)
+ return true;
+ return isEmpty(trans.toString());
+ }
+
+ /**
+ * A convenience method that checks if the {@link String} returned by from a
+ * {@link Translation} object contains a "valid" translation for the active
+ * language. A {@link String} containing only spaces or equals
+ * {@link Translation}.NO_TRANSLATION will return <code>false</code>.
+ *
+ * @param transString
+ * {@link String} to check.
+ */
+ public static boolean isEmpty(final String transString) {
+ if (transString == null)
+ return true;
+ if (transString.trim().isEmpty())
+ return true;
+ if (transString.equals(Translation.NO_TRANSLATION))
+ return true;
+ return false;
+ }
+
+ /**
+ * @return a {@link Double} between 0 and 1 representing the part of the
+ * given {@link Translation} that has been filled.
+ * @param ac
+ * {@link AtlasConfig} to determine the languages to expect.
+ * @param trans
+ * The {@link Translation} to check.
+ */
+ public static double qmTranslation(final List<String> languages,
+ final Translation trans) {
+
+ if (trans == null)
+ return 0.;
+
+ Integer cunt = 0;
+ for (final String l : languages) {
+ final String t = trans.get(l);
+ if (!isEmpty(t))
+ cunt++;
+ }
+ return cunt.doubleValue() / languages.size();
+ }
+
+ /**
+ * The German Umlaute have standard ASCII alternatives that are sometimes
+ * use. This method will replace any possible ASCII-Umlaut Representation
+ * into real Umlaute. E.g. "ae" to "ä" and "ue" to "ü". Umlaute are returned
+ * as inline-UTF8.
+ */
+ public static String mitUmlaute(final String withoutUmlaute) {
+ String replaced = withoutUmlaute;
+
+ replaced = replaced.replaceAll("ue", "\u00FC");
+ replaced = replaced.replaceAll("Ue", "\u00DC");
+
+ replaced = replaced.replaceAll("oe", "\u00F6");
+ replaced = replaced.replaceAll("Oe", "\u00D6");
+
+ replaced = replaced.replaceAll("ae", "\u00E4");
+ replaced = replaced.replaceAll("Ae", "\u00C4");
+ return replaced;
+ }
+
+ public static boolean isPropertiesLanguage(String langCode) {
+ for (String lc : getPropertiesLanguages()) {
+ if (lc.equals(langCode))
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Returns a String that displays the denoted language in three ways, e.g.
+ * "German / Deutsch / de" on a computer that has English as an active
+ * Locale.
+ */
+ public static String getMultilanguageString(String langCode) {
+ if (isValidISOLangCode(langCode)) {
+ /**
+ * Lookup a Locale where they speak the language, so we can print
+ * the language in local tounge.
+ */
+ Locale locale = getFirstLocaleForLang(langCode);
+ return locale.getDisplayLanguage(locale) + " / "
+ + locale.getDisplayLanguage() + " / " + langCode;
+ } else if (isPropertiesLanguage(langCode)) {
+ PropertiesLocale pl = propLocales.get(langCode);
+ return pl.getDisplayLanguage() + " / "
+ + pl.getDisplayLanguage(langCode) + " " + langCode;
+ }
+
+ return langCode;
+ }
+}
Property changes on: trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/I18NUtil.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id URL
Name: svn:eol-style
+ native
Copied: trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/LanguagesComboBox.java (from rev 1423, trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/LanguagesComboBox.java)
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/LanguagesComboBox.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/LanguagesComboBox.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -0,0 +1,90 @@
+package de.schmitzm.i18n;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Vector;
+
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.JComboBox;
+
+/**
+ * A JComboBox that shows the user a list of languages
+ */
+public class LanguagesComboBox extends JComboBox {
+
+ private final Vector<String> availLangs = new Vector<String>();
+
+ public LanguagesComboBox() {
+ super();
+ }
+
+ /**
+ * Create a ComboBox with the given langauges as options
+ */
+ public LanguagesComboBox(Collection<String> langCodes) {
+ this();
+ updateModel(langCodes, null);
+ }
+
+ /**
+ * Create a ComboBox with the given languages as options, excluding the
+ * second parameter.
+ *
+ * @param langCodes
+ * If <code>null</code>, {@link I8NUtil#getLanguageCodes()} will
+ * be used
+ */
+ public LanguagesComboBox(Collection<String> langCodes,
+ Collection<String> langCodesNotOffer) {
+ this();
+ updateModel(langCodes, langCodesNotOffer);
+ }
+
+ public void updateModel(Collection<String> langCodes,
+ Collection<String> langCodesNotOffer) {
+
+ if (langCodes == null) {
+ langCodes = I18NUtil.getLanguageCodes();
+ }
+
+ if (langCodesNotOffer != null) {
+ langCodes = new ArrayList<String>(langCodes);
+ langCodes.removeAll(langCodesNotOffer);
+ }
+
+ availLangs.clear();
+
+ for (String lc : langCodes) {
+ //
+ // if (I8NUtil.isValidISOLangCode(lc)) {
+ // Locale locale = I8NUtil.getFirstLocaleForLang(lc);
+ // availLangs.add(locale.getDisplayLanguage() + " / "
+ // + locale.getDisplayLanguage(locale) + " " + lc);
+ // } else if (I8NUtil.isPropertiesLanguage(lc)) {
+ //
+ // PropertiesLocale pl = I8NUtil.propLocales.get(lc);
+ // availLangs.add(pl.getDisplayLanguage() + " / "
+ // + pl.getDisplayLanguage(lc) + " " + lc);
+ // }
+
+ availLangs.add(I18NUtil.getMultilanguageString(lc));
+ }
+
+ Collections.sort(availLangs);
+
+ setModel(new DefaultComboBoxModel(availLangs));
+ setSelectedIndex(-1);
+ repaint();
+ }
+
+ public String getSelectedLanguage() {
+ if (getSelectedIndex() < 0)
+ return null;
+ String langDescription = availLangs.get(getSelectedIndex());
+
+ return langDescription.substring(langDescription.lastIndexOf(" "))
+ .trim();
+ }
+
+}
Property changes on: trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/LanguagesComboBox.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id URL
Name: svn:eol-style
+ native
Copied: trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/PropertiesLocale.java (from rev 1423, trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/PropertiesLocale.java)
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/PropertiesLocale.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/PropertiesLocale.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -0,0 +1,63 @@
+package de.schmitzm.i18n;
+
+import java.util.HashMap;
+import java.util.Locale;
+
+/**
+ */
+public class PropertiesLocale {
+
+ /**
+ * Language names => Translations
+ */
+ HashMap<String, String> displayLanguages = new HashMap<String, String>();
+
+ private final Locale locale;
+
+ private final String nativeName;
+
+ private final Locale parentLocale;
+
+ public PropertiesLocale(Locale locale, Locale parentLocale,
+ String nativeName) {
+ if (I18NUtil.isValidISOLangCode(locale.getLanguage()))
+ throw new IllegalArgumentException(
+ locale.getLanguage()
+ + " can not be defined as a PropertiesLocale langauge, since it is an existing ISO language code.");
+
+ this.parentLocale = parentLocale;
+ this.locale = locale;
+ this.nativeName = nativeName;
+ }
+
+ public String getDisplayLanguage(String langCode) {
+ if (langCode == null || displayLanguages.containsKey(langCode))
+ return displayLanguages.get(langCode);
+ else
+ return nativeName;
+ }
+
+ public String getDisplayLanguage() {
+ return getDisplayLanguage(Locale.getDefault().getLanguage());
+ }
+
+ public void setDisplayLanguages(String langCode, String languageName) {
+ displayLanguages.put(langCode, languageName);
+ }
+
+ public String getLanguage() {
+ return locale.getLanguage();
+ }
+
+ public String getCountry() {
+ return locale.getCountry();
+ }
+
+ public String getDisplayCountry() {
+ return locale.getDisplayCountry();
+ }
+
+ public Locale getParentLocale() {
+ return parentLocale;
+ }
+}
Property changes on: trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/PropertiesLocale.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id URL
Name: svn:eol-style
+ native
Copied: trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/SwitchLanguageDialog.java (from rev 1423, trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/SwitchLanguageDialog.java)
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/SwitchLanguageDialog.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/SwitchLanguageDialog.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -0,0 +1,245 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+package de.schmitzm.i18n;
+
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.ImageIcon;
+import javax.swing.JComboBox;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+import net.miginfocom.swing.MigLayout;
+
+import org.apache.log4j.Logger;
+
+import de.schmitzm.swing.AtlasDialog;
+import de.schmitzm.swing.OkButton;
+import de.schmitzm.swing.SwingUtil;
+import de.schmitzm.swing.TranslationEditJPanel;
+
+/**
+ * This dialog ask the user to select one of list of given languages. The dialog
+ * is modal and not visible after construction.
+ *
+ * @author Stefan A. Tzeggai
+ */
+public class SwitchLanguageDialog extends AtlasDialog {
+ protected Logger LOGGER = Logger.getLogger(SwitchLanguageDialog.class);
+
+ private JPanel jContentPane = null;
+
+ private JLabel jLabelFlagimage = null;
+
+ private JPanel jPanel = null;
+
+ private JLabel jLabel = null;
+
+ private OkButton jButton = null;
+
+ private LanguagesComboBox jComboBox = null;
+
+ private final List<String> languages;
+
+ /**
+ * if <code>true</code>, the default locale will also be changed during a
+ * language selection
+ **/
+ protected boolean setLocale;
+
+ /**
+ * A dialog to select one of the available languages. If only one language
+ * is available, select it directly. Creating this object automatically
+ * makes it visible, unless there is only one language to choose from.. it
+ * that case it disposes itself automatically.
+ *
+ * @param setLocale if <code>true</code>, the default locale will also be
+ * changed during a language selection
+ */
+ public SwitchLanguageDialog(final Component owner,
+ final List<String> languages, boolean setLocale) {
+ super(owner);
+ this.languages = languages;
+ this.setLocale = setLocale;
+
+ if (languages == null || languages.size() == 0) {
+ // No language is available.
+ return;
+ }
+
+ Translation.setActiveLang(languages.get(0), setLocale);
+ if (languages.size() == 1) {
+ // Only language one language is available. It has been selected
+ // automatically.
+ return;
+ }
+
+ initialize();
+ }
+
+ @Override
+ /**
+ * This modal dialog will not appear if there is <= one language to select from.
+ */
+ public void setVisible(boolean b) {
+ if (b == true && (languages == null || languages.size() <= 1)) {
+ return;
+ }
+ super.setVisible(b);
+ }
+
+ /**
+ * This method initializes this
+ *
+ * @return void
+ */
+ private void initialize() {
+ this.setContentPane(getJContentPane());
+
+ pack();
+
+ SwingUtil.centerFrameOnScreenRandom(this);
+ setModal(true);
+ }
+
+ public boolean close() {
+ // Only close by ESC and window-close if a valid selection is made
+ if (jComboBox.getSelectedIndex() == languages.size()
+ || jComboBox.getSelectedIndex() == -1)
+ return false;
+ else
+ return super.close();
+ }
+
+ /**
+ * This method initializes jContentPane
+ *
+ * @return javax.swing.JPanel
+ */
+ private JPanel getJContentPane() {
+ if (jContentPane == null) {
+ jLabelFlagimage = new JLabel(new ImageIcon(
+ TranslationEditJPanel.class
+ .getResource("resource/flags.jpg")));
+ jContentPane = new JPanel();
+ MigLayout migLayout = new MigLayout("wrap 1", "[center]", "[]0[]");
+ jContentPane.setLayout(migLayout);
+ jContentPane.add(jLabelFlagimage, "north");
+ jContentPane.add(getLanguageCombobox());
+ jContentPane.add(getOkButton(),
+ "right, w 50!, gaptop 5, gapright 5, gapbottom 5");
+ }
+ return jContentPane;
+ }
+
+ /**
+ * This method initializes the OkButton
+ *
+ * @return javax.swing.JButton
+ */
+ @Override
+ protected OkButton getOkButton() {
+ if (jButton == null) {
+ jButton = new OkButton();
+ jButton.setEnabled(false);
+
+ jButton.addActionListener(new ActionListener() {
+
+ public void actionPerformed(ActionEvent e) {
+ dispose();
+ }
+
+ });
+ }
+ return jButton;
+ }
+
+ /**
+ * This method initializes the JPanel that carries the select language
+ * combobox
+ *
+ * @return javax.swing.JPanel
+ */
+ private JPanel getLanguageCombobox() {
+ if (jPanel == null) {
+ jLabel = new JLabel();
+ jLabel.setText("Select language: "); // i8n!?! Maybe replace with an
+ // icon of an index finger
+ jPanel = new JPanel();
+ jPanel.add(jLabel);
+ jPanel.add(getJComboBox());
+ }
+ return jPanel;
+ }
+
+ /**
+ * This method initializes the Select Language Combobox
+ *
+ * @return javax.swing.JComboBox
+ */
+ private JComboBox getJComboBox() {
+ if (jComboBox == null) {
+ ArrayList<String> languagesPlusOne = new ArrayList<String>(
+ languages);
+ languagesPlusOne.add("?");
+
+ jComboBox = new LanguagesComboBox(languages);
+
+ SwingUtil.addMouseWheelForCombobox(jComboBox);
+ jComboBox.addActionListener(new ActionListener() {
+
+ public void actionPerformed(final ActionEvent e) {
+ if (jComboBox.getSelectedIndex() == languages.size()) {
+ getOkButton().setEnabled(false);
+ return;
+ }
+
+ String l = languages.get(jComboBox.getSelectedIndex());
+ try {
+ Translation.setActiveLang(l, setLocale);
+
+ getOkButton().setEnabled(true);
+ } catch (java.lang.IllegalArgumentException ee) {
+ LOGGER.warn("The language " + l + " is not valid", ee);
+ getOkButton().setEnabled(false);
+ }
+
+ }
+
+ });
+ }
+ return jComboBox;
+ }
+
+}
Property changes on: trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/SwitchLanguageDialog.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id URL
Name: svn:eol-style
+ native
Copied: trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/Translation.java (from rev 1423, trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/Translation.java)
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/Translation.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/Translation.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -0,0 +1,558 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+package de.schmitzm.i18n;
+
+import gtmig.org.geotools.util.WeakHashSet;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Random;
+import java.util.Set;
+import java.util.WeakHashMap;
+
+import javax.swing.JComponent;
+
+import org.apache.log4j.Logger;
+
+import de.schmitzm.data.Copyable;
+import de.schmitzm.lang.ResourceProvider;
+import de.schmitzm.lang.SortableVector;
+
+/**
+ * Represents a {@link HashMap} of translations. toString() returns the
+ * appropriate translation. This class is mutable.
+ *
+ * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
+ */
+
+public class Translation extends HashMap<String, String> implements
+ Copyable<Translation>, Serializable, Cloneable {
+
+ private static final long serialVersionUID = -347702744122305245L;
+
+ public static final String LOCALE_CHANGE_PROPERTY = "localechange";
+ public static final String ACTIVELANG_CHANGE_PROPERTY = "activelangchange";
+ public static final String NO_TRANSLATION = "NO TRANSLATION";
+ public static final String DEFAULT_KEY = "default";
+ static final Logger LOGGER = Logger.getLogger(Translation.class);
+
+ /** A static field defining which language should be served **/
+ static String activeLang = Locale.getDefault().getLanguage();
+
+ /**
+ * A {@link WeakHashSet} of {@link PropertyChangeListener} that will be
+ * informed if the acitveLang has been changed with a setActiveLang(..,true
+ * or false).
+ */
+ static protected WeakHashSet<PropertyChangeListener> listenersActiveLangChange = new WeakHashSet<PropertyChangeListener>(
+ PropertyChangeListener.class);
+
+ /**
+ * A {@link WeakHashSet} of {@link PropertyChangeListener} that will be
+ * informed if the Locale has been changed due to a setActiveLang(..,true)
+ */
+ static protected WeakHashSet<PropertyChangeListener> listenersLocaleChange = new WeakHashSet<PropertyChangeListener>(
+ PropertyChangeListener.class);
+
+ /**
+ * A {@link WeakHashSet} of {@link PropertyChangeListener} that will be
+ * informed if any of the translations changed. TODO: Should be registerable
+ * for specific languages
+ */
+ private final WeakHashSet<ActionListener> changeListeners = new WeakHashSet<ActionListener>(
+ ActionListener.class);
+
+ static {
+ // Get default locale
+ Locale locale = Locale.getDefault();
+ setActiveLang(locale.getLanguage());
+ }
+
+ @Override
+ /**
+ * implemented using #toOneLine and #fromOneLine
+ */
+ public Translation clone() {
+ Translation clone = new Translation();
+ clone.fromOneLine(toOneLine());
+ return clone;
+ }
+
+ /**
+ * Get the two-letter language sting that is active
+ */
+ public static String getActiveLang() {
+ return activeLang;
+ }
+
+ /**
+ * 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. The system's default {@link Locale} is
+ * changed.
+ *
+ * @param newLang
+ * The ISO Code of the new active language
+ */
+ public static void setActiveLang(String newLang) {
+ setActiveLang(newLang, true);
+ }
+
+ /**
+ * 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 setDefaultLocale
+ * Shall the system's default locale be changed?
+ */
+ public static void setActiveLang(String newLang, boolean setDefaultLocale) {
+ if (getActiveLang().equals(newLang)) {
+ return;
+ }
+
+ if (!I18NUtil.isValidISOLangCode(newLang)) {
+
+ if (!I18NUtil.isPropertiesLanguage(newLang)) {
+ throw new IllegalArgumentException(
+ "'"
+ + newLang
+ + "' is not a valid ISO language code, nor is it a valid userdefined Properties code.");
+ }
+
+ }
+
+ Translation.activeLang = newLang;
+ fireActiveLangChangeEvents();
+
+ Locale newLocale = new Locale(newLang);
+ if (setDefaultLocale) {
+
+ setDefaultLocale(newLocale);
+
+ LOGGER.info(Translation.class.getName()
+ + " switched ActiveLang and Locale to " + newLang);
+ } else {
+ LOGGER.info(Translation.class.getName()
+ + " switched ActiveLang to " + newLang);
+ }
+
+ }
+
+ /**
+ * Initializes a new {@link Translation} with a default translation if a
+ * simple text is passed. If a "oneLine" text is parsed, it is interpreted.
+ * Other translations may be added later - this is a HashMap<br/>
+ *
+ * @param defaultTranslation
+ *
+ * @see public Translation(List<String> languages, String
+ * defaultTranslation) {
+ *
+ */
+ public Translation(String defaultTranslation) {
+
+ fromOneLine(defaultTranslation);
+
+ }
+
+ /**
+ * 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. This class is not immutable.
+ *
+ * @param languages
+ * if empty or null, the given default {@link Translation} till
+ * be stored under a special key {@link #DEFAULT_KEY}
+ *
+ *
+ */
+ public Translation(List<String> languages, String defaultTranslation) {
+ if (languages == null || languages.isEmpty()) {
+ put(DEFAULT_KEY, defaultTranslation);
+ } else
+ for (String code : languages) {
+ put(code, defaultTranslation);
+ }
+ }
+
+ /**
+ * Sometimes Translations are optional, like for keywords.
+ */
+ public Translation() {
+ }
+
+ /**
+ * Fills the {@link Translation} with the values coded into the String
+ * 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
+ *
+ * @author Stefan Alfons Tzeggai
+ */
+ public void fromOneLine(final String oneLineCoded) {
+
+ clear();
+
+ try {
+
+ if ((oneLineCoded == null) || (oneLineCoded.equals(""))) {
+ put(DEFAULT_KEY, "");
+ return;
+ }
+
+ if (oneLineCoded.indexOf("}") == -1) {
+ // 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) {
+ 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);
+ }
+ } catch (Exception e) {
+ LOGGER.warn("Error while reading the oneLineCode '" + oneLineCoded
+ + "'", e);
+ LOGGER.warn("Translation will be empty!");
+ }
+ }
+
+ /**
+ * Exports the Translations to a String of the Format: "de{Baum}en{tree}"
+ *
+ * @author Stefan Alfons Tzeggai
+ */
+ public String toOneLine() {
+ return I18NUtil.toOneLine(this);
+ }
+
+ /**
+ * Returns the correct 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() {
+ final String string = get(activeLang);
+ if (string != null) {
+ return get(activeLang);
+ }
+ // ****************************************************************************
+ // MS: The ISDSS needs the concept of the default lang!! So I took the
+ // following in again!!
+ // ****************************************************************************
+ // else return "";
+ // //****************************************************************************
+ // // ST: The following is commented out.. the concept of the default
+ // lang
+ // seems to be bad....
+ // //****************************************************************************
+ // MS:
+ else {
+ if (get(DEFAULT_KEY) != null) {
+ return get(DEFAULT_KEY);
+ }
+
+ // log.debug("return first best <> '' ");
+ if (size() > 0)
+ for (String s : values()) {
+ if ((s != null) && (s.trim().length() > 0))
+ return s;
+ }
+ }
+ // log.warn("No translation found!");
+ return NO_TRANSLATION;
+ }
+
+ /**
+ * {@link PropertyChangeListener} can be registered to be informed when the
+ * {@link Locale} changed.<br>
+ * The listeners are kept in a {@link WeakHashMap}, so you have to keep a
+ * reference to the listener or it will be removed!
+ *
+ * @param propertyChangeListener
+ * A {@link PropertyChangeListener} that will be called when
+ * {@link #setActiveLang(String)} changes the language.
+ */
+ public static void addLocaleChangeListener(
+ PropertyChangeListener propertyChangeListener) {
+ listenersLocaleChange.add(propertyChangeListener);
+ }
+
+ /**
+ * {@link PropertyChangeListener} can be registered to be informed when the
+ * {@link Locale} changed.<br>
+ * The listeners are kept in a {@link WeakHashMap}, so you have to keep a
+ * reference to the listener or it will be removed!
+ *
+ * @param propertyChangeListener
+ * A {@link PropertyChangeListener} that will be called when
+ * {@link #setActiveLang(String)} changes the language.
+ */
+ public static boolean removeLocaleChangeListener(
+ PropertyChangeListener propertyChangeListener) {
+ return listenersLocaleChange.remove(propertyChangeListener);
+ }
+
+ /**
+ * {@link PropertyChangeListener} can be registered to be informed when the
+ * {@link Locale} changed.<br>
+ * The listeners are kept in a {@link WeakHashMap}, so you have to keep a
+ * reference to the listener or it will be removed!
+ *
+ * @param propertyChangeListener
+ * A {@link PropertyChangeListener} that will be called when
+ * {@link #setActiveLang(String)} changes the language.
+ */
+ public static void addActiveLangChangeListener(
+ PropertyChangeListener propertyChangeListener) {
+ listenersActiveLangChange.add(propertyChangeListener);
+ }
+
+ /**
+ * {@link PropertyChangeListener} can be registered to be informed when the
+ * {@link Locale} changed.<br>
+ * The listeners are kept in a {@link WeakHashMap}, so you have to keep a
+ * reference to the listener or it will be removed!
+ *
+ * @param propertyChangeListener
+ * A {@link PropertyChangeListener} that will be called when
+ * {@link #setActiveLang(String)} changes the language.
+ */
+ public static boolean removeActiveLangListener(
+ PropertyChangeListener propertyChangeListener) {
+ return listenersActiveLangChange.remove(propertyChangeListener);
+ }
+
+ /**
+ * Informs all registered {@link PropertyChangeListener}s about a change of
+ * type LOCALE_CHANGE_PROPERTY the the {@link Locale}.
+ */
+ public static void fireLocaleChangeEvents() {
+ PropertyChangeEvent pce = new PropertyChangeEvent(new Translation(
+ new ArrayList<String>(), "fakeSource"), LOCALE_CHANGE_PROPERTY,
+ null, getActiveLang());
+ for (PropertyChangeListener pcl : listenersLocaleChange) {
+ if (pcl != null)
+ pcl.propertyChange(pce);
+ }
+ }
+
+ /**
+ * Informs all registered {@link PropertyChangeListener}s about a change of
+ * type ACTIVELANG_CHANGE_PROPERTY the the {@link Locale}.
+ */
+ public static void fireActiveLangChangeEvents() {
+ PropertyChangeEvent pce = new PropertyChangeEvent(new Translation(
+ new ArrayList<String>(), "fakeSource"),
+ ACTIVELANG_CHANGE_PROPERTY, null, getActiveLang());
+ for (PropertyChangeListener pcl : listenersActiveLangChange) {
+ if (pcl != null)
+ pcl.propertyChange(pce);
+ }
+ }
+
+ /**
+ * The listeneras are stored in a {@link WeakHashSet}! So you HAVE TO KEEP a
+ * reference as long as you need the listener.
+ */
+ public void addTranslationChangeListener(ActionListener actionListener) {
+ if (changeListeners.add(actionListener)) {
+ // LOGGER
+ // .debug("registering a new translationChangeActionListener in the WeakHashSet");
+ }
+ }
+
+ /**
+ * The listeneras are stored in a {@link WeakHashSet}! You don't have to
+ * remove the listener, as long as you throw away the reference to the
+ * listener.
+ */
+ public boolean removeTranslationChangeListener(ActionListener actionListener) {
+ return changeListeners.remove(actionListener);
+ }
+
+ public void fireTranslationChangedEvents(String lang) {
+ ActionEvent ae = new ActionEvent(this, new Random().nextInt(), lang);
+
+ final Iterator<ActionListener> iterator = changeListeners.iterator();
+ while (iterator.hasNext()) {
+ ActionListener al = iterator.next();
+ al.actionPerformed(ae);
+ }
+ }
+
+ @Override
+ public String put(String lang, String value) {
+ String result = super.put(lang, value);
+ fireTranslationChangedEvents(lang);
+ return result;
+ }
+//
+// public void fromOneLine(InternationalString iString) {
+// if (iString != null)
+// fromOneLine(iString.toString());
+// else
+// fromOneLine((String) null);
+// }
+
+ /**
+ * Copy this {@link Translation} to another {@link Translation} e.g. for
+ * editing and return the target.
+ *
+ * @return the destination {@link Translation}
+ */
+ @Override
+ public Translation copyTo(Translation translation2) {
+ if (translation2 == null)
+ return copy();
+
+ translation2.fromOneLine(toOneLine());
+ return translation2;
+ }
+
+ @Override
+ public Translation copy() {
+ return copyTo(new Translation());
+ }
+
+ /**
+ * Checks if the {@link String}s stored in the {@link Translation} are all
+ * valid.
+ *
+ * @return <code>true</code> if all good
+ */
+ public static boolean checkValid(Translation translationToCheck) {
+
+ for (String l : translationToCheck.values()) {
+
+ if (l.contains("{") || l.contains("}")) {
+
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Goes through the available languages of the FIRST registered
+ * {@link ResourceProvider} and set the active locale to the fist match.
+ *
+ * @param fireChangeEvent
+ * if <code>true</code>, a Translation.fireLocaleChangeEvents()
+ * is issued.
+ *
+ * @return
+ */
+ public static boolean setFirstmatchingLanguage(List<String> languages,
+ boolean fireChangeEvent) {
+
+ SortableVector<ResourceProvider> registeredResourceProvider = ResourceProvider
+ .getRegisteredResourceProvider();
+ Set<Locale> available = ResourceProvider.getAvailableLocales(
+ registeredResourceProvider.get(0), true);
+
+ for (String l : languages) {
+ for (Locale loc : available) {
+ if (loc.getLanguage().equals(l)) {
+ Translation.setActiveLang(l);
+ if (fireChangeEvent)
+ Translation.fireLocaleChangeEvents();
+ return true;
+ }
+ }
+ }
+
+ return false;
+
+ }
+
+ /**
+ * Returns the translation in a requested language
+ */
+ public String toString(String lang) {
+ return get(lang);
+ }
+
+ /**
+ * Will set the default Locale (if not already equal) and fire Locale change
+ * events.
+ *
+ * @param if <code>null</code> will do nothing.
+ */
+ public static void setDefaultLocale(Locale locale) {
+
+ if (locale == null)
+ return;
+
+ if (I18NUtil.isPropertiesLanguage(locale.getLanguage())) {
+ locale = I18NUtil.propLocales.get(locale.getLanguage())
+ .getParentLocale();
+ }
+
+ if (Locale.getDefault().equals(locale))
+ return;
+ Locale.setDefault(locale);
+ /**
+ * Setting default locale for Swing JComponents to work around bug
+ * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4884480
+ */
+ JComponent.setDefaultLocale(locale);
+
+ fireLocaleChangeEvents();
+ }
+
+}
Property changes on: trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/Translation.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id URL
Name: svn:eol-style
+ native
Copied: trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/Utf8ResourceBundle.java (from rev 1423, trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/Utf8ResourceBundle.java)
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/Utf8ResourceBundle.java 2011-01-27 11:35:23 UTC (rev 1423)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/Utf8ResourceBundle.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -0,0 +1,115 @@
+// Stefan meint, das war ein Hack und wird nicht mehr benötigt.
+// package de.schmitzm.i18n;
+//
+//import java.io.UnsupportedEncodingException;
+//import java.util.Enumeration;
+//import java.util.Locale;
+//import java.util.PropertyResourceBundle;
+//import java.util.ResourceBundle;
+//
+///**
+// * Credits to http://www.thoughtsabout.net/blog/archives/000044.html
+// *
+// * May 02, 2005 Quick and Dirty Hack for UTF-8 Support in ResourceBundle
+// *
+// * I just don't get why Sun folks didn't fix this in J2SE 1.5. By specification,
+// * PropertyResourceBundles, or more exactly, the Properties files are Latin-1
+// * (i.e. ISO 8859-1) encoded:"When saving properties to a stream or loading them from a stream, the ISO 8859-1 character encoding is used. For characters that cannot be directly represented in this encoding, Unicode escapes are used; however, only a single 'u' character is allowed in an escape sequence. The native2ascii tool can be used to convert property files to and from other character encodings. "
+// * . However, since all Latin-1 characters are in the same position in UTF-8
+// * encoding, I don't see a reason why they couldn't have just added support for
+// * UTF-8 into the Properties class.
+// *
+// * While PropertyResourceBundle only has an implicit reference to the Properties
+// * class, the problem is an overall bad design of ResourceBundle class
+// * hierarchy. The super class ResourceBundle has two responsibilities: it acts
+// * both as a super class and as a factory for loading ResourceBundles. The
+// * ResourceBundle handles loading of PropertyResourceBundles that inherit from
+// * ResourceBundle, and you can already smell a problem with this suspicous
+// * implementation. Generally, the superclass should never need to know anything
+// * about child classes implementing it. The getBundle() methods in it are
+// * defined as final so there's no way to replace the the default implementation
+// * of PropertyResourceBundle. Sun has two answer to this problem: either use
+// * native2ascii tool to encode all double-byte characters in your Properties
+// * file or implement your own ResourceBundle class.
+// *
+// * Using native2ascii by hooking it up with your Ant build as a task is fine,
+// * but when you are developing and adding UTF-8 strings into your Properties
+// * file, it's just an extra burden to run native2ascii after every change. On
+// * Sun's forums, Craig McClanahan discusses how you could use your own
+// * ResourceBundle class instead of Properties files to resolve the encoding
+// * problem. But the issue with custom ResourceBundle classes is that they are
+// * inherently different from PropertiesResourceBundle; you would need a custom
+// * class per each locale you are supporting. Since ResourceBundle class handles
+// * loading of the PropertyResourceBundles and the methods are marked final, you
+// * are stuck with the Latin-1 encoding if you want to use Property files.
+// *
+// * The whole problem is stupid. Properties files should have supported UTF-8 in
+// * the first place, but the change to support them could have been made at any
+// * time after. Assuming UTF-8 as encoding when reading Latin-1 encoded file
+// * wouldn't have broken anything: this backwards compatibility is the basic
+// * reason why UTF-8 is so popular. All is not lost though; you could just use
+// * your own ResourceBundle factory class for loading ResourceBundles and then
+// * implement a UTF-8 PropertyResourceBundle class wrapper for UTF-8 support.
+// * Here's a quick and dirty hack to do just that:
+// */
+//public abstract class Utf8ResourceBundle {
+//
+// public static final ResourceBundle getBundle(String baseName) {
+// ResourceBundle bundle = ResourceBundle.getBundle(baseName);
+// return createUtf8PropertyResourceBundle(bundle);
+// }
+//
+// public static final ResourceBundle getBundle(String baseName, Locale locale) {
+// ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale);
+// return createUtf8PropertyResourceBundle(bundle);
+// }
+//
+// public static ResourceBundle getBundle(String baseName, Locale locale,
+// ClassLoader loader) {
+// ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale);
+// return createUtf8PropertyResourceBundle(bundle);
+// }
+//
+// private static ResourceBundle createUtf8PropertyResourceBundle(
+// ResourceBundle bundle) {
+// if (!(bundle instanceof PropertyResourceBundle))
+// return bundle;
+//
+// return new Utf8PropertyResourceBundle((PropertyResourceBundle) bundle);
+// }
+//
+// private static class Utf8PropertyResourceBundle extends ResourceBundle {
+// PropertyResourceBundle bundle;
+//
+// private Utf8PropertyResourceBundle(PropertyResourceBundle bundle) {
+// this.bundle = bundle;
+// }
+//
+// /*
+// * (non-Javadoc)
+// *
+// * @see java.util.ResourceBundle#getKeys()
+// */
+// public Enumeration getKeys() {
+// return bundle.getKeys();
+// }
+//
+// /*
+// * (non-Javadoc)
+// *
+// * @see java.util.ResourceBundle#handleGetObject(java.lang.String)
+// */
+// protected Object handleGetObject(String key) {
+// String value = (String) bundle.handleGetObject(key);
+// if (value == null)
+// return null;
+// try {
+// return new String(value.getBytes("ISO-8859-1"), "UTF-8");
+// } catch (UnsupportedEncodingException e) {
+// // Shouldn't fail - but should we still add logging message?
+// return null;
+// }
+// }
+//
+// }
+//}
\ No newline at end of file
Property changes on: trunk/schmitzm-core/src/main/java/de/schmitzm/i18n/Utf8ResourceBundle.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id URL
Name: svn:eol-style
+ native
Deleted: trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/I8NUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/I8NUtil.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/I8NUtil.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -1,287 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- *
- * This file is part of the SCHMITZM library - a collection of utility
- * classes based on Java 1.6, focusing (not only) on Java Swing
- * and the Geotools library.
- *
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- *
- * Contributors:
- * Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Tzeggai - additional utility classes
- ******************************************************************************/
-package de.schmitzm.i8n;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Set;
-import java.util.TreeSet;
-
-import org.apache.log4j.Logger;
-
-public class I8NUtil {
- static final Logger LOGGER = Logger.getLogger(I8NUtil.class);
-
- public static final HashMap<String, PropertiesLocale> propLocales = new HashMap<String, PropertiesLocale>();
-
- private static Set<String> languageCodes = new TreeSet<String>();
- static {
- for (final Locale locale : java.util.Locale.getAvailableLocales()) {
- languageCodes.add(locale.getLanguage());
- }
- for (String code : java.util.Locale.getISOLanguages()) {
- languageCodes.add(code);
- }
- for (String lang : getPropertiesLanguages()) {
- languageCodes.add(lang);
- }
- }
-
- /**
- * Creates a {@link Translation}<br/>
- * <p>
- * <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 Tzeggai
- */
- public static Translation createFromOneLine(final String oneLineCoded) {
- final Translation result = new Translation();
- result.fromOneLine(oneLineCoded);
- return result;
- }
-
- /**
- * A list of Locales defined in a <code>locales.properties</code> File on
- * the classpath.
- */
- static Set<String> getPropertiesLanguages() {
-
- // TODO read these definitions from a text file
- // URL resource = I8NUtil.class.getResource("/gplocales.properties");
-
- Locale oshikwanya = new Locale("ok", "na");
- PropertiesLocale plo1 = new PropertiesLocale(oshikwanya, new Locale(
- "kj", "na"), "Oshikwanya");
- propLocales.put(plo1.getLanguage(), plo1);
-
- Locale oshindonga = new Locale("od", "na");
- PropertiesLocale plo2 = new PropertiesLocale(oshindonga, new Locale(
- "kj", "na"), "Oshindonga");
- propLocales.put(plo2.getLanguage(), plo2);
-
- return propLocales.keySet();
- }
-
- /**
- * Returns the Translation to a String of the Format: "de{Baum}en{tree}" <br/>
- *
- *
- * @author Stefan Alfons Tzeggai
- */
- public static String toOneLine(final Translation source) {
- final StringBuffer oneLine = new StringBuffer();
- for (final String key : source.keySet()) {
- oneLine.append(key + "{" + source.get(key) + "}");
- }
- return oneLine.toString();
- }
-
- /**
- * @author Stefan Alfons Tzeggai
- * @param code
- * @return true if the code paramter is a valid ISO Language code
- */
- public static boolean isValidISOLangCode(final String code) {
- return Arrays.asList(java.util.Locale.getISOLanguages()).contains(code);
- }
-
- /**
- * @author Stefan Alfons Tzeggai
- * @param code
- * @return true if the code paramter is a valid ISO Language code
- */
- public static boolean isValidLangCode(final String code) {
- return getLanguageCodes().contains(code);
- }
-
- /**
- * @return All language codes available in
- * java.util.Locale.getISOLanguages() without duplicates.
- */
- public static Set<String> getLanguageCodes() {
- return languageCodes;
- }
-
- /**
- * Lookup {@link Locale} where they speak the 2 letter code language.
- *
- * @param code
- * A two-letter language code.
- * @return <code>null</code> or one (of many possible) {@link Locale} that
- * uses this language.
- */
- public static List<Locale> getLocalesForLang(final String code) {
-
- final ArrayList<Locale> locales = new ArrayList<Locale>();
-
- for (final Locale l : Locale.getAvailableLocales()) {
- if (l.getLanguage().equals(code.toLowerCase())) {
- locales.add(l);
- }
- }
-
- return locales;
- }
-
- /**
- * Lookup first country where they speak the 2 letter code language.
- *
- * @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 getFirstLocaleForLang(final String code) {
-
- List<Locale> locales = getLocalesForLang(code);
-
- if (locales.size() > 0)
- return locales.get(0);
-
- Locale l = new Locale(code);
- // LOGGER.error("Can't find Locale for code " + code
- // + "! Returning a selfmade locale");
- return l;
-
- // return Locale.getDefault();
- }
-
- /**
- * A convenience method that checks if the {@link Translation} object
- * contains a translation for the active language. A {@link String}
- * containing only spaces will return <code>false</code>.
- *
- * @param trans
- * {@link Translation} to check.
- */
- public static boolean isEmpty(final Translation trans) {
- if (trans == null)
- return true;
- return isEmpty(trans.toString());
- }
-
- /**
- * A convenience method that checks if the {@link String} returned by from a
- * {@link Translation} object contains a "valid" translation for the active
- * language. A {@link String} containing only spaces or equals
- * {@link Translation}.NO_TRANSLATION will return <code>false</code>.
- *
- * @param transString
- * {@link String} to check.
- */
- public static boolean isEmpty(final String transString) {
- if (transString == null)
- return true;
- if (transString.trim().isEmpty())
- return true;
- if (transString.equals(Translation.NO_TRANSLATION))
- return true;
- return false;
- }
-
- /**
- * @return a {@link Double} between 0 and 1 representing the part of the
- * given {@link Translation} that has been filled.
- * @param ac
- * {@link AtlasConfig} to determine the languages to expect.
- * @param trans
- * The {@link Translation} to check.
- */
- public static double qmTranslation(final List<String> languages,
- final Translation trans) {
-
- if (trans == null)
- return 0.;
-
- Integer cunt = 0;
- for (final String l : languages) {
- final String t = trans.get(l);
- if (!isEmpty(t))
- cunt++;
- }
- return cunt.doubleValue() / languages.size();
- }
-
- /**
- * The German Umlaute have standard ASCII alternatives that are sometimes
- * use. This method will replace any possible ASCII-Umlaut Representation
- * into real Umlaute. E.g. "ae" to "ä" and "ue" to "ü". Umlaute are returned
- * as inline-UTF8.
- */
- public static String mitUmlaute(final String withoutUmlaute) {
- String replaced = withoutUmlaute;
-
- replaced = replaced.replaceAll("ue", "\u00FC");
- replaced = replaced.replaceAll("Ue", "\u00DC");
-
- replaced = replaced.replaceAll("oe", "\u00F6");
- replaced = replaced.replaceAll("Oe", "\u00D6");
-
- replaced = replaced.replaceAll("ae", "\u00E4");
- replaced = replaced.replaceAll("Ae", "\u00C4");
- return replaced;
- }
-
- public static boolean isPropertiesLanguage(String langCode) {
- for (String lc : getPropertiesLanguages()) {
- if (lc.equals(langCode))
- return true;
- }
- return false;
- }
-
- /**
- * Returns a String that displays the denoted language in three ways, e.g.
- * "German / Deutsch / de" on a computer that has English as an active
- * Locale.
- */
- public static String getMultilanguageString(String langCode) {
- if (isValidISOLangCode(langCode)) {
- /**
- * Lookup a Locale where they speak the language, so we can print
- * the language in local tounge.
- */
- Locale locale = I8NUtil.getFirstLocaleForLang(langCode);
- return locale.getDisplayLanguage(locale) + " / "
- + locale.getDisplayLanguage() + " / " + langCode;
- } else if (isPropertiesLanguage(langCode)) {
- PropertiesLocale pl = I8NUtil.propLocales.get(langCode);
- return pl.getDisplayLanguage() + " / "
- + pl.getDisplayLanguage(langCode) + " " + langCode;
- }
-
- return langCode;
- }
-}
Deleted: trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/LanguagesComboBox.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/LanguagesComboBox.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/LanguagesComboBox.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -1,90 +0,0 @@
-package de.schmitzm.i8n;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Vector;
-
-import javax.swing.DefaultComboBoxModel;
-import javax.swing.JComboBox;
-
-/**
- * A JComboBox that shows the user a list of languages
- */
-public class LanguagesComboBox extends JComboBox {
-
- private final Vector<String> availLangs = new Vector<String>();
-
- public LanguagesComboBox() {
- super();
- }
-
- /**
- * Create a ComboBox with the given langauges as options
- */
- public LanguagesComboBox(Collection<String> langCodes) {
- this();
- updateModel(langCodes, null);
- }
-
- /**
- * Create a ComboBox with the given languages as options, excluding the
- * second parameter.
- *
- * @param langCodes
- * If <code>null</code>, {@link I8NUtil#getLanguageCodes()} will
- * be used
- */
- public LanguagesComboBox(Collection<String> langCodes,
- Collection<String> langCodesNotOffer) {
- this();
- updateModel(langCodes, langCodesNotOffer);
- }
-
- public void updateModel(Collection<String> langCodes,
- Collection<String> langCodesNotOffer) {
-
- if (langCodes == null) {
- langCodes = I8NUtil.getLanguageCodes();
- }
-
- if (langCodesNotOffer != null) {
- langCodes = new ArrayList<String>(langCodes);
- langCodes.removeAll(langCodesNotOffer);
- }
-
- availLangs.clear();
-
- for (String lc : langCodes) {
- //
- // if (I8NUtil.isValidISOLangCode(lc)) {
- // Locale locale = I8NUtil.getFirstLocaleForLang(lc);
- // availLangs.add(locale.getDisplayLanguage() + " / "
- // + locale.getDisplayLanguage(locale) + " " + lc);
- // } else if (I8NUtil.isPropertiesLanguage(lc)) {
- //
- // PropertiesLocale pl = I8NUtil.propLocales.get(lc);
- // availLangs.add(pl.getDisplayLanguage() + " / "
- // + pl.getDisplayLanguage(lc) + " " + lc);
- // }
-
- availLangs.add(I8NUtil.getMultilanguageString(lc));
- }
-
- Collections.sort(availLangs);
-
- setModel(new DefaultComboBoxModel(availLangs));
- setSelectedIndex(-1);
- repaint();
- }
-
- public String getSelectedLanguage() {
- if (getSelectedIndex() < 0)
- return null;
- String langDescription = availLangs.get(getSelectedIndex());
-
- return langDescription.substring(langDescription.lastIndexOf(" "))
- .trim();
- }
-
-}
Deleted: trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/PropertiesLocale.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/PropertiesLocale.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/PropertiesLocale.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -1,63 +0,0 @@
-package de.schmitzm.i8n;
-
-import java.util.HashMap;
-import java.util.Locale;
-
-/**
- */
-public class PropertiesLocale {
-
- /**
- * Language names => Translations
- */
- HashMap<String, String> displayLanguages = new HashMap<String, String>();
-
- private final Locale locale;
-
- private final String nativeName;
-
- private final Locale parentLocale;
-
- public PropertiesLocale(Locale locale, Locale parentLocale,
- String nativeName) {
- if (I8NUtil.isValidISOLangCode(locale.getLanguage()))
- throw new IllegalArgumentException(
- locale.getLanguage()
- + " can not be defined as a PropertiesLocale langauge, since it is an existing ISO language code.");
-
- this.parentLocale = parentLocale;
- this.locale = locale;
- this.nativeName = nativeName;
- }
-
- public String getDisplayLanguage(String langCode) {
- if (langCode == null || displayLanguages.containsKey(langCode))
- return displayLanguages.get(langCode);
- else
- return nativeName;
- }
-
- public String getDisplayLanguage() {
- return getDisplayLanguage(Locale.getDefault().getLanguage());
- }
-
- public void setDisplayLanguages(String langCode, String languageName) {
- displayLanguages.put(langCode, languageName);
- }
-
- public String getLanguage() {
- return locale.getLanguage();
- }
-
- public String getCountry() {
- return locale.getCountry();
- }
-
- public String getDisplayCountry() {
- return locale.getDisplayCountry();
- }
-
- public Locale getParentLocale() {
- return parentLocale;
- }
-}
Deleted: trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/SwitchLanguageDialog.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/SwitchLanguageDialog.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/SwitchLanguageDialog.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -1,245 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- *
- * This file is part of the SCHMITZM library - a collection of utility
- * classes based on Java 1.6, focusing (not only) on Java Swing
- * and the Geotools library.
- *
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- *
- * Contributors:
- * Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Tzeggai - additional utility classes
- ******************************************************************************/
-package de.schmitzm.i8n;
-
-import java.awt.Component;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.swing.ImageIcon;
-import javax.swing.JComboBox;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-
-import net.miginfocom.swing.MigLayout;
-
-import org.apache.log4j.Logger;
-
-import de.schmitzm.swing.AtlasDialog;
-import de.schmitzm.swing.OkButton;
-import de.schmitzm.swing.SwingUtil;
-import de.schmitzm.swing.TranslationEditJPanel;
-
-/**
- * This dialog ask the user to select one of list of given languages. The dialog
- * is modal and not visible after construction.
- *
- * @author Stefan A. Tzeggai
- */
-public class SwitchLanguageDialog extends AtlasDialog {
- protected Logger LOGGER = Logger.getLogger(SwitchLanguageDialog.class);
-
- private JPanel jContentPane = null;
-
- private JLabel jLabelFlagimage = null;
-
- private JPanel jPanel = null;
-
- private JLabel jLabel = null;
-
- private OkButton jButton = null;
-
- private LanguagesComboBox jComboBox = null;
-
- private final List<String> languages;
-
- /**
- * if <code>true</code>, the default locale will also be changed during a
- * language selection
- **/
- protected boolean setLocale;
-
- /**
- * A dialog to select one of the available languages. If only one language
- * is available, select it directly. Creating this object automatically
- * makes it visible, unless there is only one language to choose from.. it
- * that case it disposes itself automatically.
- *
- * @param setLocale if <code>true</code>, the default locale will also be
- * changed during a language selection
- */
- public SwitchLanguageDialog(final Component owner,
- final List<String> languages, boolean setLocale) {
- super(owner);
- this.languages = languages;
- this.setLocale = setLocale;
-
- if (languages == null || languages.size() == 0) {
- // No language is available.
- return;
- }
-
- Translation.setActiveLang(languages.get(0), setLocale);
- if (languages.size() == 1) {
- // Only language one language is available. It has been selected
- // automatically.
- return;
- }
-
- initialize();
- }
-
- @Override
- /**
- * This modal dialog will not appear if there is <= one language to select from.
- */
- public void setVisible(boolean b) {
- if (b == true && (languages == null || languages.size() <= 1)) {
- return;
- }
- super.setVisible(b);
- }
-
- /**
- * This method initializes this
- *
- * @return void
- */
- private void initialize() {
- this.setContentPane(getJContentPane());
-
- pack();
-
- SwingUtil.centerFrameOnScreenRandom(this);
- setModal(true);
- }
-
- public boolean close() {
- // Only close by ESC and window-close if a valid selection is made
- if (jComboBox.getSelectedIndex() == languages.size()
- || jComboBox.getSelectedIndex() == -1)
- return false;
- else
- return super.close();
- }
-
- /**
- * This method initializes jContentPane
- *
- * @return javax.swing.JPanel
- */
- private JPanel getJContentPane() {
- if (jContentPane == null) {
- jLabelFlagimage = new JLabel(new ImageIcon(
- TranslationEditJPanel.class
- .getResource("resource/flags.jpg")));
- jContentPane = new JPanel();
- MigLayout migLayout = new MigLayout("wrap 1", "[center]", "[]0[]");
- jContentPane.setLayout(migLayout);
- jContentPane.add(jLabelFlagimage, "north");
- jContentPane.add(getLanguageCombobox());
- jContentPane.add(getOkButton(),
- "right, w 50!, gaptop 5, gapright 5, gapbottom 5");
- }
- return jContentPane;
- }
-
- /**
- * This method initializes the OkButton
- *
- * @return javax.swing.JButton
- */
- @Override
- protected OkButton getOkButton() {
- if (jButton == null) {
- jButton = new OkButton();
- jButton.setEnabled(false);
-
- jButton.addActionListener(new ActionListener() {
-
- public void actionPerformed(ActionEvent e) {
- dispose();
- }
-
- });
- }
- return jButton;
- }
-
- /**
- * This method initializes the JPanel that carries the select language
- * combobox
- *
- * @return javax.swing.JPanel
- */
- private JPanel getLanguageCombobox() {
- if (jPanel == null) {
- jLabel = new JLabel();
- jLabel.setText("Select language: "); // i8n!?! Maybe replace with an
- // icon of an index finger
- jPanel = new JPanel();
- jPanel.add(jLabel);
- jPanel.add(getJComboBox());
- }
- return jPanel;
- }
-
- /**
- * This method initializes the Select Language Combobox
- *
- * @return javax.swing.JComboBox
- */
- private JComboBox getJComboBox() {
- if (jComboBox == null) {
- ArrayList<String> languagesPlusOne = new ArrayList<String>(
- languages);
- languagesPlusOne.add("?");
-
- jComboBox = new LanguagesComboBox(languages);
-
- SwingUtil.addMouseWheelForCombobox(jComboBox);
- jComboBox.addActionListener(new ActionListener() {
-
- public void actionPerformed(final ActionEvent e) {
- if (jComboBox.getSelectedIndex() == languages.size()) {
- getOkButton().setEnabled(false);
- return;
- }
-
- String l = languages.get(jComboBox.getSelectedIndex());
- try {
- Translation.setActiveLang(l, setLocale);
-
- getOkButton().setEnabled(true);
- } catch (java.lang.IllegalArgumentException ee) {
- LOGGER.warn("The language " + l + " is not valid", ee);
- getOkButton().setEnabled(false);
- }
-
- }
-
- });
- }
- return jComboBox;
- }
-
-}
Deleted: trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/Translation.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/Translation.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/Translation.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -1,558 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Martin O. J. Schmitz.
- *
- * This file is part of the SCHMITZM library - a collection of utility
- * classes based on Java 1.6, focusing (not only) on Java Swing
- * and the Geotools library.
- *
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- *
- * Contributors:
- * Martin O. J. Schmitz - initial API and implementation
- * Stefan A. Tzeggai - additional utility classes
- ******************************************************************************/
-package de.schmitzm.i8n;
-
-import gtmig.org.geotools.util.WeakHashSet;
-
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Random;
-import java.util.Set;
-import java.util.WeakHashMap;
-
-import javax.swing.JComponent;
-
-import org.apache.log4j.Logger;
-
-import de.schmitzm.data.Copyable;
-import de.schmitzm.lang.ResourceProvider;
-import de.schmitzm.lang.SortableVector;
-
-/**
- * Represents a {@link HashMap} of translations. toString() returns the
- * appropriate translation. This class is mutable.
- *
- * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
- */
-
-public class Translation extends HashMap<String, String> implements
- Copyable<Translation>, Serializable, Cloneable {
-
- private static final long serialVersionUID = -347702744122305245L;
-
- public static final String LOCALE_CHANGE_PROPERTY = "localechange";
- public static final String ACTIVELANG_CHANGE_PROPERTY = "activelangchange";
- public static final String NO_TRANSLATION = "NO TRANSLATION";
- public static final String DEFAULT_KEY = "default";
- static final Logger LOGGER = Logger.getLogger(Translation.class);
-
- /** A static field defining which language should be served **/
- static String activeLang = Locale.getDefault().getLanguage();
-
- /**
- * A {@link WeakHashSet} of {@link PropertyChangeListener} that will be
- * informed if the acitveLang has been changed with a setActiveLang(..,true
- * or false).
- */
- static protected WeakHashSet<PropertyChangeListener> listenersActiveLangChange = new WeakHashSet<PropertyChangeListener>(
- PropertyChangeListener.class);
-
- /**
- * A {@link WeakHashSet} of {@link PropertyChangeListener} that will be
- * informed if the Locale has been changed due to a setActiveLang(..,true)
- */
- static protected WeakHashSet<PropertyChangeListener> listenersLocaleChange = new WeakHashSet<PropertyChangeListener>(
- PropertyChangeListener.class);
-
- /**
- * A {@link WeakHashSet} of {@link PropertyChangeListener} that will be
- * informed if any of the translations changed. TODO: Should be registerable
- * for specific languages
- */
- private final WeakHashSet<ActionListener> changeListeners = new WeakHashSet<ActionListener>(
- ActionListener.class);
-
- static {
- // Get default locale
- Locale locale = Locale.getDefault();
- setActiveLang(locale.getLanguage());
- }
-
- @Override
- /**
- * implemented using #toOneLine and #fromOneLine
- */
- public Translation clone() {
- Translation clone = new Translation();
- clone.fromOneLine(toOneLine());
- return clone;
- }
-
- /**
- * Get the two-letter language sting that is active
- */
- public static String getActiveLang() {
- return activeLang;
- }
-
- /**
- * 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. The system's default {@link Locale} is
- * changed.
- *
- * @param newLang
- * The ISO Code of the new active language
- */
- public static void setActiveLang(String newLang) {
- setActiveLang(newLang, true);
- }
-
- /**
- * 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 setDefaultLocale
- * Shall the system's default locale be changed?
- */
- public static void setActiveLang(String newLang, boolean setDefaultLocale) {
- if (getActiveLang().equals(newLang)) {
- return;
- }
-
- if (!I8NUtil.isValidISOLangCode(newLang)) {
-
- if (!I8NUtil.isPropertiesLanguage(newLang)) {
- throw new IllegalArgumentException(
- "'"
- + newLang
- + "' is not a valid ISO language code, nor is it a valid userdefined Properties code.");
- }
-
- }
-
- Translation.activeLang = newLang;
- fireActiveLangChangeEvents();
-
- Locale newLocale = new Locale(newLang);
- if (setDefaultLocale) {
-
- setDefaultLocale(newLocale);
-
- LOGGER.info(Translation.class.getName()
- + " switched ActiveLang and Locale to " + newLang);
- } else {
- LOGGER.info(Translation.class.getName()
- + " switched ActiveLang to " + newLang);
- }
-
- }
-
- /**
- * Initializes a new {@link Translation} with a default translation if a
- * simple text is passed. If a "oneLine" text is parsed, it is interpreted.
- * Other translations may be added later - this is a HashMap<br/>
- *
- * @param defaultTranslation
- *
- * @see public Translation(List<String> languages, String
- * defaultTranslation) {
- *
- */
- public Translation(String defaultTranslation) {
-
- fromOneLine(defaultTranslation);
-
- }
-
- /**
- * 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. This class is not immutable.
- *
- * @param languages
- * if empty or null, the given default {@link Translation} till
- * be stored under a special key {@link #DEFAULT_KEY}
- *
- *
- */
- public Translation(List<String> languages, String defaultTranslation) {
- if (languages == null || languages.isEmpty()) {
- put(DEFAULT_KEY, defaultTranslation);
- } else
- for (String code : languages) {
- put(code, defaultTranslation);
- }
- }
-
- /**
- * Sometimes Translations are optional, like for keywords.
- */
- public Translation() {
- }
-
- /**
- * Fills the {@link Translation} with the values coded into the String
- * 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
- *
- * @author Stefan Alfons Tzeggai
- */
- public void fromOneLine(final String oneLineCoded) {
-
- clear();
-
- try {
-
- if ((oneLineCoded == null) || (oneLineCoded.equals(""))) {
- put(DEFAULT_KEY, "");
- return;
- }
-
- if (oneLineCoded.indexOf("}") == -1) {
- // 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) {
- 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);
- }
- } catch (Exception e) {
- LOGGER.warn("Error while reading the oneLineCode '" + oneLineCoded
- + "'", e);
- LOGGER.warn("Translation will be empty!");
- }
- }
-
- /**
- * Exports the Translations to a String of the Format: "de{Baum}en{tree}"
- *
- * @author Stefan Alfons Tzeggai
- */
- public String toOneLine() {
- return I8NUtil.toOneLine(this);
- }
-
- /**
- * Returns the correct 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() {
- final String string = get(activeLang);
- if (string != null) {
- return get(activeLang);
- }
- // ****************************************************************************
- // MS: The ISDSS needs the concept of the default lang!! So I took the
- // following in again!!
- // ****************************************************************************
- // else return "";
- // //****************************************************************************
- // // ST: The following is commented out.. the concept of the default
- // lang
- // seems to be bad....
- // //****************************************************************************
- // MS:
- else {
- if (get(DEFAULT_KEY) != null) {
- return get(DEFAULT_KEY);
- }
-
- // log.debug("return first best <> '' ");
- if (size() > 0)
- for (String s : values()) {
- if ((s != null) && (s.trim().length() > 0))
- return s;
- }
- }
- // log.warn("No translation found!");
- return NO_TRANSLATION;
- }
-
- /**
- * {@link PropertyChangeListener} can be registered to be informed when the
- * {@link Locale} changed.<br>
- * The listeners are kept in a {@link WeakHashMap}, so you have to keep a
- * reference to the listener or it will be removed!
- *
- * @param propertyChangeListener
- * A {@link PropertyChangeListener} that will be called when
- * {@link #setActiveLang(String)} changes the language.
- */
- public static void addLocaleChangeListener(
- PropertyChangeListener propertyChangeListener) {
- listenersLocaleChange.add(propertyChangeListener);
- }
-
- /**
- * {@link PropertyChangeListener} can be registered to be informed when the
- * {@link Locale} changed.<br>
- * The listeners are kept in a {@link WeakHashMap}, so you have to keep a
- * reference to the listener or it will be removed!
- *
- * @param propertyChangeListener
- * A {@link PropertyChangeListener} that will be called when
- * {@link #setActiveLang(String)} changes the language.
- */
- public static boolean removeLocaleChangeListener(
- PropertyChangeListener propertyChangeListener) {
- return listenersLocaleChange.remove(propertyChangeListener);
- }
-
- /**
- * {@link PropertyChangeListener} can be registered to be informed when the
- * {@link Locale} changed.<br>
- * The listeners are kept in a {@link WeakHashMap}, so you have to keep a
- * reference to the listener or it will be removed!
- *
- * @param propertyChangeListener
- * A {@link PropertyChangeListener} that will be called when
- * {@link #setActiveLang(String)} changes the language.
- */
- public static void addActiveLangChangeListener(
- PropertyChangeListener propertyChangeListener) {
- listenersActiveLangChange.add(propertyChangeListener);
- }
-
- /**
- * {@link PropertyChangeListener} can be registered to be informed when the
- * {@link Locale} changed.<br>
- * The listeners are kept in a {@link WeakHashMap}, so you have to keep a
- * reference to the listener or it will be removed!
- *
- * @param propertyChangeListener
- * A {@link PropertyChangeListener} that will be called when
- * {@link #setActiveLang(String)} changes the language.
- */
- public static boolean removeActiveLangListener(
- PropertyChangeListener propertyChangeListener) {
- return listenersActiveLangChange.remove(propertyChangeListener);
- }
-
- /**
- * Informs all registered {@link PropertyChangeListener}s about a change of
- * type LOCALE_CHANGE_PROPERTY the the {@link Locale}.
- */
- public static void fireLocaleChangeEvents() {
- PropertyChangeEvent pce = new PropertyChangeEvent(new Translation(
- new ArrayList<String>(), "fakeSource"), LOCALE_CHANGE_PROPERTY,
- null, getActiveLang());
- for (PropertyChangeListener pcl : listenersLocaleChange) {
- if (pcl != null)
- pcl.propertyChange(pce);
- }
- }
-
- /**
- * Informs all registered {@link PropertyChangeListener}s about a change of
- * type ACTIVELANG_CHANGE_PROPERTY the the {@link Locale}.
- */
- public static void fireActiveLangChangeEvents() {
- PropertyChangeEvent pce = new PropertyChangeEvent(new Translation(
- new ArrayList<String>(), "fakeSource"),
- ACTIVELANG_CHANGE_PROPERTY, null, getActiveLang());
- for (PropertyChangeListener pcl : listenersActiveLangChange) {
- if (pcl != null)
- pcl.propertyChange(pce);
- }
- }
-
- /**
- * The listeneras are stored in a {@link WeakHashSet}! So you HAVE TO KEEP a
- * reference as long as you need the listener.
- */
- public void addTranslationChangeListener(ActionListener actionListener) {
- if (changeListeners.add(actionListener)) {
- // LOGGER
- // .debug("registering a new translationChangeActionListener in the WeakHashSet");
- }
- }
-
- /**
- * The listeneras are stored in a {@link WeakHashSet}! You don't have to
- * remove the listener, as long as you throw away the reference to the
- * listener.
- */
- public boolean removeTranslationChangeListener(ActionListener actionListener) {
- return changeListeners.remove(actionListener);
- }
-
- public void fireTranslationChangedEvents(String lang) {
- ActionEvent ae = new ActionEvent(this, new Random().nextInt(), lang);
-
- final Iterator<ActionListener> iterator = changeListeners.iterator();
- while (iterator.hasNext()) {
- ActionListener al = iterator.next();
- al.actionPerformed(ae);
- }
- }
-
- @Override
- public String put(String lang, String value) {
- String result = super.put(lang, value);
- fireTranslationChangedEvents(lang);
- return result;
- }
-//
-// public void fromOneLine(InternationalString iString) {
-// if (iString != null)
-// fromOneLine(iString.toString());
-// else
-// fromOneLine((String) null);
-// }
-
- /**
- * Copy this {@link Translation} to another {@link Translation} e.g. for
- * editing and return the target.
- *
- * @return the destination {@link Translation}
- */
- @Override
- public Translation copyTo(Translation translation2) {
- if (translation2 == null)
- return copy();
-
- translation2.fromOneLine(toOneLine());
- return translation2;
- }
-
- @Override
- public Translation copy() {
- return copyTo(new Translation());
- }
-
- /**
- * Checks if the {@link String}s stored in the {@link Translation} are all
- * valid.
- *
- * @return <code>true</code> if all good
- */
- public static boolean checkValid(Translation translationToCheck) {
-
- for (String l : translationToCheck.values()) {
-
- if (l.contains("{") || l.contains("}")) {
-
- return false;
- }
- }
- return true;
- }
-
- /**
- * Goes through the available languages of the FIRST registered
- * {@link ResourceProvider} and set the active locale to the fist match.
- *
- * @param fireChangeEvent
- * if <code>true</code>, a Translation.fireLocaleChangeEvents()
- * is issued.
- *
- * @return
- */
- public static boolean setFirstmatchingLanguage(List<String> languages,
- boolean fireChangeEvent) {
-
- SortableVector<ResourceProvider> registeredResourceProvider = ResourceProvider
- .getRegisteredResourceProvider();
- Set<Locale> available = ResourceProvider.getAvailableLocales(
- registeredResourceProvider.get(0), true);
-
- for (String l : languages) {
- for (Locale loc : available) {
- if (loc.getLanguage().equals(l)) {
- Translation.setActiveLang(l);
- if (fireChangeEvent)
- Translation.fireLocaleChangeEvents();
- return true;
- }
- }
- }
-
- return false;
-
- }
-
- /**
- * Returns the translation in a requested language
- */
- public String toString(String lang) {
- return get(lang);
- }
-
- /**
- * Will set the default Locale (if not already equal) and fire Locale change
- * events.
- *
- * @param if <code>null</code> will do nothing.
- */
- public static void setDefaultLocale(Locale locale) {
-
- if (locale == null)
- return;
-
- if (I8NUtil.isPropertiesLanguage(locale.getLanguage())) {
- locale = I8NUtil.propLocales.get(locale.getLanguage())
- .getParentLocale();
- }
-
- if (Locale.getDefault().equals(locale))
- return;
- Locale.setDefault(locale);
- /**
- * Setting default locale for Swing JComponents to work around bug
- * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4884480
- */
- JComponent.setDefaultLocale(locale);
-
- fireLocaleChangeEvents();
- }
-
-}
Deleted: trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/TranslationTool.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/TranslationTool.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/TranslationTool.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -1,110 +0,0 @@
-package de.schmitzm.i8n;
-/*******************************************************************************
- * Copyright (c) 2010 Stefan A. Tzeggai.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the GNU Public License v2.0
- * which accompanies this distribution, and is available at
- * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
- *
- * Contributors:
- * Stefan A. Tzeggai - initial API and implementation
- ******************************************************************************/
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.util.HashMap;
-import java.util.Locale;
-
-import de.schmitzm.lang.ResourceProvider;
-
-
-/**
- * This tool helps to find missing french translations
- *
- */
-public class TranslationTool {
-
- static File GPenglish = new File ("/home/stefan/EigeneDateien/code/atlas/trunk/Atlas-Framework/bin/skrueger/creator/resource/locales/GeopublisherTranslation.properties");
- static File GPfrench = new File ("/home/stefan/EigeneDateien/code/atlas/trunk/Atlas-Framework/bin/skrueger/creator/resource/locales/GeopublisherTranslation_fr.properties");
-
- static File ASenglish = new File ("/home/stefan/EigeneDateien/code/atlas/trunk/Atlas-Framework/src/skrueger/sld/resources/locales/AtlasStylerTranslation.properties");
- static File ASfrench = new File ("/home/stefan/EigeneDateien/code/atlas/trunk/Atlas-Framework/src/skrueger/sld/resources/locales/AtlasStylerTranslation_fr.properties");
-
- static File AVenglish = new File ("/home/stefan/EigeneDateien/code/atlas/trunk/Atlas-Framework/src/skrueger/atlas/resource/locales/AtlasViewerTranslation.properties");
- static File AVfrench = new File ("/home/stefan/EigeneDateien/code/atlas/trunk/Atlas-Framework/src/skrueger/atlas/resource/locales/AtlasViewerTranslation_fr.properties");
-
- private static HashMap<String,String> frenchTranslations = new HashMap<String, String>();
-
- /**
- * @param args
- * @throws IOException
- * @throws URISyntaxException
- */
- public static void main(String[] args) throws IOException, URISyntaxException {
-
- Locale dl = Locale.getDefault();
-
- for (ResourceProvider p : ResourceProvider.getRegisteredResourceProvider()){
-
- for (Locale l : p.getAvailableLocales(false)) {
- File propertyFile = ResourceProvider.getPropertyFile(p, l, null);
- }
- }
-
-
- BufferedReader en_Reader;
- BufferedReader fr_Reader;
-
- int mode = 3;
-
- if (mode == 1) {
- en_Reader = new BufferedReader(new FileReader(GPenglish));
- fr_Reader = new BufferedReader(new FileReader(GPfrench));
- } else if (mode == 2) {
- en_Reader = new BufferedReader(new FileReader(ASenglish));
- fr_Reader = new BufferedReader(new FileReader(ASfrench));
- } else {
- en_Reader = new BufferedReader(new FileReader(AVenglish));
- fr_Reader = new BufferedReader(new FileReader(AVfrench));
- }
-
-
- // Read all french translations keys into a HashMap
- String readLine = "start";
- while (readLine != null) {
- readLine = fr_Reader.readLine();
- if (readLine != null && !readLine.startsWith("#")) {
- int indexOf = readLine.indexOf("=");
- if (indexOf == -1) continue;
- String key = readLine.substring(0,indexOf).trim();
- String value = readLine.substring(indexOf+1).trim();
- frenchTranslations .put(key.trim(),value.trim());
- }
- }
-
- System.out.println(frenchTranslations.size()+" french imported");
-
- readLine = "start";
- int missing =0;
- while (readLine != null) {
- readLine = en_Reader.readLine();
-
- if (readLine != null && !readLine.startsWith("#")) {
- int indexOf = readLine.indexOf("=");
- if (indexOf == -1) continue;
- String key = readLine.substring(0,indexOf).trim();
- String value = readLine.substring(indexOf+1).trim();
- if (!frenchTranslations.containsKey(key)) {
- System.out.println("#"+key+"="+value+"\n");
- missing++;
- }
- }
- }
- System.out.println("missing = "+missing);
- }
-
-
-
-}
Deleted: trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/Utf8ResourceBundle.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/Utf8ResourceBundle.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/i8n/Utf8ResourceBundle.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -1,114 +0,0 @@
-package de.schmitzm.i8n;
-
-import java.io.UnsupportedEncodingException;
-import java.util.Enumeration;
-import java.util.Locale;
-import java.util.PropertyResourceBundle;
-import java.util.ResourceBundle;
-
-/**
- * Credits to http://www.thoughtsabout.net/blog/archives/000044.html
- *
- * May 02, 2005 Quick and Dirty Hack for UTF-8 Support in ResourceBundle
- *
- * I just don't get why Sun folks didn't fix this in J2SE 1.5. By specification,
- * PropertyResourceBundles, or more exactly, the Properties files are Latin-1
- * (i.e. ISO 8859-1) encoded:"When saving properties to a stream or loading them from a stream, the ISO 8859-1 character encoding is used. For characters that cannot be directly represented in this encoding, Unicode escapes are used; however, only a single 'u' character is allowed in an escape sequence. The native2ascii tool can be used to convert property files to and from other character encodings. "
- * . However, since all Latin-1 characters are in the same position in UTF-8
- * encoding, I don't see a reason why they couldn't have just added support for
- * UTF-8 into the Properties class.
- *
- * While PropertyResourceBundle only has an implicit reference to the Properties
- * class, the problem is an overall bad design of ResourceBundle class
- * hierarchy. The super class ResourceBundle has two responsibilities: it acts
- * both as a super class and as a factory for loading ResourceBundles. The
- * ResourceBundle handles loading of PropertyResourceBundles that inherit from
- * ResourceBundle, and you can already smell a problem with this suspicous
- * implementation. Generally, the superclass should never need to know anything
- * about child classes implementing it. The getBundle() methods in it are
- * defined as final so there's no way to replace the the default implementation
- * of PropertyResourceBundle. Sun has two answer to this problem: either use
- * native2ascii tool to encode all double-byte characters in your Properties
- * file or implement your own ResourceBundle class.
- *
- * Using native2ascii by hooking it up with your Ant build as a task is fine,
- * but when you are developing and adding UTF-8 strings into your Properties
- * file, it's just an extra burden to run native2ascii after every change. On
- * Sun's forums, Craig McClanahan discusses how you could use your own
- * ResourceBundle class instead of Properties files to resolve the encoding
- * problem. But the issue with custom ResourceBundle classes is that they are
- * inherently different from PropertiesResourceBundle; you would need a custom
- * class per each locale you are supporting. Since ResourceBundle class handles
- * loading of the PropertyResourceBundles and the methods are marked final, you
- * are stuck with the Latin-1 encoding if you want to use Property files.
- *
- * The whole problem is stupid. Properties files should have supported UTF-8 in
- * the first place, but the change to support them could have been made at any
- * time after. Assuming UTF-8 as encoding when reading Latin-1 encoded file
- * wouldn't have broken anything: this backwards compatibility is the basic
- * reason why UTF-8 is so popular. All is not lost though; you could just use
- * your own ResourceBundle factory class for loading ResourceBundles and then
- * implement a UTF-8 PropertyResourceBundle class wrapper for UTF-8 support.
- * Here's a quick and dirty hack to do just that:
- */
-public abstract class Utf8ResourceBundle {
-
- public static final ResourceBundle getBundle(String baseName) {
- ResourceBundle bundle = ResourceBundle.getBundle(baseName);
- return createUtf8PropertyResourceBundle(bundle);
- }
-
- public static final ResourceBundle getBundle(String baseName, Locale locale) {
- ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale);
- return createUtf8PropertyResourceBundle(bundle);
- }
-
- public static ResourceBundle getBundle(String baseName, Locale locale,
- ClassLoader loader) {
- ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale);
- return createUtf8PropertyResourceBundle(bundle);
- }
-
- private static ResourceBundle createUtf8PropertyResourceBundle(
- ResourceBundle bundle) {
- if (!(bundle instanceof PropertyResourceBundle))
- return bundle;
-
- return new Utf8PropertyResourceBundle((PropertyResourceBundle) bundle);
- }
-
- private static class Utf8PropertyResourceBundle extends ResourceBundle {
- PropertyResourceBundle bundle;
-
- private Utf8PropertyResourceBundle(PropertyResourceBundle bundle) {
- this.bundle = bundle;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.ResourceBundle#getKeys()
- */
- public Enumeration getKeys() {
- return bundle.getKeys();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.util.ResourceBundle#handleGetObject(java.lang.String)
- */
- protected Object handleGetObject(String key) {
- String value = (String) bundle.handleGetObject(key);
- if (value == null)
- return null;
- try {
- return new String(value.getBytes("ISO-8859-1"), "UTF-8");
- } catch (UnsupportedEncodingException e) {
- // Shouldn't fail - but should we still add logging message?
- return null;
- }
- }
-
- }
-}
\ No newline at end of file
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/TranslationEditJPanel.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/TranslationEditJPanel.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/TranslationEditJPanel.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -46,7 +46,7 @@
import org.apache.log4j.Logger;
-import de.schmitzm.i8n.Translation;
+import de.schmitzm.i18n.Translation;
/**
* A {@link JPanel} that asks the user for the translations of a String in
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/TranslationJTextField.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/TranslationJTextField.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/TranslationJTextField.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -40,7 +40,7 @@
import org.apache.log4j.Logger;
-import de.schmitzm.i8n.Translation;
+import de.schmitzm.i18n.Translation;
/**
* A {@link JTextArea} that signals red when it is not filled by a value. A
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/TranslationsAskJPanel.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/TranslationsAskJPanel.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/TranslationsAskJPanel.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -5,7 +5,7 @@
import javax.swing.JOptionPane;
import net.miginfocom.swing.MigLayout;
-import de.schmitzm.i8n.Translation;
+import de.schmitzm.i18n.Translation;
public class TranslationsAskJPanel extends JPanel implements Cancellable, Checkable {
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/xml/XMLUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/xml/XMLUtil.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/xml/XMLUtil.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -47,7 +47,7 @@
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
-import de.schmitzm.i8n.Translation;
+import de.schmitzm.i18n.Translation;
import de.schmitzm.lang.LangUtil;
import de.schmitzm.swing.SwingUtil;
Added: trunk/schmitzm-core/src/test/java/de/schmitzm/i18n/I18NUtilTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/i18n/I18NUtilTest.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/i18n/I18NUtilTest.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -0,0 +1,108 @@
+package de.schmitzm.i18n;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import de.schmitzm.testing.TestingClass;
+
+public class I18NUtilTest extends TestingClass {
+
+ final static String oneLineCoded = "de{Baum}en{tree}";
+ final static List<String> langs4 = new ArrayList<String>();
+
+ @BeforeClass
+ public static void setup() {
+ langs4.add("de");
+ langs4.add("en");
+ langs4.add("xx");
+ langs4.add("yy");
+ }
+
+ @Test
+ public void testCreateFromOneLine() {
+ Translation t = I18NUtil.createFromOneLine(oneLineCoded);
+ assertEquals("Baum", t.toString("de"));
+ assertEquals("tree", t.toString("en"));
+ assertEquals(oneLineCoded, t.toOneLine());
+ }
+
+ @Test
+ public void testIsValidISOLangCode() {
+ assertTrue(I18NUtil.isValidISOLangCode("de"));
+ assertTrue(I18NUtil.isValidISOLangCode("ar"));
+ assertFalse(I18NUtil.isValidISOLangCode("äü"));
+ assertFalse(I18NUtil.isValidISOLangCode("ara"));
+ }
+
+ @Test
+ public void testMitUmlaute() {
+ assertEquals("öäü", I18NUtil.mitUmlaute("oeaeue"));
+ }
+
+ @Test
+ public void testQmTranslation() {
+ Translation t = I18NUtil.createFromOneLine(oneLineCoded);
+ assertEquals(0.5, I18NUtil.qmTranslation(langs4, t), .00000000001);
+ }
+
+ @Test
+ public void testGetLocalesForLang() {
+ List<Locale> locales = I18NUtil.getLocalesForLang("en");
+
+ assertTrue(locales.contains(new Locale("en", "za")));
+ assertTrue(locales.contains(new Locale("en", "sg")));
+ }
+
+ @Test
+ public void testGetLanguageCodes() {
+ Set<String> languageCodes = I18NUtil.getLanguageCodes();
+
+ assertTrue(languageCodes.contains("kj"));
+
+ assertTrue(languageCodes.contains("od"));
+ assertTrue(languageCodes.contains("ok"));
+
+ }
+
+ @Test
+ public void testGetFirstLocaleForLang() {
+ Locale tjLocaleSelfmade = I18NUtil.getFirstLocaleForLang("kj");
+ assertNotNull(tjLocaleSelfmade);
+ System.out.println(tjLocaleSelfmade);
+ }
+
+ @Test
+ public void testGetPropertiesLanguages() {
+ Set<String> propertiesLocales = I18NUtil.getPropertiesLanguages();
+ String o1 = propertiesLocales.iterator().next();
+
+ PropertiesLocale po1 = I18NUtil.propLocales.get(o1);
+
+ assertTrue(po1.getDisplayCountry().startsWith("Namibi"));
+ assertEquals("od", po1.getLanguage());
+ assertEquals("Oshindonga", po1.getDisplayLanguage());
+ assertEquals("Oshindonga",
+ po1.getDisplayLanguage(Locale.GERMAN.getLanguage()));
+ assertEquals("Oshindonga",
+ po1.getDisplayLanguage(Locale.ENGLISH.getLanguage()));
+
+ Translation t = new Translation();
+ t.put(po1.getLanguage(), "native");
+ t.put("en", "english");
+
+ Translation.setActiveLang("en");
+ assertEquals("english", t.toString());
+ Translation.setActiveLang(po1.getLanguage());
+ assertEquals("native", t.toString());
+ }
+}
Property changes on: trunk/schmitzm-core/src/test/java/de/schmitzm/i18n/I18NUtilTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id URL
Name: svn:eol-style
+ native
Added: trunk/schmitzm-core/src/test/java/de/schmitzm/i18n/SwitchLanguageDialogTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/i18n/SwitchLanguageDialogTest.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/i18n/SwitchLanguageDialogTest.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+package de.schmitzm.i18n;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+
+import org.junit.Test;
+
+import de.schmitzm.testing.TestingClass;
+import de.schmitzm.testing.TestingUtil;
+
+public class SwitchLanguageDialogTest extends TestingClass {
+
+ @Test
+ public void testDialog() throws Throwable {
+
+ if (!TestingUtil.isInteractive())
+ // Test needed here because following GUI creation would crash
+ // without X11 DISPLAY
+ return;
+
+ ArrayList<String> langs = new ArrayList<String>();
+ langs.add("tr");
+ langs.add("fr");
+ langs.add("kj");
+ TestingUtil.testGui(new SwitchLanguageDialog(null, langs, false), 20);
+ }
+
+ @Test
+ public void testDialogDoesntAppearIf0OrOneLangOnly() throws Throwable {
+ if (!TestingUtil.isInteractive())
+ // Test needed here because following GUI creation would crash
+ // without X11 DISPLAY
+ return;
+
+ ArrayList<String> langs = new ArrayList<String>();
+ langs.add("fr");
+
+ long startTime = System.currentTimeMillis();
+ TestingUtil.testGui(new SwitchLanguageDialog(null, langs, false), 2);
+ assertTrue("dialog did pop up incorrectly", System.currentTimeMillis()
+ - startTime < 1000);
+ }
+
+}
Property changes on: trunk/schmitzm-core/src/test/java/de/schmitzm/i18n/SwitchLanguageDialogTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id URL
Name: svn:eol-style
+ native
Added: trunk/schmitzm-core/src/test/java/de/schmitzm/i18n/TranslationTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/i18n/TranslationTest.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/i18n/TranslationTest.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -0,0 +1,142 @@
+package de.schmitzm.i18n;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import de.schmitzm.testing.TestingClass;
+public class TranslationTest extends TestingClass {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testCopyToAndEquals() {
+ Translation t = new Translation();
+ Translation t2 = new Translation();
+ t.put("de", "berg");
+ t.put("en", "mountain");
+ t.copyTo(t2);
+ assertEquals(t2.keySet(), t.keySet());
+ assertEquals(t2.toOneLine(), t.toOneLine());
+ assertEquals(t2, t);
+
+ assertEquals(t.copyTo(null), t);
+ }
+
+ @Test
+ public void testCopyAndClone() {
+ Translation t = new Translation();
+ t.put("de", "berg");
+ t.put("en", "mountain");
+ Translation t2 = t.copy();
+
+ assertEquals(t2, t);
+
+ Translation t3 = t2.clone();
+ assertEquals(t3, t);
+ }
+
+ @Test
+ public void testActiveLangChanges() {
+ Translation t = new Translation();
+ final AtomicBoolean calledAl = new AtomicBoolean(false);
+ final AtomicBoolean calledL = new AtomicBoolean(false);
+ final AtomicBoolean calledC = new AtomicBoolean(false);
+
+ PropertyChangeListener alListener = new PropertyChangeListener() {
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ calledAl.set(true);
+ }
+ };
+ Translation.addActiveLangChangeListener(alListener);
+
+ PropertyChangeListener localListener = new PropertyChangeListener() {
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ calledL.set(true);
+ }
+ };
+ Translation.addLocaleChangeListener(localListener);
+
+ ActionListener anyChangeListener = new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ calledC.set(true);
+ }
+ };
+ t.addTranslationChangeListener(anyChangeListener);
+
+ // Change the content
+ t.put("de", "change");
+ assertFalse(calledAl.get());
+ assertFalse(calledL.get());
+ assertTrue(calledC.get());
+
+ // Change active language by default
+ calledAl.set(false);
+ calledL.set(false);
+ calledC.set(false);
+ Translation.setActiveLang("de");
+ Translation.setActiveLang("en");
+
+ assertTrue(calledAl.get());
+ assertTrue(calledL.get());
+ assertFalse(calledC.get());
+
+ calledAl.set(false);
+ calledL.set(false);
+ Translation.setActiveLang("ar", false);
+ assertTrue(calledAl.get());
+ assertFalse(calledL.get());
+ assertFalse(calledC.get());
+
+ calledAl.set(false);
+ Translation.setActiveLang("ar", false);
+ assertFalse(
+ "if the same language is set again, it should not trigger events",
+ calledAl.get());
+ assertFalse(calledC.get());
+ }
+
+ @Test
+ public void testToString() {
+ Translation t = new Translation();
+ t.put("de", "de");
+ t.put("en", "en");
+ t.put("fr", "fr");
+ t.put("ru", "ru");
+
+ Translation.setActiveLang("de");
+ assertEquals("de", t.toString());
+ Translation.setActiveLang("ru");
+ assertEquals("ru", t.toString());
+ }
+
+ @Test
+ public void testFromOneLine() {
+ Translation t = new Translation();
+ t.fromOneLine("en{- 3 MBps/billion capita}");
+
+ assertEquals("- 3 MBps/billion capita", t.toString("en"));
+ }
+}
\ No newline at end of file
Property changes on: trunk/schmitzm-core/src/test/java/de/schmitzm/i18n/TranslationTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id URL
Name: svn:eol-style
+ native
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/MapContextManagerInterface.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/MapContextManagerInterface.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/MapContextManagerInterface.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -34,8 +34,8 @@
import org.geotools.map.MapLayer;
import org.geotools.map.event.MapLayerListListener;
+import de.schmitzm.geotools.data.amd.AttributeMetadataImpl;
import de.schmitzm.geotools.data.rld.RasterLegendData;
-import de.schmitzm.geotools.data.amd.AttributeMetadataImpl;
import de.schmitzm.geotools.styling.StyledFeatureCollectionInterface;
import de.schmitzm.geotools.styling.StyledLayerInterface;
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AbstractAttributeMetadata.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AbstractAttributeMetadata.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AbstractAttributeMetadata.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -6,7 +6,7 @@
import org.opengis.feature.type.Name;
import de.schmitzm.geotools.styling.StyledLayerUtil;
-import de.schmitzm.i8n.Translation;
+import de.schmitzm.i18n.Translation;
public abstract class AbstractAttributeMetadata implements AttributeMetadataInterface {
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetaDataAttributeTypeFilter.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetaDataAttributeTypeFilter.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetaDataAttributeTypeFilter.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -31,7 +31,6 @@
import org.opengis.feature.type.AttributeDescriptor;
-import de.schmitzm.geotools.data.amd.AttributeMetadataImplMap;
import de.schmitzm.geotools.feature.AttributeTypeFilter;
/**
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataImpl.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataImpl.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataImpl.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -40,8 +40,8 @@
import de.schmitzm.data.Copyable;
import de.schmitzm.geotools.data.QualityQuantizable;
import de.schmitzm.geotools.styling.StyledLayerInterface;
-import de.schmitzm.i8n.I8NUtil;
-import de.schmitzm.i8n.Translation;
+import de.schmitzm.i18n.I18NUtil;
+import de.schmitzm.i18n.Translation;
/**
* This class holds meta information about an attribute/column. This information
@@ -248,7 +248,7 @@
if (!isVisible())
return 1.;
- return (I8NUtil.qmTranslation(languages, getTitle()) * 2. + I8NUtil
+ return (I18NUtil.qmTranslation(languages, getTitle()) * 2. + I18NUtil
.qmTranslation(languages, getDesc()) * 1.) / 3.;
}
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataImplMap.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataImplMap.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataImplMap.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -5,8 +5,6 @@
import org.opengis.feature.type.Name;
import de.schmitzm.data.Copyable;
-import de.schmitzm.geotools.data.amd.AttributeMetadataImpl;
-import de.schmitzm.geotools.data.amd.AttributeMetadataMap;
public class AttributeMetadataImplMap extends AttributeMetadataMap<AttributeMetadataImpl> {
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataInterface.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataInterface.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataInterface.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -5,7 +5,7 @@
import org.opengis.feature.type.Name;
import de.schmitzm.data.Copyable;
-import de.schmitzm.i8n.Translation;
+import de.schmitzm.i18n.Translation;
public interface AttributeMetadataInterface extends Copyable<AttributeMetadataInterface>,
Comparable<AttributeMetadataInterface> {
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataMap.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataMap.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/amd/AttributeMetadataMap.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -13,7 +13,7 @@
import de.schmitzm.data.Copyable;
import de.schmitzm.geotools.data.QualityQuantizable;
-import de.schmitzm.i8n.Translation;
+import de.schmitzm.i18n.Translation;
/**
* The {@link AttributeMetadataMap} is a {@link Map} holding {@link AMD_IMPL}
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/rld/RasterLegendData.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/rld/RasterLegendData.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/data/rld/RasterLegendData.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -44,7 +44,7 @@
import de.schmitzm.data.Copyable;
import de.schmitzm.geotools.GTUtil;
import de.schmitzm.geotools.grid.GridUtil;
-import de.schmitzm.i8n.Translation;
+import de.schmitzm.i18n.Translation;
/**
* Holds all the additional information needed to paint a Legend for a
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/AtlasFeatureLayerFilterDialog.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/AtlasFeatureLayerFilterDialog.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/AtlasFeatureLayerFilterDialog.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -35,7 +35,7 @@
import de.schmitzm.geotools.feature.FeatureTypeTableModel;
import de.schmitzm.geotools.feature.FilterParser;
import de.schmitzm.geotools.styling.StyledFeaturesInterface;
-import de.schmitzm.i8n.I8NUtil;
+import de.schmitzm.i18n.I18NUtil;
import de.schmitzm.lang.LangUtil;
import de.schmitzm.swing.SwingUtil;
@@ -205,7 +205,7 @@
* description of the variable
*/
if (metaData == null
- || I8NUtil.isEmpty(metaData.getDesc()))
+ || I18NUtil.isEmpty(metaData.getDesc()))
return null;
return metaData.getDesc();
@@ -216,7 +216,7 @@
* the variable
*/
if (metaData == null
- || I8NUtil.isEmpty(metaData.getUnit()))
+ || I18NUtil.isEmpty(metaData.getUnit()))
return null;
return metaData.getUnit();
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/CrsLabel.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/CrsLabel.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/CrsLabel.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -2,9 +2,6 @@
import javax.swing.JLabel;
-import de.schmitzm.geotools.gui.GeotoolsGUIUtil;
-import de.schmitzm.geotools.gui.SelectableXMapPane;
-import de.schmitzm.geotools.gui.XMapPaneEvent;
import de.schmitzm.geotools.map.event.JMapPaneListener;
public class CrsLabel extends JLabel {
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/MapPaneStatusBar.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/MapPaneStatusBar.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/MapPaneStatusBar.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -35,7 +35,6 @@
import javax.swing.SwingConstants;
import net.miginfocom.swing.MigLayout;
-import de.schmitzm.geotools.gui.CrsLabel;
import de.schmitzm.swing.JPanel;
/**
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/MapPaneToolBar.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/MapPaneToolBar.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/MapPaneToolBar.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -53,10 +53,6 @@
import com.vividsolutions.jts.geom.Envelope;
-import de.schmitzm.geotools.gui.GeotoolsGUIUtil;
-import de.schmitzm.geotools.gui.SelectableXMapPane;
-import de.schmitzm.geotools.gui.XMapPaneEvent;
-import de.schmitzm.geotools.gui.XMapPaneTool;
import de.schmitzm.geotools.map.event.JMapPaneListener;
import de.schmitzm.geotools.map.event.MapAreaChangedEvent;
import de.schmitzm.swing.ButtonGroup;
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/MapView.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/MapView.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/MapView.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -41,10 +41,7 @@
import org.apache.log4j.Logger;
-import de.schmitzm.geotools.gui.GeoMapPane;
-import de.schmitzm.geotools.gui.MapContextControlPane;
-import de.schmitzm.geotools.gui.MapPaneStatusBar;
-import de.schmitzm.geotools.gui.SelectableXMapPane;
+import de.schmitzm.geotools.MapContextManagerInterface;
import de.schmitzm.geotools.styling.ColorMapManager;
/**
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/XMapPane.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/XMapPane.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/XMapPane.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -79,7 +79,7 @@
import de.schmitzm.geotools.map.event.JMapPaneListener;
import de.schmitzm.geotools.map.event.MapLayerAdapter;
import de.schmitzm.geotools.styling.StylingUtil;
-import de.schmitzm.i8n.Translation;
+import de.schmitzm.i18n.Translation;
import de.schmitzm.lang.LangUtil;
import de.schmitzm.swing.ExceptionDialog;
import de.schmitzm.swing.JPanel;
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/XMapPaneTool.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/XMapPaneTool.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/XMapPaneTool.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -11,7 +11,6 @@
import javax.swing.KeyStroke;
import de.schmitzm.data.Copyable;
-import de.schmitzm.geotools.gui.MapPaneToolBar;
import de.schmitzm.swing.SwingUtil;
import de.schmitzm.swing.event.MouseInputType;
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/AbstractStyledLayer.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/AbstractStyledLayer.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/AbstractStyledLayer.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -37,7 +37,7 @@
import com.vividsolutions.jts.geom.Envelope;
-import de.schmitzm.i8n.Translation;
+import de.schmitzm.i18n.Translation;
import de.schmitzm.lang.LangUtil;
/**
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFS.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFS.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFS.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -56,7 +56,7 @@
import de.schmitzm.geotools.feature.FeatureUtil;
import de.schmitzm.geotools.feature.FeatureUtil.GeometryForm;
import de.schmitzm.geotools.io.GeoImportUtil;
-import de.schmitzm.i8n.Translation;
+import de.schmitzm.i18n.Translation;
/**
* This class enables a non Atlas context to use the Atlas LayerPanel
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeatureCollection.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeatureCollection.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledFeatureCollection.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -47,12 +47,12 @@
import org.opengis.feature.type.AttributeDescriptor;
import org.opengis.filter.Filter;
+import de.schmitzm.geotools.data.amd.AttributeMetadataImpl;
import de.schmitzm.geotools.data.amd.AttributeMetadataImplMap;
-import de.schmitzm.geotools.data.amd.AttributeMetadataImpl;
import de.schmitzm.geotools.data.amd.AttributeMetadataMap;
import de.schmitzm.geotools.feature.FeatureUtil;
import de.schmitzm.geotools.feature.FeatureUtil.GeometryForm;
-import de.schmitzm.i8n.Translation;
+import de.schmitzm.i18n.Translation;
/**
* This class provides a simple implementation of {@link StyledLayerInterface}
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverage.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverage.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverage.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -40,7 +40,7 @@
import de.schmitzm.geotools.JTSUtil;
import de.schmitzm.geotools.data.rld.RasterLegendData;
import de.schmitzm.geotools.grid.GridUtil;
-import de.schmitzm.i8n.Translation;
+import de.schmitzm.i18n.Translation;
/**
* This class provides a simple implementation of {@link StyledLayerInterface}
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverageReader.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverageReader.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverageReader.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -41,7 +41,7 @@
import de.schmitzm.geotools.JTSUtil;
import de.schmitzm.geotools.data.rld.RasterLegendData;
import de.schmitzm.geotools.grid.GridUtil;
-import de.schmitzm.i8n.Translation;
+import de.schmitzm.i18n.Translation;
/**
* This class provides a simple implementation of {@link StyledLayerInterface}
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerInterface.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerInterface.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerInterface.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -41,10 +41,10 @@
import com.vividsolutions.jts.geom.Envelope;
import de.schmitzm.geotools.MapContextManagerInterface;
-import de.schmitzm.geotools.data.rld.RasterLegendData;
import de.schmitzm.geotools.data.amd.AttributeMetadataImpl;
import de.schmitzm.geotools.data.amd.AttributeMetadataInterface;
-import de.schmitzm.i8n.Translation;
+import de.schmitzm.geotools.data.rld.RasterLegendData;
+import de.schmitzm.i18n.Translation;
/**
* This class is the top interface for styled objects to be managed in
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerUtil.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerUtil.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerUtil.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -90,16 +90,16 @@
import com.vividsolutions.jts.geom.Geometry;
-import de.schmitzm.geotools.data.amd.AttributeMetadataImplMap;
import de.schmitzm.geotools.FilterUtil;
import de.schmitzm.geotools.JTSUtil;
import de.schmitzm.geotools.LegendIconFeatureRenderer;
-import de.schmitzm.geotools.data.rld.RasterLegendData;
import de.schmitzm.geotools.data.amd.AttributeMetadataImpl;
+import de.schmitzm.geotools.data.amd.AttributeMetadataImplMap;
import de.schmitzm.geotools.data.amd.AttributeMetadataInterface;
import de.schmitzm.geotools.data.amd.AttributeMetadataMap;
+import de.schmitzm.geotools.data.rld.RasterLegendData;
import de.schmitzm.geotools.feature.FeatureUtil;
-import de.schmitzm.i8n.Translation;
+import de.schmitzm.i18n.Translation;
import de.schmitzm.io.IOUtil;
import de.schmitzm.lang.LangUtil;
import de.schmitzm.swing.ExceptionDialog;
Modified: trunk/schmitzm-jfree/src/main/java/de/schmitzm/jfree/chart/style/ChartAxisStyle.java
===================================================================
--- trunk/schmitzm-jfree/src/main/java/de/schmitzm/jfree/chart/style/ChartAxisStyle.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-jfree/src/main/java/de/schmitzm/jfree/chart/style/ChartAxisStyle.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -41,7 +41,7 @@
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.NumberAxis;
-import de.schmitzm.i8n.Translation;
+import de.schmitzm.i18n.Translation;
import de.schmitzm.lang.LangUtil;
/**
Modified: trunk/schmitzm-jfree/src/main/java/de/schmitzm/jfree/chart/style/ChartLabelStyle.java
===================================================================
--- trunk/schmitzm-jfree/src/main/java/de/schmitzm/jfree/chart/style/ChartLabelStyle.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-jfree/src/main/java/de/schmitzm/jfree/chart/style/ChartLabelStyle.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -35,7 +35,7 @@
import org.apache.log4j.Category;
import de.schmitzm.data.Copyable;
-import de.schmitzm.i8n.Translation;
+import de.schmitzm.i18n.Translation;
import de.schmitzm.lang.LangUtil;
/**
Modified: trunk/schmitzm-jfree/src/main/java/de/schmitzm/jfree/table/style/TableChartAxisStyle.java
===================================================================
--- trunk/schmitzm-jfree/src/main/java/de/schmitzm/jfree/table/style/TableChartAxisStyle.java 2011-01-27 11:46:22 UTC (rev 1424)
+++ trunk/schmitzm-jfree/src/main/java/de/schmitzm/jfree/table/style/TableChartAxisStyle.java 2011-01-27 11:52:53 UTC (rev 1425)
@@ -34,7 +34,7 @@
import org.jfree.chart.axis.Axis;
-import de.schmitzm.i8n.Translation;
+import de.schmitzm.i18n.Translation;
import de.schmitzm.jfree.JFreeChartUtil;
import de.schmitzm.jfree.chart.style.ChartAxisStyle;
import de.schmitzm.lang.LangUtil;
More information about the Schmitzm-commits
mailing list