Skip to content

Commit

Permalink
minor modifications to the GUI Language option panel (issue #407)
Browse files Browse the repository at this point in the history
  • Loading branch information
pminos committed May 17, 2016
1 parent e2af1bd commit e15424d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
Expand Up @@ -451,6 +451,6 @@ ShowDisambiguatorLog = Show disambiguator log
guiMenuRecentFiles = &Recent Files guiMenuRecentFiles = &Recent Files
guiFileNotFound = File Not Found guiFileNotFound = File Not Found
dialogTitleError = Error dialogTitleError = Error
guiLanguage = GUI Language: guiLanguage = GUI Language
quiLanguageNeedsRestart = Restart application for the language change to take effect. quiLanguageNeedsRestart = Restart application for the language change to take effect.
guiLanguageSystem = System Default guiLanguageSystem = System Default
Expand Up @@ -27,6 +27,7 @@
import java.awt.event.ItemListener; import java.awt.event.ItemListener;
import java.util.Locale; import java.util.Locale;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import javax.swing.BorderFactory;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import org.languagetool.Languages; import org.languagetool.Languages;
Expand All @@ -40,43 +41,43 @@
class GuiLangConfigPanel extends JPanel implements SavablePanel, ItemListener { class GuiLangConfigPanel extends JPanel implements SavablePanel, ItemListener {


private final LocalStorage storage; private final LocalStorage storage;
private final ResourceBundle messages;
private final LanguageComboBox languageBox; private final LanguageComboBox languageBox;
private final LanguageAdapter system; private final LanguageAdapter system;
private final JLabel needsRestartLabel = new JLabel("");
private boolean needsRestart = false;
private LanguageAdapter guiLang = null; private LanguageAdapter guiLang = null;


GuiLangConfigPanel(ResourceBundle messages, LocalStorage storage) { GuiLangConfigPanel(ResourceBundle messages, LocalStorage storage) {
super(new GridBagLayout()); super(new GridBagLayout());
applyComponentOrientation( applyComponentOrientation(
ComponentOrientation.getOrientation(Locale.getDefault())); ComponentOrientation.getOrientation(Locale.getDefault()));
setBorder(BorderFactory.createTitledBorder(messages.getString("guiLanguage")));
this.messages = messages;
this.storage = storage; this.storage = storage;
system = new LanguageAdapter(messages.getString("guiLanguageSystem")); system = new LanguageAdapter(messages.getString("guiLanguageSystem"));
//create a ComboBox with flags, do not include hidden languages, //create a ComboBox with flags, do not include hidden languages,
//use system as first option //use system as first option
languageBox = LanguageComboBox.create(messages, "", true, false, system); languageBox = LanguageComboBox.create(messages, "", true, false, system);


GridBagConstraints c = new GridBagConstraints(); GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(2, 4, 2, 0); c.insets = new Insets(2, 2, 2, 2);
c.gridx = 0; c.gridx = 0;
c.gridy = 0; c.gridy = 0;
add(new JLabel(messages.getString("guiLanguage")), c); c.weightx = 1;
c.insets = new Insets(2, 4, 2, 0); c.anchor = GridBagConstraints.LINE_START;
c.gridx = 1;
add(languageBox, c); add(languageBox, c);
c.insets = new Insets(2, 4, 2, 0);
c.gridx = 0;
c.gridy = 1; c.gridy = 1;
c.gridwidth = 2;

c.fill = GridBagConstraints.HORIZONTAL; c.fill = GridBagConstraints.HORIZONTAL;
JLabel warn = new JLabel("<html>" + messages.getString("quiLanguageNeedsRestart")); add(needsRestartLabel, c);
warn.setForeground(Color.red);
add(warn, c);
} }


@Override @Override
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) { if (e.getStateChange() == ItemEvent.SELECTED) {
guiLang = (LanguageAdapter) e.getItem(); guiLang = (LanguageAdapter) e.getItem();
needsRestartLabel.setText(messages.getString("quiLanguageNeedsRestart"));
needsRestartLabel.setForeground(Color.red);
} }
} }


Expand All @@ -92,6 +93,7 @@ public void save() {
if (guiLang == null) { if (guiLang == null) {
return; return;
} }
needsRestart = true;
if (guiLang.getLanguage() != null) { if (guiLang.getLanguage() != null) {
storage.saveProperty("gui.locale", new LocaleBean( storage.saveProperty("gui.locale", new LocaleBean(
guiLang.getLanguage().getLocaleWithCountryAndVariant())); guiLang.getLanguage().getLocaleWithCountryAndVariant()));
Expand All @@ -101,6 +103,10 @@ public void save() {
} }


private void loadOption() { private void loadOption() {
guiLang = null;
if (!needsRestart) {
needsRestartLabel.setText("");
}
LocaleBean lang = storage.loadProperty("gui.locale", LocaleBean.class); LocaleBean lang = storage.loadProperty("gui.locale", LocaleBean.class);
if (lang != null) { if (lang != null) {
Locale l = lang.asLocale(); Locale l = lang.asLocale();
Expand Down

0 comments on commit e15424d

Please sign in to comment.