diff options
| author | 2021-04-06 15:30:20 +0200 | |
|---|---|---|
| committer | 2021-04-06 15:30:20 +0200 | |
| commit | 08563fc589c8d004568765eea1f17076151456bd (patch) | |
| tree | 4e314a657ff94d215bfdce61ce6b223dbd9ca60d | |
| parent | Fix progress bar being very tall. (diff) | |
| download | enigma-08563fc589c8d004568765eea1f17076151456bd.tar.gz enigma-08563fc589c8d004568765eea1f17076151456bd.tar.xz enigma-08563fc589c8d004568765eea1f17076151456bd.zip | |
Fix visual inconsistencies after changing theme settings.
Closes #376.
4 files changed, 27 insertions, 18 deletions
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java index 007af645..ce4823e2 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java | |||
| @@ -117,8 +117,6 @@ public class Gui implements LanguageChangeListener { | |||
| 117 | private final HashBiMap<ClassEntry, EditorPanel> editors = HashBiMap.create(); | 117 | private final HashBiMap<ClassEntry, EditorPanel> editors = HashBiMap.create(); |
| 118 | 118 | ||
| 119 | public Gui(EnigmaProfile profile) { | 119 | public Gui(EnigmaProfile profile) { |
| 120 | UiConfig.getActiveLookAndFeel().setGlobalLAF(); | ||
| 121 | |||
| 122 | // init frame | 120 | // init frame |
| 123 | this.frame = new JFrame(Enigma.NAME); | 121 | this.frame = new JFrame(Enigma.NAME); |
| 124 | final Container pane = this.frame.getContentPane(); | 122 | final Container pane = this.frame.getContentPane(); |
| @@ -135,14 +133,10 @@ public class Gui implements LanguageChangeListener { | |||
| 135 | }); | 133 | }); |
| 136 | } | 134 | } |
| 137 | 135 | ||
| 138 | System.setProperty("apple.laf.useScreenMenuBar", "true"); | 136 | Themes.addListener((lookAndFeel, boxHighlightPainters) -> SwingUtilities.updateComponentTreeUI(this.getFrame())); |
| 139 | 137 | ||
| 140 | this.controller = new GuiController(this, profile); | 138 | this.controller = new GuiController(this, profile); |
| 141 | 139 | ||
| 142 | Themes.addListener((lookAndFeel, boxHighlightPainters) -> SwingUtilities.updateComponentTreeUI(getFrame())); | ||
| 143 | |||
| 144 | Themes.updateTheme(); | ||
| 145 | |||
| 146 | // init file choosers | 140 | // init file choosers |
| 147 | this.jarFileChooser = new FileDialog(getFrame(), I18n.translate("menu.file.jar.open"), FileDialog.LOAD); | 141 | this.jarFileChooser = new FileDialog(getFrame(), I18n.translate("menu.file.jar.open"), FileDialog.LOAD); |
| 148 | 142 | ||
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/Main.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/Main.java index 0589f362..b655bd4e 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/Main.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/Main.java | |||
| @@ -20,6 +20,7 @@ import com.google.common.io.MoreFiles; | |||
| 20 | import joptsimple.*; | 20 | import joptsimple.*; |
| 21 | 21 | ||
| 22 | import cuchaz.enigma.EnigmaProfile; | 22 | import cuchaz.enigma.EnigmaProfile; |
| 23 | import cuchaz.enigma.gui.config.Themes; | ||
| 23 | import cuchaz.enigma.gui.config.UiConfig; | 24 | import cuchaz.enigma.gui.config.UiConfig; |
| 24 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; | 25 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; |
| 25 | import cuchaz.enigma.utils.I18n; | 26 | import cuchaz.enigma.utils.I18n; |
| @@ -54,6 +55,9 @@ public class Main { | |||
| 54 | EnigmaProfile parsedProfile = EnigmaProfile.read(options.valueOf(profile)); | 55 | EnigmaProfile parsedProfile = EnigmaProfile.read(options.valueOf(profile)); |
| 55 | 56 | ||
| 56 | I18n.setLanguage(UiConfig.getLanguage()); | 57 | I18n.setLanguage(UiConfig.getLanguage()); |
| 58 | System.setProperty("apple.laf.useScreenMenuBar", "true"); | ||
| 59 | Themes.setupTheme(); | ||
| 60 | |||
| 57 | Gui gui = new Gui(parsedProfile); | 61 | Gui gui = new Gui(parsedProfile); |
| 58 | GuiController controller = gui.getController(); | 62 | GuiController controller = gui.getController(); |
| 59 | 63 | ||
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/config/Themes.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/config/Themes.java index b45236f5..839a5cbc 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/config/Themes.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/config/Themes.java | |||
| @@ -19,11 +19,14 @@ public class Themes { | |||
| 19 | 19 | ||
| 20 | private static final Set<ThemeChangeListener> listeners = new HashSet<>(); | 20 | private static final Set<ThemeChangeListener> listeners = new HashSet<>(); |
| 21 | 21 | ||
| 22 | public static void updateTheme() { | 22 | // Calling this after the UI is initialized (e.g. when the user changes |
| 23 | // theme settings) is currently not functional. | ||
| 24 | public static void setupTheme() { | ||
| 23 | LookAndFeel laf = UiConfig.getActiveLookAndFeel(); | 25 | LookAndFeel laf = UiConfig.getActiveLookAndFeel(); |
| 24 | laf.setGlobalLAF(); | 26 | laf.setGlobalLAF(); |
| 25 | setFonts(); | 27 | UiConfig.setLookAndFeelDefaults(UiConfig.getLookAndFeel(), LookAndFeel.isDarkLaf()); |
| 26 | UiConfig.setLookAndFeelDefaults(laf, LookAndFeel.isDarkLaf()); | 28 | UiConfig.snapshotConfig(); |
| 29 | Themes.setFonts(); | ||
| 27 | UIManager.put("ScrollBar.showButtons", true); | 30 | UIManager.put("ScrollBar.showButtons", true); |
| 28 | EnigmaSyntaxKit.invalidate(); | 31 | EnigmaSyntaxKit.invalidate(); |
| 29 | DefaultSyntaxKit.initKit(); | 32 | DefaultSyntaxKit.initKit(); |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/config/UiConfig.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/config/UiConfig.java index 9191485a..8ec8720d 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/config/UiConfig.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/config/UiConfig.java | |||
| @@ -25,13 +25,21 @@ public final class UiConfig { | |||
| 25 | // Don't change the values in this container with the expectation that they | 25 | // Don't change the values in this container with the expectation that they |
| 26 | // get saved, this is purely a backup of the configuration that existed at | 26 | // get saved, this is purely a backup of the configuration that existed at |
| 27 | // startup. | 27 | // startup. |
| 28 | private static final ConfigSection runningSwing; | 28 | private static ConfigSection runningSwing; |
| 29 | 29 | ||
| 30 | static { | 30 | static { |
| 31 | if (!swing.existsOnDisk() && !ui.existsOnDisk()) { | 31 | if (!swing.existsOnDisk() && !ui.existsOnDisk()) { |
| 32 | OldConfigImporter.doImport(); | 32 | OldConfigImporter.doImport(); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | UiConfig.snapshotConfig(); | ||
| 36 | } | ||
| 37 | |||
| 38 | // Saves the current configuration state so a consistent user interface can | ||
| 39 | // be provided for parts of the interface that don't support changing the | ||
| 40 | // configuration at runtime. Calling this after any UI elements are | ||
| 41 | // displayed can lead to visual glitches! | ||
| 42 | public static void snapshotConfig() { | ||
| 35 | runningSwing = swing.data().copy(); | 43 | runningSwing = swing.data().copy(); |
| 36 | } | 44 | } |
| 37 | 45 | ||
| @@ -107,12 +115,12 @@ public final class UiConfig { | |||
| 107 | } | 115 | } |
| 108 | 116 | ||
| 109 | private static Color getThemeColorRgba(String colorName) { | 117 | private static Color getThemeColorRgba(String colorName) { |
| 110 | ConfigSection s = runningSwing.section("Themes").section(getLookAndFeel().name()).section("Colors"); | 118 | ConfigSection s = runningSwing.section("Themes").section(getActiveLookAndFeel().name()).section("Colors"); |
| 111 | return fromComponents(s.getRgbColor(colorName).orElse(0), s.getDouble(String.format("%s Alpha", colorName)).orElse(0)); | 119 | return fromComponents(s.getRgbColor(colorName).orElse(0), s.getDouble(String.format("%s Alpha", colorName)).orElse(0)); |
| 112 | } | 120 | } |
| 113 | 121 | ||
| 114 | private static Color getThemeColorRgb(String colorName) { | 122 | private static Color getThemeColorRgb(String colorName) { |
| 115 | ConfigSection s = runningSwing.section("Themes").section(getLookAndFeel().name()).section("Colors"); | 123 | ConfigSection s = runningSwing.section("Themes").section(getActiveLookAndFeel().name()).section("Colors"); |
| 116 | return new Color(s.getRgbColor(colorName).orElse(0)); | 124 | return new Color(s.getRgbColor(colorName).orElse(0)); |
| 117 | } | 125 | } |
| 118 | 126 | ||
| @@ -197,24 +205,24 @@ public final class UiConfig { | |||
| 197 | } | 205 | } |
| 198 | 206 | ||
| 199 | public static boolean useCustomFonts() { | 207 | public static boolean useCustomFonts() { |
| 200 | return swing.data().section("Themes").section(getLookAndFeel().name()).section("Fonts").setIfAbsentBool("Use Custom", false); | 208 | return swing.data().section("Themes").section(getActiveLookAndFeel().name()).section("Fonts").setIfAbsentBool("Use Custom", false); |
| 201 | } | 209 | } |
| 202 | 210 | ||
| 203 | public static boolean activeUseCustomFonts() { | 211 | public static boolean activeUseCustomFonts() { |
| 204 | return runningSwing.section("Themes").section(getLookAndFeel().name()).section("Fonts").setIfAbsentBool("Use Custom", false); | 212 | return runningSwing.section("Themes").section(getActiveLookAndFeel().name()).section("Fonts").setIfAbsentBool("Use Custom", false); |
| 205 | } | 213 | } |
| 206 | 214 | ||
| 207 | public static void setUseCustomFonts(boolean b) { | 215 | public static void setUseCustomFonts(boolean b) { |
| 208 | swing.data().section("Themes").section(getLookAndFeel().name()).section("Fonts").setBool("Use Custom", b); | 216 | swing.data().section("Themes").section(getActiveLookAndFeel().name()).section("Fonts").setBool("Use Custom", b); |
| 209 | } | 217 | } |
| 210 | 218 | ||
| 211 | public static Optional<Font> getFont(String name) { | 219 | public static Optional<Font> getFont(String name) { |
| 212 | Optional<String> spec = swing.data().section("Themes").section(getLookAndFeel().name()).section("Fonts").getString(name); | 220 | Optional<String> spec = swing.data().section("Themes").section(getActiveLookAndFeel().name()).section("Fonts").getString(name); |
| 213 | return spec.map(Font::decode); | 221 | return spec.map(Font::decode); |
| 214 | } | 222 | } |
| 215 | 223 | ||
| 216 | public static Optional<Font> getActiveFont(String name) { | 224 | public static Optional<Font> getActiveFont(String name) { |
| 217 | Optional<String> spec = runningSwing.section("Themes").section(getLookAndFeel().name()).section("Fonts").getString(name); | 225 | Optional<String> spec = runningSwing.section("Themes").section(getActiveLookAndFeel().name()).section("Fonts").getString(name); |
| 218 | return spec.map(Font::decode); | 226 | return spec.map(Font::decode); |
| 219 | } | 227 | } |
| 220 | 228 | ||