translation-tool: do not allow removing/testing the "C" locale

git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@669 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
jason@long.name 2013-05-21 13:30:31 +00:00
parent 74bc9593b3
commit 5fddf1d8f1
2 changed files with 48 additions and 30 deletions

View file

@ -182,10 +182,12 @@ class StringsModel extends AbstractTableModel
void removeLocale(String localeCode) void removeLocale(String localeCode)
{ {
assert localeCode != null;
boolean found = false; boolean found = false;
for (int i = locales.size()-1; i >= 0; i--) { for (int i = locales.size()-1; i >= 0; i--) {
String loc = locales.get(i).code; String loc = locales.get(i).code;
if (loc == localeCode || (loc != null && loc.equals(localeCode))) { if (localeCode.equals(loc)) {
locales.remove(i); locales.remove(i);
found = true; found = true;
} }

View file

@ -11,9 +11,10 @@ public class TranslationTool extends JFrame
{ {
JTable stringsTable; JTable stringsTable;
StringsModel stringsModel; StringsModel stringsModel;
String lastLanguage;
String lastCountry; JButton removeBtn;
String lastVariant; JButton testBtn;
JButton submitBtn;
public TranslationTool() public TranslationTool()
{ {
@ -46,12 +47,12 @@ public class TranslationTool extends JFrame
}}); }});
buttonPane.add(btn); buttonPane.add(btn);
btn = new JButton("Remove Locale"); removeBtn = new JButton("Remove Locale");
btn.addActionListener(new ActionListener() { removeBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
onRemoveLocaleClicked(); onRemoveLocaleClicked();
}}); }});
buttonPane.add(btn); buttonPane.add(removeBtn);
btn = new JButton("Save"); btn = new JButton("Save");
btn.addActionListener(new ActionListener() { btn.addActionListener(new ActionListener() {
@ -60,19 +61,21 @@ public class TranslationTool extends JFrame
}}); }});
buttonPane.add(btn); buttonPane.add(btn);
btn = new JButton("Test"); testBtn = new JButton("Test");
btn.addActionListener(new ActionListener() { testBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
onTestClicked(); onTestClicked();
}}); }});
buttonPane.add(btn); buttonPane.add(testBtn);
btn = new JButton("Submit"); submitBtn = new JButton("Submit");
btn.addActionListener(new ActionListener() { submitBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
onSubmitClicked(); onSubmitClicked();
}}); }});
buttonPane.add(btn); buttonPane.add(submitBtn);
updateButtonsEnabled();
pack(); pack();
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
@ -105,9 +108,9 @@ public class TranslationTool extends JFrame
} }
String [] localeParts = code.split("_"); String [] localeParts = code.split("_");
lastLanguage = localeParts.length >= 1 ? localeParts[0] : ""; String selLanguage = localeParts.length >= 1 ? localeParts[0] : "";
lastCountry = localeParts.length >= 2 ? localeParts[1] : ""; String selCountry = localeParts.length >= 2 ? localeParts[1] : "";
lastVariant = localeParts.length >= 3 ? localeParts[2] : ""; String selVariant = localeParts.length >= 3 ? localeParts[2] : "";
try try
{ {
@ -118,9 +121,9 @@ public class TranslationTool extends JFrame
ProcessBuilder processBuilder = ProcessBuilder processBuilder =
new ProcessBuilder(javaPath, new ProcessBuilder(javaPath,
"-Duser.language="+lastLanguage, "-Duser.language="+selLanguage,
"-Duser.country="+lastCountry, "-Duser.country="+selCountry,
"-Duser.variant="+lastVariant, "-Duser.variant="+selVariant,
"-cp", "-cp",
classPath, classPath,
"micropolisj.Main" "micropolisj.Main"
@ -178,9 +181,9 @@ public class TranslationTool extends JFrame
try try
{ {
lastLanguage = langEntry.getText(); String lastLanguage = langEntry.getText();
lastCountry = countryEntry.getText(); String lastCountry = countryEntry.getText();
lastVariant = variantEntry.getText(); String lastVariant = variantEntry.getText();
if (lastLanguage.length() == 0) { if (lastLanguage.length() == 0) {
throw new Exception("Language is required"); throw new Exception("Language is required");
@ -198,6 +201,7 @@ public class TranslationTool extends JFrame
} }
stringsModel.addLocale(code); stringsModel.addLocale(code);
updateButtonsEnabled();
} }
catch (Exception e) catch (Exception e)
{ {
@ -208,21 +212,32 @@ public class TranslationTool extends JFrame
} }
} }
private void updateButtonsEnabled()
{
int count = stringsModel.getAllLocaleCodes().length;
removeBtn.setEnabled(count > 1);
testBtn.setEnabled(count > 1);
submitBtn.setEnabled(count > 1);
}
String pickLocale(String message, String dlgTitle) String pickLocale(String message, String dlgTitle)
{ {
String[] locales = stringsModel.getAllLocaleCodes(); String[] locales = stringsModel.getAllLocaleCodes();
if (locales.length == 1) { JComboBox<String> localeCb = new JComboBox<String>();
return locales[0]; for (int i = 0; i < locales.length; i++) {
if (locales[i] != null) {
localeCb.addItem(locales[i]);
}
} }
else if (locales.length == 0) {
if (localeCb.getItemCount() == 1) {
return (String) localeCb.getItemAt(0);
}
else if (localeCb.getItemCount() == 0) {
return null; return null;
} }
JComboBox<String> localeCb = new JComboBox<String>(); localeCb.setSelectedIndex(localeCb.getItemCount()-1);
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[] { JComponent [] inputs = new JComponent[] {
new JLabel(message), new JLabel(message),
@ -248,6 +263,7 @@ public class TranslationTool extends JFrame
); );
if (code != null) { if (code != null) {
stringsModel.removeLocale(code.equals("C") ? null : code); stringsModel.removeLocale(code.equals("C") ? null : code);
updateButtonsEnabled();
} }
} }