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.
*/
// 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")
public static void installTheme(final Theme theme) {
if (theme == getTheme() && isInstalled()) return;
@ -453,6 +453,14 @@ public final class LafManager {
setInstalledTheme(theme);
}
public static void forceLafUpdate() {
if (isInstalled()) {
installer.install(getInstalledTheme());
} else {
install();
}
}
/** Update the component ui classes for all current windows. */
public static void updateLaf() {
installer.updateLaf();

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

@ -1,7 +1,7 @@
/*
* 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
* associated documentation files (the "Software"), to deal in the Software without restriction,
@ -34,7 +34,7 @@ public final class DynamicUI {
static {
UIManager.addPropertyChangeListener(e -> {
String key = e.getPropertyName();
if ("lookAndFeel".equals(key)) {
if ("lookandfeel".equalsIgnoreCase(key)) {
listeners.keySet().forEach(DynamicUI::updateComponent);
}
});
@ -63,6 +63,13 @@ public final class DynamicUI {
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) {
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.components.DefaultButton;
import com.github.weisj.darklaf.components.DynamicUI;
import com.github.weisj.darklaf.properties.icons.IconLoader;
import com.github.weisj.darklaf.theme.Theme;
import com.github.weisj.darklaf.theme.event.ThemePreferenceChangeEvent;
@ -369,20 +370,19 @@ public class ThemeSettings implements ThemePreferenceListener {
}
protected Component createButtonPanel() {
Locale l = Locale.getDefault();
JButton ok = new DefaultButton(UIManager.getString("settings.dialog_ok", l));
JButton ok = DynamicUI.withLocalizedText(new DefaultButton(""), "settings.dialog_ok");
ok.setDefaultCapable(true);
ok.addActionListener(e -> {
apply();
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 -> {
revert();
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());
Box box = Box.createHorizontalBox();

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

@ -1,7 +1,7 @@
/*
* 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
* associated documentation files (the "Software"), to deal in the Software without restriction,
@ -21,7 +21,6 @@
package com.github.weisj.darklaf.settings;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.ChangeListener;
@ -85,7 +84,7 @@ public class ThemeSettingsPanel extends JPanel {
}
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) {

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

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

Loading…
Cancel
Save