diff options
| author | 2021-03-25 19:23:35 +0100 | |
|---|---|---|
| committer | 2021-03-25 19:24:39 +0100 | |
| commit | cd9671588014985792a694ff8e0fc3e217a6dfda (patch) | |
| tree | 637d952b238b11fa8f29204512f452c2399b1eec | |
| parent | Bump version (diff) | |
| download | enigma-cd9671588014985792a694ff8e0fc3e217a6dfda.tar.gz enigma-cd9671588014985792a694ff8e0fc3e217a6dfda.tar.xz enigma-cd9671588014985792a694ff8e0fc3e217a6dfda.zip | |
Fix using runtime changed configuration for parts of the UI that don't support it yet
Closes #346.
9 files changed, 64 insertions, 35 deletions
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/EnigmaSyntaxKit.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/EnigmaSyntaxKit.java index b500e4ba..115dfb4a 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/EnigmaSyntaxKit.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/EnigmaSyntaxKit.java | |||
| @@ -1,5 +1,7 @@ | |||
| 1 | package cuchaz.enigma.gui; | 1 | package cuchaz.enigma.gui; |
| 2 | 2 | ||
| 3 | import java.awt.Font; | ||
| 4 | |||
| 3 | import de.sciss.syntaxpane.DefaultSyntaxKit; | 5 | import de.sciss.syntaxpane.DefaultSyntaxKit; |
| 4 | import de.sciss.syntaxpane.components.LineNumbersRuler; | 6 | import de.sciss.syntaxpane.components.LineNumbersRuler; |
| 5 | import de.sciss.syntaxpane.syntaxkits.JavaSyntaxKit; | 7 | import de.sciss.syntaxpane.syntaxkits.JavaSyntaxKit; |
| @@ -7,8 +9,6 @@ import de.sciss.syntaxpane.util.Configuration; | |||
| 7 | 9 | ||
| 8 | import cuchaz.enigma.gui.config.UiConfig; | 10 | import cuchaz.enigma.gui.config.UiConfig; |
| 9 | 11 | ||
| 10 | import java.awt.Font; | ||
| 11 | |||
| 12 | public class EnigmaSyntaxKit extends JavaSyntaxKit { | 12 | public class EnigmaSyntaxKit extends JavaSyntaxKit { |
| 13 | 13 | ||
| 14 | private static Configuration configuration = null; | 14 | private static Configuration configuration = null; |
| @@ -55,7 +55,7 @@ public class EnigmaSyntaxKit extends JavaSyntaxKit { | |||
| 55 | 55 | ||
| 56 | configuration.put("Action.quick-find", "cuchaz.enigma.gui.QuickFindAction, menu F"); | 56 | configuration.put("Action.quick-find", "cuchaz.enigma.gui.QuickFindAction, menu F"); |
| 57 | 57 | ||
| 58 | Font editorFont = UiConfig.shouldUseCustomFonts() ? UiConfig.getEditorFont() : UiConfig.getFallbackEditorFont(); | 58 | Font editorFont = UiConfig.activeUseCustomFonts() ? UiConfig.getEditorFont() : UiConfig.getFallbackEditorFont(); |
| 59 | configuration.put("DefaultFont", UiConfig.encodeFont(editorFont)); | 59 | configuration.put("DefaultFont", UiConfig.encodeFont(editorFont)); |
| 60 | } | 60 | } |
| 61 | 61 | ||
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 c5f827ef..007af645 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java | |||
| @@ -23,7 +23,10 @@ import java.util.function.Function; | |||
| 23 | 23 | ||
| 24 | import javax.annotation.Nullable; | 24 | import javax.annotation.Nullable; |
| 25 | import javax.swing.*; | 25 | import javax.swing.*; |
| 26 | import javax.swing.tree.*; | 26 | import javax.swing.tree.DefaultMutableTreeNode; |
| 27 | import javax.swing.tree.DefaultTreeModel; | ||
| 28 | import javax.swing.tree.TreeNode; | ||
| 29 | import javax.swing.tree.TreePath; | ||
| 27 | 30 | ||
| 28 | import com.google.common.collect.HashBiMap; | 31 | import com.google.common.collect.HashBiMap; |
| 29 | import com.google.common.collect.Lists; | 32 | import com.google.common.collect.Lists; |
| @@ -55,7 +58,10 @@ import cuchaz.enigma.network.packet.RemoveMappingC2SPacket; | |||
| 55 | import cuchaz.enigma.network.packet.RenameC2SPacket; | 58 | import cuchaz.enigma.network.packet.RenameC2SPacket; |
| 56 | import cuchaz.enigma.source.Token; | 59 | import cuchaz.enigma.source.Token; |
| 57 | import cuchaz.enigma.translation.mapping.EntryRemapper; | 60 | import cuchaz.enigma.translation.mapping.EntryRemapper; |
| 58 | import cuchaz.enigma.translation.representation.entry.*; | 61 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 62 | import cuchaz.enigma.translation.representation.entry.Entry; | ||
| 63 | import cuchaz.enigma.translation.representation.entry.FieldEntry; | ||
| 64 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | ||
| 59 | import cuchaz.enigma.utils.I18n; | 65 | import cuchaz.enigma.utils.I18n; |
| 60 | import cuchaz.enigma.utils.validation.ParameterizedMessage; | 66 | import cuchaz.enigma.utils.validation.ParameterizedMessage; |
| 61 | import cuchaz.enigma.utils.validation.ValidationContext; | 67 | import cuchaz.enigma.utils.validation.ValidationContext; |
| @@ -111,7 +117,7 @@ public class Gui implements LanguageChangeListener { | |||
| 111 | private final HashBiMap<ClassEntry, EditorPanel> editors = HashBiMap.create(); | 117 | private final HashBiMap<ClassEntry, EditorPanel> editors = HashBiMap.create(); |
| 112 | 118 | ||
| 113 | public Gui(EnigmaProfile profile) { | 119 | public Gui(EnigmaProfile profile) { |
| 114 | UiConfig.getLookAndFeel().setGlobalLAF(); | 120 | UiConfig.getActiveLookAndFeel().setGlobalLAF(); |
| 115 | 121 | ||
| 116 | // init frame | 122 | // init frame |
| 117 | this.frame = new JFrame(Enigma.NAME); | 123 | this.frame = new JFrame(Enigma.NAME); |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/config/LookAndFeel.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/config/LookAndFeel.java index 3edc87a2..ab9fa2a0 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/config/LookAndFeel.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/config/LookAndFeel.java | |||
| @@ -11,7 +11,6 @@ import javax.swing.plaf.metal.MetalLookAndFeel; | |||
| 11 | import com.formdev.flatlaf.FlatDarkLaf; | 11 | import com.formdev.flatlaf.FlatDarkLaf; |
| 12 | import com.formdev.flatlaf.FlatLightLaf; | 12 | import com.formdev.flatlaf.FlatLightLaf; |
| 13 | import com.formdev.flatlaf.FlatSystemProperties; | 13 | import com.formdev.flatlaf.FlatSystemProperties; |
| 14 | import cuchaz.enigma.gui.util.ScaleUtil; | ||
| 15 | 14 | ||
| 16 | public enum LookAndFeel { | 15 | public enum LookAndFeel { |
| 17 | DEFAULT(false), | 16 | DEFAULT(false), |
| @@ -37,7 +36,7 @@ public enum LookAndFeel { | |||
| 37 | public void setGlobalLAF() { | 36 | public void setGlobalLAF() { |
| 38 | // Configure FlatLaf's UI scale to be our scale factor. | 37 | // Configure FlatLaf's UI scale to be our scale factor. |
| 39 | // This is also used for the SVG icons, so it applies even when some other LaF is active. | 38 | // This is also used for the SVG icons, so it applies even when some other LaF is active. |
| 40 | System.setProperty(FlatSystemProperties.UI_SCALE, Float.toString(ScaleUtil.getScaleFactor())); | 39 | System.setProperty(FlatSystemProperties.UI_SCALE, Float.toString(UiConfig.getActiveScaleFactor())); |
| 41 | 40 | ||
| 42 | try { | 41 | try { |
| 43 | switch (this) { | 42 | switch (this) { |
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 4905b1c5..fe8d863e 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 | |||
| @@ -20,7 +20,7 @@ public class Themes { | |||
| 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 | public static void updateTheme() { |
| 23 | LookAndFeel laf = UiConfig.getLookAndFeel(); | 23 | LookAndFeel laf = UiConfig.getActiveLookAndFeel(); |
| 24 | laf.setGlobalLAF(); | 24 | laf.setGlobalLAF(); |
| 25 | setFonts(); | 25 | setFonts(); |
| 26 | UiConfig.setLookAndFeelDefaults(laf, LookAndFeel.isDarkLaf()); | 26 | UiConfig.setLookAndFeelDefaults(laf, LookAndFeel.isDarkLaf()); |
| @@ -34,7 +34,7 @@ public class Themes { | |||
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | private static void setFonts() { | 36 | private static void setFonts() { |
| 37 | if (UiConfig.shouldUseCustomFonts()) { | 37 | if (UiConfig.activeUseCustomFonts()) { |
| 38 | Font small = UiConfig.getSmallFont(); | 38 | Font small = UiConfig.getSmallFont(); |
| 39 | Font bold = UiConfig.getDefaultFont(); | 39 | Font bold = UiConfig.getDefaultFont(); |
| 40 | Font normal = UiConfig.getDefault2Font(); | 40 | Font normal = UiConfig.getDefault2Font(); |
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 e4adadf1..9191485a 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 | |||
| @@ -19,10 +19,20 @@ public final class UiConfig { | |||
| 19 | // Swing specific configuration such as theming | 19 | // Swing specific configuration such as theming |
| 20 | private static final ConfigContainer swing = ConfigContainer.getOrCreate("enigma/enigmaswing"); | 20 | private static final ConfigContainer swing = ConfigContainer.getOrCreate("enigma/enigmaswing"); |
| 21 | 21 | ||
| 22 | // These are used for getting stuff that needs to stay constant for the | ||
| 23 | // runtime of the program, e.g. the current theme, because changing of these | ||
| 24 | // settings without a restart isn't implemented correctly yet. | ||
| 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 | ||
| 27 | // startup. | ||
| 28 | private static final ConfigSection runningSwing; | ||
| 29 | |||
| 22 | static { | 30 | static { |
| 23 | if (!swing.existsOnDisk() && !ui.existsOnDisk()) { | 31 | if (!swing.existsOnDisk() && !ui.existsOnDisk()) { |
| 24 | OldConfigImporter.doImport(); | 32 | OldConfigImporter.doImport(); |
| 25 | } | 33 | } |
| 34 | |||
| 35 | runningSwing = swing.data().copy(); | ||
| 26 | } | 36 | } |
| 27 | 37 | ||
| 28 | public static void save() { | 38 | public static void save() { |
| @@ -42,6 +52,10 @@ public final class UiConfig { | |||
| 42 | return (float) swing.data().section("General").setIfAbsentDouble("Scale Factor", 1.0); | 52 | return (float) swing.data().section("General").setIfAbsentDouble("Scale Factor", 1.0); |
| 43 | } | 53 | } |
| 44 | 54 | ||
| 55 | public static float getActiveScaleFactor() { | ||
| 56 | return (float) runningSwing.section("General").setIfAbsentDouble("Scale Factor", 1.0); | ||
| 57 | } | ||
| 58 | |||
| 45 | public static void setScaleFactor(float scale) { | 59 | public static void setScaleFactor(float scale) { |
| 46 | swing.data().section("General").setDouble("Scale Factor", scale); | 60 | swing.data().section("General").setDouble("Scale Factor", scale); |
| 47 | } | 61 | } |
| @@ -71,6 +85,10 @@ public final class UiConfig { | |||
| 71 | return swing.data().section("Themes").setIfAbsentEnum(LookAndFeel::valueOf, "Current", LookAndFeel.NONE); | 85 | return swing.data().section("Themes").setIfAbsentEnum(LookAndFeel::valueOf, "Current", LookAndFeel.NONE); |
| 72 | } | 86 | } |
| 73 | 87 | ||
| 88 | public static LookAndFeel getActiveLookAndFeel() { | ||
| 89 | return runningSwing.section("Themes").setIfAbsentEnum(LookAndFeel::valueOf, "Current", LookAndFeel.NONE); | ||
| 90 | } | ||
| 91 | |||
| 74 | public static void setLookAndFeel(LookAndFeel laf) { | 92 | public static void setLookAndFeel(LookAndFeel laf) { |
| 75 | swing.data().section("Themes").setEnum("Current", laf); | 93 | swing.data().section("Themes").setEnum("Current", laf); |
| 76 | } | 94 | } |
| @@ -89,12 +107,12 @@ public final class UiConfig { | |||
| 89 | } | 107 | } |
| 90 | 108 | ||
| 91 | private static Color getThemeColorRgba(String colorName) { | 109 | private static Color getThemeColorRgba(String colorName) { |
| 92 | ConfigSection s = swing.data().section("Themes").section(getLookAndFeel().name()).section("Colors"); | 110 | ConfigSection s = runningSwing.section("Themes").section(getLookAndFeel().name()).section("Colors"); |
| 93 | return fromComponents(s.getRgbColor(colorName).orElse(0), s.getDouble(String.format("%s Alpha", colorName)).orElse(0)); | 111 | return fromComponents(s.getRgbColor(colorName).orElse(0), s.getDouble(String.format("%s Alpha", colorName)).orElse(0)); |
| 94 | } | 112 | } |
| 95 | 113 | ||
| 96 | private static Color getThemeColorRgb(String colorName) { | 114 | private static Color getThemeColorRgb(String colorName) { |
| 97 | ConfigSection s = swing.data().section("Themes").section(getLookAndFeel().name()).section("Colors"); | 115 | ConfigSection s = runningSwing.section("Themes").section(getLookAndFeel().name()).section("Colors"); |
| 98 | return new Color(s.getRgbColor(colorName).orElse(0)); | 116 | return new Color(s.getRgbColor(colorName).orElse(0)); |
| 99 | } | 117 | } |
| 100 | 118 | ||
| @@ -178,10 +196,14 @@ public final class UiConfig { | |||
| 178 | return getThemeColorRgb("Line Numbers Selected"); | 196 | return getThemeColorRgb("Line Numbers Selected"); |
| 179 | } | 197 | } |
| 180 | 198 | ||
| 181 | public static boolean shouldUseCustomFonts() { | 199 | public static boolean useCustomFonts() { |
| 182 | return swing.data().section("Themes").section(getLookAndFeel().name()).section("Fonts").setIfAbsentBool("Use Custom", false); | 200 | return swing.data().section("Themes").section(getLookAndFeel().name()).section("Fonts").setIfAbsentBool("Use Custom", false); |
| 183 | } | 201 | } |
| 184 | 202 | ||
| 203 | public static boolean activeUseCustomFonts() { | ||
| 204 | return runningSwing.section("Themes").section(getLookAndFeel().name()).section("Fonts").setIfAbsentBool("Use Custom", false); | ||
| 205 | } | ||
| 206 | |||
| 185 | public static void setUseCustomFonts(boolean b) { | 207 | public static void setUseCustomFonts(boolean b) { |
| 186 | swing.data().section("Themes").section(getLookAndFeel().name()).section("Fonts").setBool("Use Custom", b); | 208 | swing.data().section("Themes").section(getLookAndFeel().name()).section("Fonts").setBool("Use Custom", b); |
| 187 | } | 209 | } |
| @@ -191,12 +213,17 @@ public final class UiConfig { | |||
| 191 | return spec.map(Font::decode); | 213 | return spec.map(Font::decode); |
| 192 | } | 214 | } |
| 193 | 215 | ||
| 216 | public static Optional<Font> getActiveFont(String name) { | ||
| 217 | Optional<String> spec = runningSwing.section("Themes").section(getLookAndFeel().name()).section("Fonts").getString(name); | ||
| 218 | return spec.map(Font::decode); | ||
| 219 | } | ||
| 220 | |||
| 194 | public static void setFont(String name, Font font) { | 221 | public static void setFont(String name, Font font) { |
| 195 | swing.data().section("Themes").section(getLookAndFeel().name()).section("Fonts").setString(name, encodeFont(font)); | 222 | swing.data().section("Themes").section(getLookAndFeel().name()).section("Fonts").setString(name, encodeFont(font)); |
| 196 | } | 223 | } |
| 197 | 224 | ||
| 198 | public static Font getDefaultFont() { | 225 | public static Font getDefaultFont() { |
| 199 | return getFont("Default").orElseGet(() -> ScaleUtil.scaleFont(Font.decode(Font.DIALOG).deriveFont(Font.BOLD))); | 226 | return getActiveFont("Default").orElseGet(() -> ScaleUtil.scaleFont(Font.decode(Font.DIALOG).deriveFont(Font.BOLD))); |
| 200 | } | 227 | } |
| 201 | 228 | ||
| 202 | public static void setDefaultFont(Font font) { | 229 | public static void setDefaultFont(Font font) { |
| @@ -204,7 +231,7 @@ public final class UiConfig { | |||
| 204 | } | 231 | } |
| 205 | 232 | ||
| 206 | public static Font getDefault2Font() { | 233 | public static Font getDefault2Font() { |
| 207 | return getFont("Default 2").orElseGet(() -> ScaleUtil.scaleFont(Font.decode(Font.DIALOG))); | 234 | return getActiveFont("Default 2").orElseGet(() -> ScaleUtil.scaleFont(Font.decode(Font.DIALOG))); |
| 208 | } | 235 | } |
| 209 | 236 | ||
| 210 | public static void setDefault2Font(Font font) { | 237 | public static void setDefault2Font(Font font) { |
| @@ -212,7 +239,7 @@ public final class UiConfig { | |||
| 212 | } | 239 | } |
| 213 | 240 | ||
| 214 | public static Font getSmallFont() { | 241 | public static Font getSmallFont() { |
| 215 | return getFont("Small").orElseGet(() -> ScaleUtil.scaleFont(Font.decode(Font.DIALOG))); | 242 | return getActiveFont("Small").orElseGet(() -> ScaleUtil.scaleFont(Font.decode(Font.DIALOG))); |
| 216 | } | 243 | } |
| 217 | 244 | ||
| 218 | public static void setSmallFont(Font font) { | 245 | public static void setSmallFont(Font font) { |
| @@ -220,7 +247,7 @@ public final class UiConfig { | |||
| 220 | } | 247 | } |
| 221 | 248 | ||
| 222 | public static Font getEditorFont() { | 249 | public static Font getEditorFont() { |
| 223 | return getFont("Editor").orElseGet(UiConfig::getFallbackEditorFont); | 250 | return getActiveFont("Editor").orElseGet(UiConfig::getFallbackEditorFont); |
| 224 | } | 251 | } |
| 225 | 252 | ||
| 226 | public static void setEditorFont(Font font) { | 253 | public static void setEditorFont(Font font) { |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/FontDialog.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/FontDialog.java index de019adb..1db8aea2 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/FontDialog.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/FontDialog.java | |||
| @@ -43,7 +43,7 @@ public class FontDialog extends JDialog { | |||
| 43 | public FontDialog(Frame owner) { | 43 | public FontDialog(Frame owner) { |
| 44 | super(owner, "Fonts", true); | 44 | super(owner, "Fonts", true); |
| 45 | 45 | ||
| 46 | this.customCheckBox.setSelected(UiConfig.shouldUseCustomFonts()); | 46 | this.customCheckBox.setSelected(UiConfig.useCustomFonts()); |
| 47 | 47 | ||
| 48 | this.entries.setPreferredSize(ScaleUtil.getDimension(100, 0)); | 48 | this.entries.setPreferredSize(ScaleUtil.getDimension(100, 0)); |
| 49 | 49 | ||
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/JavadocDialog.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/JavadocDialog.java index 8a5a3766..0e6d374c 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/JavadocDialog.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/dialog/JavadocDialog.java | |||
| @@ -79,7 +79,7 @@ public class JavadocDialog { | |||
| 79 | } | 79 | } |
| 80 | } | 80 | } |
| 81 | }); | 81 | }); |
| 82 | this.text.setFont(UiConfig.shouldUseCustomFonts() ? UiConfig.getEditorFont() : UiConfig.getFallbackEditorFont()); | 82 | this.text.setFont(UiConfig.activeUseCustomFonts() ? UiConfig.getEditorFont() : UiConfig.getFallbackEditorFont()); |
| 83 | 83 | ||
| 84 | // buttons panel | 84 | // buttons panel |
| 85 | JPanel buttonsPanel = new JPanel(); | 85 | JPanel buttonsPanel = new JPanel(); |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java index d5d657dc..f7f42a58 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java | |||
| @@ -270,7 +270,7 @@ public class MenuBar { | |||
| 270 | 270 | ||
| 271 | private void onCustomScaleClicked() { | 271 | private void onCustomScaleClicked() { |
| 272 | String answer = (String) JOptionPane.showInputDialog(this.gui.getFrame(), I18n.translate("menu.view.scale.custom.title"), I18n.translate("menu.view.scale.custom.title"), | 272 | String answer = (String) JOptionPane.showInputDialog(this.gui.getFrame(), I18n.translate("menu.view.scale.custom.title"), I18n.translate("menu.view.scale.custom.title"), |
| 273 | JOptionPane.QUESTION_MESSAGE, null, null, Float.toString(ScaleUtil.getScaleFactor() * 100)); | 273 | JOptionPane.QUESTION_MESSAGE, null, null, Float.toString(UiConfig.getScaleFactor() * 100)); |
| 274 | if (answer == null) return; | 274 | if (answer == null) return; |
| 275 | float newScale = 1.0f; | 275 | float newScale = 1.0f; |
| 276 | try { | 276 | try { |
| @@ -455,7 +455,7 @@ public class MenuBar { | |||
| 455 | }) | 455 | }) |
| 456 | .collect(Collectors.toMap(x -> x.a, x -> x.b)); | 456 | .collect(Collectors.toMap(x -> x.a, x -> x.b)); |
| 457 | 457 | ||
| 458 | JRadioButtonMenuItem currentScaleButton = scaleButtons.get(ScaleUtil.getScaleFactor()); | 458 | JRadioButtonMenuItem currentScaleButton = scaleButtons.get(UiConfig.getScaleFactor()); |
| 459 | if (currentScaleButton != null) { | 459 | if (currentScaleButton != null) { |
| 460 | currentScaleButton.setSelected(true); | 460 | currentScaleButton.setSelected(true); |
| 461 | } | 461 | } |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/util/ScaleUtil.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/util/ScaleUtil.java index 78de07dc..28e37693 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/util/ScaleUtil.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/util/ScaleUtil.java | |||
| @@ -24,12 +24,8 @@ public class ScaleUtil { | |||
| 24 | 24 | ||
| 25 | private static List<ScaleChangeListener> listeners = new ArrayList<>(); | 25 | private static List<ScaleChangeListener> listeners = new ArrayList<>(); |
| 26 | 26 | ||
| 27 | public static float getScaleFactor() { | ||
| 28 | return UiConfig.getScaleFactor(); | ||
| 29 | } | ||
| 30 | |||
| 31 | public static void setScaleFactor(float scaleFactor) { | 27 | public static void setScaleFactor(float scaleFactor) { |
| 32 | float oldScale = getScaleFactor(); | 28 | float oldScale = UiConfig.getScaleFactor(); |
| 33 | float clamped = Math.min(Math.max(0.25f, scaleFactor), 10.0f); | 29 | float clamped = Math.min(Math.max(0.25f, scaleFactor), 10.0f); |
| 34 | UiConfig.setScaleFactor(clamped); | 30 | UiConfig.setScaleFactor(clamped); |
| 35 | rescaleFontInConfig("Default", oldScale); | 31 | rescaleFontInConfig("Default", oldScale); |
| @@ -61,28 +57,29 @@ public class ScaleUtil { | |||
| 61 | } | 57 | } |
| 62 | 58 | ||
| 63 | public static Font scaleFont(Font font) { | 59 | public static Font scaleFont(Font font) { |
| 64 | return createTweakerForCurrentLook(getScaleFactor()).modifyFont("", font); | 60 | return createTweakerForCurrentLook(UiConfig.getActiveScaleFactor()).modifyFont("", font); |
| 65 | } | 61 | } |
| 66 | 62 | ||
| 67 | private static void rescaleFontInConfig(String name, float oldScale) { | 63 | private static void rescaleFontInConfig(String name, float oldScale) { |
| 68 | UiConfig.getFont(name).ifPresent(font -> UiConfig.setFont(name, rescaleFont(font, oldScale))); | 64 | UiConfig.getFont(name).ifPresent(font -> UiConfig.setFont(name, rescaleFont(font, oldScale))); |
| 69 | } | 65 | } |
| 70 | 66 | ||
| 71 | public static Font rescaleFont(Font font, float oldScale) { | 67 | // This does not use the font that's currently active in the UI! |
| 72 | float newSize = Math.round(font.getSize() / oldScale * getScaleFactor()); | 68 | private static Font rescaleFont(Font font, float oldScale) { |
| 69 | float newSize = Math.round(font.getSize() / oldScale * UiConfig.getScaleFactor()); | ||
| 73 | return font.deriveFont(newSize); | 70 | return font.deriveFont(newSize); |
| 74 | } | 71 | } |
| 75 | 72 | ||
| 76 | public static float scale(float f) { | 73 | public static float scale(float f) { |
| 77 | return f * getScaleFactor(); | 74 | return f * UiConfig.getActiveScaleFactor(); |
| 78 | } | 75 | } |
| 79 | 76 | ||
| 80 | public static float invert(float f) { | 77 | public static float invert(float f) { |
| 81 | return f / getScaleFactor(); | 78 | return f / UiConfig.getActiveScaleFactor(); |
| 82 | } | 79 | } |
| 83 | 80 | ||
| 84 | public static int scale(int i) { | 81 | public static int scale(int i) { |
| 85 | return (int) (i * getScaleFactor()); | 82 | return (int) (i * UiConfig.getActiveScaleFactor()); |
| 86 | } | 83 | } |
| 87 | 84 | ||
| 88 | public static Border createEmptyBorder(int top, int left, int bottom, int right) { | 85 | public static Border createEmptyBorder(int top, int left, int bottom, int right) { |
| @@ -90,13 +87,13 @@ public class ScaleUtil { | |||
| 90 | } | 87 | } |
| 91 | 88 | ||
| 92 | public static int invert(int i) { | 89 | public static int invert(int i) { |
| 93 | return (int) (i / getScaleFactor()); | 90 | return (int) (i / UiConfig.getActiveScaleFactor()); |
| 94 | } | 91 | } |
| 95 | 92 | ||
| 96 | public static void applyScaling() { | 93 | public static void applyScaling() { |
| 97 | float scale = getScaleFactor(); | 94 | float scale = UiConfig.getActiveScaleFactor(); |
| 98 | 95 | ||
| 99 | if (UiConfig.getLookAndFeel().needsScaling()) { | 96 | if (UiConfig.getActiveLookAndFeel().needsScaling()) { |
| 100 | UiDefaultsScaler.updateAndApplyGlobalScaling((int) (100 * scale), true); | 97 | UiDefaultsScaler.updateAndApplyGlobalScaling((int) (100 * scale), true); |
| 101 | } | 98 | } |
| 102 | 99 | ||