Browse Source

Settings: Ensure the settings dialog responds to locale changes

decorations
Jannis Weis 3 years ago
parent
commit
34f3815046
No known key found for this signature in database
GPG Key ID: 7C9D8D4B558049AB
  1. 10
      core/src/main/java/com/github/weisj/darklaf/LafManager.java
  2. 11
      core/src/main/java/com/github/weisj/darklaf/components/DynamicUI.java
  3. 8
      core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettings.java
  4. 5
      core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsPanel.java
  5. 8
      core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsUI.java

10
core/src/main/java/com/github/weisj/darklaf/LafManager.java

@ -418,7 +418,7 @@ public final class LafManager {
* @param theme the theme to install. * @param theme the theme to install.
*/ */
// Even for themes which are Objects#equals we can't be sure that they have the same effect. // Even for themes which are Objects#equals we can't be sure that they have the same effect.
// Maybe someone installed a custom installtion task and wants to reinstall. // Maybe someone installed a custom installation task and wants to reinstall.
@SuppressWarnings("ReferenceEquality") @SuppressWarnings("ReferenceEquality")
public static void installTheme(final Theme theme) { public static void installTheme(final Theme theme) {
if (theme == getTheme() && isInstalled()) return; if (theme == getTheme() && isInstalled()) return;
@ -453,6 +453,14 @@ public final class LafManager {
setInstalledTheme(theme); setInstalledTheme(theme);
} }
public static void forceLafUpdate() {
if (isInstalled()) {
installer.install(getInstalledTheme());
} else {
install();
}
}
/** Update the component ui classes for all current windows. */ /** Update the component ui classes for all current windows. */
public static void updateLaf() { public static void updateLaf() {
installer.updateLaf(); installer.updateLaf();

11
core/src/main/java/com/github/weisj/darklaf/components/DynamicUI.java

@ -1,7 +1,7 @@
/* /*
* MIT License * MIT License
* *
* Copyright (c) 2020-2021 Jannis Weis * Copyright (c) 2020-2022 Jannis Weis
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, * associated documentation files (the "Software"), to deal in the Software without restriction,
@ -34,7 +34,7 @@ public final class DynamicUI {
static { static {
UIManager.addPropertyChangeListener(e -> { UIManager.addPropertyChangeListener(e -> {
String key = e.getPropertyName(); String key = e.getPropertyName();
if ("lookAndFeel".equals(key)) { if ("lookandfeel".equalsIgnoreCase(key)) {
listeners.keySet().forEach(DynamicUI::updateComponent); listeners.keySet().forEach(DynamicUI::updateComponent);
} }
}); });
@ -63,6 +63,13 @@ public final class DynamicUI {
return component; return component;
} }
public static <T extends AbstractButton> T withLocalizedText(final T comp, final String textKey) {
return withDynamic(comp, c -> c.setText(UIManager.getString(textKey, c.getLocale())));
}
public static <T extends JLabel> T withLocalizedText(final T comp, final String textKey) {
return withDynamic(comp, c -> c.setText(UIManager.getString(textKey, c.getLocale())));
}
public static <T extends JComponent> T withLocalizedTooltip(final T comp, final String tipTextKey) { public static <T extends JComponent> T withLocalizedTooltip(final T comp, final String tipTextKey) {
return withDynamic(comp, c -> c.setToolTipText(UIManager.getString(tipTextKey, c.getLocale()))); return withDynamic(comp, c -> c.setToolTipText(UIManager.getString(tipTextKey, c.getLocale())));

8
core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettings.java

@ -30,6 +30,7 @@ import javax.swing.*;
import com.github.weisj.darklaf.LafManager; import com.github.weisj.darklaf.LafManager;
import com.github.weisj.darklaf.components.DefaultButton; import com.github.weisj.darklaf.components.DefaultButton;
import com.github.weisj.darklaf.components.DynamicUI;
import com.github.weisj.darklaf.properties.icons.IconLoader; import com.github.weisj.darklaf.properties.icons.IconLoader;
import com.github.weisj.darklaf.theme.Theme; import com.github.weisj.darklaf.theme.Theme;
import com.github.weisj.darklaf.theme.event.ThemePreferenceChangeEvent; import com.github.weisj.darklaf.theme.event.ThemePreferenceChangeEvent;
@ -369,20 +370,19 @@ public class ThemeSettings implements ThemePreferenceListener {
} }
protected Component createButtonPanel() { protected Component createButtonPanel() {
Locale l = Locale.getDefault(); JButton ok = DynamicUI.withLocalizedText(new DefaultButton(""), "settings.dialog_ok");
JButton ok = new DefaultButton(UIManager.getString("settings.dialog_ok", l));
ok.setDefaultCapable(true); ok.setDefaultCapable(true);
ok.addActionListener(e -> { ok.addActionListener(e -> {
apply(); apply();
dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING)); dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
}); });
JButton cancel = new JButton(UIManager.getString("settings.dialog_cancel", l)); JButton cancel = DynamicUI.withLocalizedText(new JButton(), "settings.dialog_cancel");
cancel.addActionListener(e -> { cancel.addActionListener(e -> {
revert(); revert();
dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING)); dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
}); });
JButton apply = new JButton(UIManager.getString("settings.dialog_apply", l)); JButton apply = DynamicUI.withLocalizedText(new JButton(), "settings.dialog_apply");
apply.addActionListener(e -> apply()); apply.addActionListener(e -> apply());
Box box = Box.createHorizontalBox(); Box box = Box.createHorizontalBox();

5
core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsPanel.java

@ -1,7 +1,7 @@
/* /*
* MIT License * MIT License
* *
* Copyright (c) 2020-2021 Jannis Weis * Copyright (c) 2020-2022 Jannis Weis
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, * associated documentation files (the "Software"), to deal in the Software without restriction,
@ -21,7 +21,6 @@
package com.github.weisj.darklaf.settings; package com.github.weisj.darklaf.settings;
import java.awt.*; import java.awt.*;
import java.util.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
@ -85,7 +84,7 @@ public class ThemeSettingsPanel extends JPanel {
} }
private static JLabel createDynamicLabel(final String key) { private static JLabel createDynamicLabel(final String key) {
return DynamicUI.withDynamic(new JLabel(), c -> c.setText(UIManager.getString(key, c.getLocale()))); return DynamicUI.withLocalizedText(new JLabel(), key);
} }
private JComponent createGeneralSettings(final GroupLayout.Alignment alignment, final Insets insets) { private JComponent createGeneralSettings(final GroupLayout.Alignment alignment, final Insets insets) {

8
core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsUI.java

@ -107,8 +107,8 @@ public class ThemeSettingsUI {
fontSlider = createFontSlider(); fontSlider = createFontSlider();
enabledSystemPreferences = DynamicUI.withDynamic(new TristateCheckBox(), enabledSystemPreferences =
c -> c.setText(UIManager.getString("settings.check_system_preferences", c.getLocale()))); DynamicUI.withLocalizedText(new TristateCheckBox(), "settings.check_system_preferences");
accentColorFollowsSystem = createSystemSettingCheckBox("settings.check_system_accent_color", accentColorFollowsSystem = createSystemSettingCheckBox("settings.check_system_accent_color",
ThemePreferencesHandler::supportsNativeAccentColor); ThemePreferencesHandler::supportsNativeAccentColor);
selectionColorFollowsSystem = createSystemSettingCheckBox("settings.check_system_selection_color", selectionColorFollowsSystem = createSystemSettingCheckBox("settings.check_system_selection_color",
@ -376,13 +376,13 @@ public class ThemeSettingsUI {
private static JCheckBox createSystemSettingCheckBox(final String labelKey, private static JCheckBox createSystemSettingCheckBox(final String labelKey,
final Function<ThemePreferencesHandler, Boolean> enabledCondition) { final Function<ThemePreferencesHandler, Boolean> enabledCondition) {
JCheckBox checkBox = DynamicUI.withDynamic(new JCheckBox() { JCheckBox checkBox = DynamicUI.withLocalizedText(new JCheckBox() {
@Override @Override
public void setEnabled(final boolean b) { public void setEnabled(final boolean b) {
boolean enabled = b && enabledCondition.apply(ThemePreferencesHandler.getSharedInstance()); boolean enabled = b && enabledCondition.apply(ThemePreferencesHandler.getSharedInstance());
super.setEnabled(enabled); super.setEnabled(enabled);
} }
}, c -> c.setText(UIManager.getString(labelKey, c.getLocale()))); }, labelKey);
checkBox.setSelected(false); checkBox.setSelected(false);
checkBox.setEnabled(false); checkBox.setEnabled(false);
return checkBox; return checkBox;

Loading…
Cancel
Save