diff --git a/core/src/main/java/com/github/weisj/darklaf/LafManager.java b/core/src/main/java/com/github/weisj/darklaf/LafManager.java index 9515453c..23733aae 100644 --- a/core/src/main/java/com/github/weisj/darklaf/LafManager.java +++ b/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(); diff --git a/core/src/main/java/com/github/weisj/darklaf/components/DynamicUI.java b/core/src/main/java/com/github/weisj/darklaf/components/DynamicUI.java index 57eae674..6d4f2852 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/DynamicUI.java +++ b/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 withLocalizedText(final T comp, final String textKey) { + return withDynamic(comp, c -> c.setText(UIManager.getString(textKey, c.getLocale()))); + } + + public static T withLocalizedText(final T comp, final String textKey) { + return withDynamic(comp, c -> c.setText(UIManager.getString(textKey, c.getLocale()))); + } public static T withLocalizedTooltip(final T comp, final String tipTextKey) { return withDynamic(comp, c -> c.setToolTipText(UIManager.getString(tipTextKey, c.getLocale()))); diff --git a/core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettings.java b/core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettings.java index 77e95074..8b672e13 100644 --- a/core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettings.java +++ b/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(); diff --git a/core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsPanel.java b/core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsPanel.java index 6405e1d5..33947c3f 100644 --- a/core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsPanel.java +++ b/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) { diff --git a/core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsUI.java b/core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsUI.java index 30eb0422..da2c1a38 100644 --- a/core/src/main/java/com/github/weisj/darklaf/settings/ThemeSettingsUI.java +++ b/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 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;