[Schmitzm-commits] r1150 - in trunk: src/skrueger/i8n src_junit/skrueger/i8n
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Oct 18 14:28:24 CEST 2010
Author: alfonx
Date: 2010-10-18 14:28:24 +0200 (Mon, 18 Oct 2010)
New Revision: 1150
Added:
trunk/src/skrueger/i8n/LanguagesComboBox.java
Modified:
trunk/src/skrueger/i8n/I8NUtil.java
trunk/src/skrueger/i8n/SwitchLanguageDialog.java
trunk/src_junit/skrueger/i8n/I8NUtilTest.java
trunk/src_junit/skrueger/i8n/SwitchLanguageDialogTest.java
Log:
* AtlasStyler multi-language will now offer a drop-down list for the languages.
* Increased the number of languagesoffered in GP from 44 to 150.
Modified: trunk/src/skrueger/i8n/I8NUtil.java
===================================================================
--- trunk/src/skrueger/i8n/I8NUtil.java 2010-10-18 09:21:46 UTC (rev 1149)
+++ trunk/src/skrueger/i8n/I8NUtil.java 2010-10-18 12:28:24 UTC (rev 1150)
@@ -43,11 +43,11 @@
private static Set<String> languageCodes = new TreeSet<String>();
static {
for (final Locale locale : java.util.Locale.getAvailableLocales()) {
- getLanguageCodes().add(locale.getLanguage());
+ languageCodes.add(locale.getLanguage());
}
- // for (String code : java.util.Locale.getISOLanguages()) {
- // getLanguageCodes().add(code);
- // }
+ for (String code : java.util.Locale.getISOLanguages()) {
+ languageCodes.add(code);
+ }
}
/**
@@ -132,10 +132,12 @@
if (locales.size() > 0)
return locales.get(0);
- LOGGER.error("Can't create a Locale for code " + code
- + "! Returning the system default locale to avoid NPEs.");
+ Locale l = new Locale(code);
+ LOGGER.error("Can't find Locale for code " + code
+ + "! Returning a selfmade locale");
+ return l;
- return Locale.getDefault();
+ // return Locale.getDefault();
}
/**
Added: trunk/src/skrueger/i8n/LanguagesComboBox.java
===================================================================
--- trunk/src/skrueger/i8n/LanguagesComboBox.java 2010-10-18 09:21:46 UTC (rev 1149)
+++ trunk/src/skrueger/i8n/LanguagesComboBox.java 2010-10-18 12:28:24 UTC (rev 1150)
@@ -0,0 +1,82 @@
+package skrueger.i8n;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Locale;
+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 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) {
+ Locale locale = I8NUtil.getFirstLocaleForLang(lc);
+
+ availLangs.add(locale.getDisplayLanguage() + " / "
+ + locale.getDisplayLanguage(locale) + " " + 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/src/skrueger/i8n/LanguagesComboBox.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id URL
Name: svn:eol-style
+ native
Modified: trunk/src/skrueger/i8n/SwitchLanguageDialog.java
===================================================================
--- trunk/src/skrueger/i8n/SwitchLanguageDialog.java 2010-10-18 09:21:46 UTC (rev 1149)
+++ trunk/src/skrueger/i8n/SwitchLanguageDialog.java 2010-10-18 12:28:24 UTC (rev 1150)
@@ -35,11 +35,9 @@
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.awt.event.MouseWheelListener;
+import java.util.ArrayList;
import java.util.List;
-import java.util.Locale;
-import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
@@ -74,7 +72,7 @@
private JLabel jLabel = null;
- private JComboBox jComboBox = null;
+ private LanguagesComboBox jComboBox = null;
private final List<String> languages;
@@ -142,7 +140,8 @@
public boolean close() {
// Only close by ESC and window-close if a valid selection is made
- if (jComboBox.getSelectedIndex() == languages.size())
+ if (jComboBox.getSelectedIndex() == languages.size()
+ || jComboBox.getSelectedIndex() == -1)
return false;
else
return super.close();
@@ -258,38 +257,13 @@
*/
private JComboBox getJComboBox() {
if (jComboBox == null) {
- jComboBox = new JComboBox();
+ ArrayList<String> languagesPlusOne = new ArrayList<String>(
+ languages);
+ languagesPlusOne.add("?");
- jComboBox.addMouseWheelListener(new MouseWheelListener() {
- public void mouseWheelMoved(java.awt.event.MouseWheelEvent e) {
+ jComboBox = new LanguagesComboBox(languages);
- if ((e.getWheelRotation() < 0)) {
- if (jComboBox.getSelectedIndex() < jComboBox
- .getItemCount() - 1)
- jComboBox.setSelectedIndex(jComboBox
- .getSelectedIndex() + 1);
- } else {
- if (jComboBox.getSelectedIndex() > 0)
- jComboBox.setSelectedIndex(jComboBox
- .getSelectedIndex() - 1);
- }
- }
- });
-
- String[] langNames = new String[languages.size() + 1];
- for (int i = 0; i < languages.size(); i++) {
-
- Locale locale = I8NUtil.getFirstLocaleForLang(languages.get(i));
-
- langNames[i] = locale.getDisplayLanguage(locale) + " / "
- + locale.getDisplayLanguage() + " / "
- + languages.get(i);
- }
- langNames[languages.size()] = "?";
-
- jComboBox.setModel(new DefaultComboBoxModel(langNames));
- jComboBox.setSelectedItem(langNames[languages.size()]);
-
+ SwingUtil.addMouseWheelForCombobox(jComboBox);
jComboBox.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
Modified: trunk/src_junit/skrueger/i8n/I8NUtilTest.java
===================================================================
--- trunk/src_junit/skrueger/i8n/I8NUtilTest.java 2010-10-18 09:21:46 UTC (rev 1149)
+++ trunk/src_junit/skrueger/i8n/I8NUtilTest.java 2010-10-18 12:28:24 UTC (rev 1150)
@@ -2,11 +2,13 @@
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;
@@ -59,4 +61,17 @@
assertTrue(locales.contains(new Locale("en", "sg")));
}
+ @Test
+ public void testGetLanguageCodes() {
+ Set<String> languageCodes = I8NUtil.getLanguageCodes();
+
+ assertTrue(languageCodes.contains("kj"));
+ }
+
+ @Test
+ public void testGetFirstLocaleForLang() {
+ Locale tjLocaleSelfmade = I8NUtil.getFirstLocaleForLang("kj");
+ assertNotNull(tjLocaleSelfmade);
+ System.out.println(tjLocaleSelfmade);
+ }
}
Modified: trunk/src_junit/skrueger/i8n/SwitchLanguageDialogTest.java
===================================================================
--- trunk/src_junit/skrueger/i8n/SwitchLanguageDialogTest.java 2010-10-18 09:21:46 UTC (rev 1149)
+++ trunk/src_junit/skrueger/i8n/SwitchLanguageDialogTest.java 2010-10-18 12:28:24 UTC (rev 1150)
@@ -48,9 +48,10 @@
return;
ArrayList<String> langs = new ArrayList<String>();
+ langs.add("tr");
langs.add("fr");
- langs.add("tr");
- TestingUtil.testGui(new SwitchLanguageDialog(null, langs, false), 10);
+ langs.add("kj");
+ TestingUtil.testGui(new SwitchLanguageDialog(null, langs, false), 20);
}
@Test
More information about the Schmitzm-commits
mailing list