From 74bc9593b3baa19b2dca892d7eafbf86e1c6eb4b Mon Sep 17 00:00:00 2001 From: "jason@long.name" Date: Tue, 21 May 2013 13:30:15 +0000 Subject: [PATCH] translation-tool: code for removing locale from tool git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@668 d9718cc8-9f43-0410-858b-315f434eb58c --- src/micropolisj/util/StringsModel.java | 24 ++++++++++ src/micropolisj/util/TranslationTool.java | 53 ++++++++++++++++++++++- 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/src/micropolisj/util/StringsModel.java b/src/micropolisj/util/StringsModel.java index 3000872..e935bc2 100644 --- a/src/micropolisj/util/StringsModel.java +++ b/src/micropolisj/util/StringsModel.java @@ -171,6 +171,30 @@ class StringsModel extends AbstractTableModel fireTableStructureChanged(); } + String [] getAllLocaleCodes() + { + String [] rv = new String[locales.size()]; + for (int i = 0; i < rv.length; i++) { + rv[i] = locales.get(i).code; + } + return rv; + } + + void removeLocale(String localeCode) + { + boolean found = false; + for (int i = locales.size()-1; i >= 0; i--) { + String loc = locales.get(i).code; + if (loc == localeCode || (loc != null && loc.equals(localeCode))) { + locales.remove(i); + found = true; + } + } + if (found) { + fireTableStructureChanged(); + } + } + void makeDirectories(File f) throws IOException { diff --git a/src/micropolisj/util/TranslationTool.java b/src/micropolisj/util/TranslationTool.java index ff35d03..b73e970 100644 --- a/src/micropolisj/util/TranslationTool.java +++ b/src/micropolisj/util/TranslationTool.java @@ -96,6 +96,19 @@ public class TranslationTool extends JFrame private void onTestClicked() { + String code = pickLocale( + "Which locale do you want to test?", + "Test Locale" + ); + if (code == null) { + return; + } + + String [] localeParts = code.split("_"); + lastLanguage = localeParts.length >= 1 ? localeParts[0] : ""; + lastCountry = localeParts.length >= 2 ? localeParts[1] : ""; + lastVariant = localeParts.length >= 3 ? localeParts[2] : ""; + try { String javaPath = "java"; @@ -195,9 +208,47 @@ public class TranslationTool extends JFrame } } + String pickLocale(String message, String dlgTitle) + { + String[] locales = stringsModel.getAllLocaleCodes(); + if (locales.length == 1) { + return locales[0]; + } + else if (locales.length == 0) { + return null; + } + + JComboBox localeCb = new JComboBox(); + for (int i = 0; i < locales.length; i++) { + localeCb.addItem(locales[i] != null ? locales[i] : "C"); + } + localeCb.setSelectedIndex(locales.length-1); + + JComponent [] inputs = new JComponent[] { + new JLabel(message), + localeCb + }; + int rv = JOptionPane.showOptionDialog(this, + inputs, + dlgTitle, + JOptionPane.OK_CANCEL_OPTION, + JOptionPane.PLAIN_MESSAGE, + null, null, null); + if (rv != JOptionPane.OK_OPTION) + return null; + + return (String) localeCb.getSelectedItem(); + } + private void onRemoveLocaleClicked() { - //TODO + String code = pickLocale( + "Which locale do you want to remove?", + "Remove Locale" + ); + if (code != null) { + stringsModel.removeLocale(code.equals("C") ? null : code); + } } private void onSubmitClicked()