diff options
| author | 2021-03-20 11:56:05 +0100 | |
|---|---|---|
| committer | 2021-03-20 11:56:05 +0100 | |
| commit | 8481e74e19cc349949851b3564e72a5f7fe89144 (patch) | |
| tree | 82e64ecec7a634fad8016f1377258c76fdc8e4a2 | |
| parent | Bump version (diff) | |
| parent | Switch to FlatDarkLaf instead of FlatDarculaLaf (diff) | |
| download | enigma-8481e74e19cc349949851b3564e72a5f7fe89144.tar.gz enigma-8481e74e19cc349949851b3564e72a5f7fe89144.tar.xz enigma-8481e74e19cc349949851b3564e72a5f7fe89144.zip | |
Merge pull request #358 from Juuxel/flatlaf
Migrate to FlatLaf
8 files changed, 53 insertions, 17 deletions
| @@ -11,7 +11,7 @@ Enigma includes the following open-source libraries: | |||
| 11 | - A [modified version](https://github.com/FabricMC/cfr) of [CFR](https://github.com/leibnitz27/cfr) (MIT) | 11 | - A [modified version](https://github.com/FabricMC/cfr) of [CFR](https://github.com/leibnitz27/cfr) (MIT) |
| 12 | - [Guava](https://github.com/google/guava) (Apache-2.0) | 12 | - [Guava](https://github.com/google/guava) (Apache-2.0) |
| 13 | - [SyntaxPane](https://github.com/Sciss/SyntaxPane) (Apache-2.0) | 13 | - [SyntaxPane](https://github.com/Sciss/SyntaxPane) (Apache-2.0) |
| 14 | - [Darcula](https://github.com/bulenkov/Darcula) (Apache-2.0) | 14 | - [FlatLaf](https://github.com/JFormDesigner/FlatLaf) (Apache-2.0) |
| 15 | - [jopt-simple](https://github.com/jopt-simple/jopt-simple) (MIT) | 15 | - [jopt-simple](https://github.com/jopt-simple/jopt-simple) (MIT) |
| 16 | - [ASM](https://asm.ow2.io/) (BSD-3-Clause) | 16 | - [ASM](https://asm.ow2.io/) (BSD-3-Clause) |
| 17 | 17 | ||
diff --git a/enigma-swing/build.gradle b/enigma-swing/build.gradle index 4f301391..06b28bb3 100644 --- a/enigma-swing/build.gradle +++ b/enigma-swing/build.gradle | |||
| @@ -8,7 +8,7 @@ dependencies { | |||
| 8 | implementation project(':enigma-server') | 8 | implementation project(':enigma-server') |
| 9 | 9 | ||
| 10 | implementation 'net.sf.jopt-simple:jopt-simple:6.0-alpha-3' | 10 | implementation 'net.sf.jopt-simple:jopt-simple:6.0-alpha-3' |
| 11 | implementation 'com.bulenkov:darcula:1.0.0-bobbylight' | 11 | implementation 'com.formdev:flatlaf:1.0' |
| 12 | implementation 'de.sciss:syntaxpane:1.2.0' | 12 | implementation 'de.sciss:syntaxpane:1.2.0' |
| 13 | implementation 'com.github.lukeu:swing-dpi:0.9' | 13 | implementation 'com.github.lukeu:swing-dpi:0.9' |
| 14 | implementation 'org.drjekyll:fontchooser:2.4' | 14 | implementation 'org.drjekyll:fontchooser:2.4' |
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 27c866ca..b500e4ba 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/EnigmaSyntaxKit.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/EnigmaSyntaxKit.java | |||
| @@ -7,6 +7,8 @@ import de.sciss.syntaxpane.util.Configuration; | |||
| 7 | 7 | ||
| 8 | import cuchaz.enigma.gui.config.UiConfig; | 8 | import cuchaz.enigma.gui.config.UiConfig; |
| 9 | 9 | ||
| 10 | import java.awt.Font; | ||
| 11 | |||
| 10 | public class EnigmaSyntaxKit extends JavaSyntaxKit { | 12 | public class EnigmaSyntaxKit extends JavaSyntaxKit { |
| 11 | 13 | ||
| 12 | private static Configuration configuration = null; | 14 | private static Configuration configuration = null; |
| @@ -53,7 +55,8 @@ public class EnigmaSyntaxKit extends JavaSyntaxKit { | |||
| 53 | 55 | ||
| 54 | configuration.put("Action.quick-find", "cuchaz.enigma.gui.QuickFindAction, menu F"); | 56 | configuration.put("Action.quick-find", "cuchaz.enigma.gui.QuickFindAction, menu F"); |
| 55 | 57 | ||
| 56 | configuration.put("DefaultFont", UiConfig.encodeFont(UiConfig.getEditorFont())); | 58 | Font editorFont = UiConfig.shouldUseCustomFonts() ? UiConfig.getEditorFont() : UiConfig.getFallbackEditorFont(); |
| 59 | configuration.put("DefaultFont", UiConfig.encodeFont(editorFont)); | ||
| 57 | } | 60 | } |
| 58 | 61 | ||
| 59 | /** | 62 | /** |
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 1c70d439..e21ef52c 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 | |||
| @@ -8,37 +8,49 @@ import javax.swing.JPanel; | |||
| 8 | import javax.swing.UIManager; | 8 | import javax.swing.UIManager; |
| 9 | import javax.swing.plaf.metal.MetalLookAndFeel; | 9 | import javax.swing.plaf.metal.MetalLookAndFeel; |
| 10 | 10 | ||
| 11 | import com.bulenkov.darcula.DarculaLaf; | 11 | import com.formdev.flatlaf.FlatDarkLaf; |
| 12 | import com.formdev.flatlaf.FlatLightLaf; | ||
| 13 | import com.formdev.flatlaf.FlatSystemProperties; | ||
| 14 | import cuchaz.enigma.gui.util.ScaleUtil; | ||
| 12 | 15 | ||
| 13 | public enum LookAndFeel { | 16 | public enum LookAndFeel { |
| 14 | DEFAULT("Default"), | 17 | DEFAULT(false), |
| 15 | DARCULA("Darcula"), | 18 | DARCULA(false), |
| 16 | SYSTEM("System"), | 19 | METAL(true), |
| 17 | NONE("None (JVM default)"); | 20 | SYSTEM(true), |
| 21 | NONE(true); | ||
| 18 | 22 | ||
| 19 | // the "JVM default" look and feel, get it at the beginning and store it so we can set it later | 23 | // the "JVM default" look and feel, get it at the beginning and store it so we can set it later |
| 20 | private static javax.swing.LookAndFeel NONE_LAF = UIManager.getLookAndFeel(); | 24 | private static final javax.swing.LookAndFeel NONE_LAF = UIManager.getLookAndFeel(); |
| 21 | private final String name; | 25 | private final boolean needsScaling; |
| 22 | 26 | ||
| 23 | LookAndFeel(String name) { | 27 | LookAndFeel(boolean needsScaling) { |
| 24 | this.name = name; | 28 | this.needsScaling = needsScaling; |
| 25 | } | 29 | } |
| 26 | 30 | ||
| 27 | public String getName() { | 31 | public boolean needsScaling() { |
| 28 | return name; | 32 | // FlatLaf-based LaFs do their own scaling so we don't have to do it. |
| 33 | // Running swing-dpi for FlatLaf actually breaks fonts, so we let it scale the GUI. | ||
| 34 | return needsScaling; | ||
| 29 | } | 35 | } |
| 30 | 36 | ||
| 31 | public void setGlobalLAF() { | 37 | public void setGlobalLAF() { |
| 38 | // Configure FlatLaf's UI scale to be our scale factor. | ||
| 39 | System.setProperty(FlatSystemProperties.UI_SCALE, Float.toString(ScaleUtil.getScaleFactor())); | ||
| 40 | |||
| 32 | try { | 41 | try { |
| 33 | switch (this) { | 42 | switch (this) { |
| 34 | case NONE: | 43 | case NONE: |
| 35 | UIManager.setLookAndFeel(NONE_LAF); | 44 | UIManager.setLookAndFeel(NONE_LAF); |
| 36 | break; | 45 | break; |
| 37 | case DEFAULT: | 46 | case DEFAULT: |
| 47 | UIManager.setLookAndFeel(new FlatLightLaf()); | ||
| 48 | break; | ||
| 49 | case METAL: | ||
| 38 | UIManager.setLookAndFeel(new MetalLookAndFeel()); | 50 | UIManager.setLookAndFeel(new MetalLookAndFeel()); |
| 39 | break; | 51 | break; |
| 40 | case DARCULA: | 52 | case DARCULA: |
| 41 | UIManager.setLookAndFeel(new DarculaLaf()); | 53 | UIManager.setLookAndFeel(new FlatDarkLaf()); |
| 42 | break; | 54 | break; |
| 43 | case SYSTEM: | 55 | case SYSTEM: |
| 44 | UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | 56 | UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
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 828da116..bab50df1 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 | |||
| @@ -220,13 +220,27 @@ public final class UiConfig { | |||
| 220 | } | 220 | } |
| 221 | 221 | ||
| 222 | public static Font getEditorFont() { | 222 | public static Font getEditorFont() { |
| 223 | return getFont("Editor").orElseGet(() -> ScaleUtil.scaleFont(Font.decode(Font.MONOSPACED))); | 223 | return getFont("Editor").orElseGet(UiConfig::getFallbackEditorFont); |
| 224 | } | 224 | } |
| 225 | 225 | ||
| 226 | public static void setEditorFont(Font font) { | 226 | public static void setEditorFont(Font font) { |
| 227 | setFont("Editor", font); | 227 | setFont("Editor", font); |
| 228 | } | 228 | } |
| 229 | 229 | ||
| 230 | /** | ||
| 231 | * Gets the fallback editor font. | ||
| 232 | * It is used | ||
| 233 | * <ul> | ||
| 234 | * <li>when there is no custom editor font chosen</li> | ||
| 235 | * <li>when custom fonts are disabled</li> | ||
| 236 | * </ul> | ||
| 237 | * | ||
| 238 | * @return the fallback editor font | ||
| 239 | */ | ||
| 240 | public static Font getFallbackEditorFont() { | ||
| 241 | return ScaleUtil.scaleFont(Font.decode(Font.MONOSPACED)); | ||
| 242 | } | ||
| 243 | |||
| 230 | public static String encodeFont(Font font) { | 244 | public static String encodeFont(Font font) { |
| 231 | int style = font.getStyle(); | 245 | int style = font.getStyle(); |
| 232 | String s = style == (Font.BOLD | Font.ITALIC) ? "bolditalic" : style == Font.ITALIC ? "italic" : style == Font.BOLD ? "bold" : "plain"; | 246 | String s = style == (Font.BOLD | Font.ITALIC) ? "bolditalic" : style == Font.ITALIC ? "italic" : style == Font.BOLD ? "bold" : "plain"; |
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 a934d34c..8a5a3766 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 | |||
| @@ -25,6 +25,7 @@ import com.google.common.base.Strings; | |||
| 25 | 25 | ||
| 26 | import cuchaz.enigma.analysis.EntryReference; | 26 | import cuchaz.enigma.analysis.EntryReference; |
| 27 | import cuchaz.enigma.gui.GuiController; | 27 | import cuchaz.enigma.gui.GuiController; |
| 28 | import cuchaz.enigma.gui.config.UiConfig; | ||
| 28 | import cuchaz.enigma.gui.elements.ValidatableTextArea; | 29 | import cuchaz.enigma.gui.elements.ValidatableTextArea; |
| 29 | import cuchaz.enigma.gui.util.GuiUtil; | 30 | import cuchaz.enigma.gui.util.GuiUtil; |
| 30 | import cuchaz.enigma.gui.util.ScaleUtil; | 31 | import cuchaz.enigma.gui.util.ScaleUtil; |
| @@ -78,6 +79,7 @@ public class JavadocDialog { | |||
| 78 | } | 79 | } |
| 79 | } | 80 | } |
| 80 | }); | 81 | }); |
| 82 | this.text.setFont(UiConfig.shouldUseCustomFonts() ? UiConfig.getEditorFont() : UiConfig.getFallbackEditorFont()); | ||
| 81 | 83 | ||
| 82 | // buttons panel | 84 | // buttons panel |
| 83 | JPanel buttonsPanel = new JPanel(); | 85 | JPanel buttonsPanel = new JPanel(); |
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 47799fad..78de07dc 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 | |||
| @@ -95,7 +95,11 @@ public class ScaleUtil { | |||
| 95 | 95 | ||
| 96 | public static void applyScaling() { | 96 | public static void applyScaling() { |
| 97 | float scale = getScaleFactor(); | 97 | float scale = getScaleFactor(); |
| 98 | UiDefaultsScaler.updateAndApplyGlobalScaling((int) (100 * scale), true); | 98 | |
| 99 | if (UiConfig.getLookAndFeel().needsScaling()) { | ||
| 100 | UiDefaultsScaler.updateAndApplyGlobalScaling((int) (100 * scale), true); | ||
| 101 | } | ||
| 102 | |||
| 99 | try { | 103 | try { |
| 100 | Field defaultFontField = DefaultSyntaxKit.class.getDeclaredField("DEFAULT_FONT"); | 104 | Field defaultFontField = DefaultSyntaxKit.class.getDeclaredField("DEFAULT_FONT"); |
| 101 | defaultFontField.setAccessible(true); | 105 | defaultFontField.setAccessible(true); |
diff --git a/enigma/src/main/resources/lang/en_us.json b/enigma/src/main/resources/lang/en_us.json index 8195bb1f..8862f22d 100644 --- a/enigma/src/main/resources/lang/en_us.json +++ b/enigma/src/main/resources/lang/en_us.json | |||
| @@ -36,6 +36,7 @@ | |||
| 36 | "menu.view.themes": "Themes", | 36 | "menu.view.themes": "Themes", |
| 37 | "menu.view.themes.default": "Default", | 37 | "menu.view.themes.default": "Default", |
| 38 | "menu.view.themes.darcula": "Darcula", | 38 | "menu.view.themes.darcula": "Darcula", |
| 39 | "menu.view.themes.metal": "Metal", | ||
| 39 | "menu.view.themes.system": "System", | 40 | "menu.view.themes.system": "System", |
| 40 | "menu.view.themes.none": "None (JVM Default)", | 41 | "menu.view.themes.none": "None (JVM Default)", |
| 41 | "menu.view.languages": "Languages", | 42 | "menu.view.languages": "Languages", |