diff options
| author | 2021-03-18 22:56:21 +0200 | |
|---|---|---|
| committer | 2021-03-18 22:56:21 +0200 | |
| commit | 15ae5e21fcb395279587dd2a03d3b84ef308bd65 (patch) | |
| tree | f2158bb9bcb7afa959c81e36537b63bcc8218cdc | |
| parent | Use FlatLaf's own DPI scaling instead of swing-dpi (diff) | |
| download | enigma-15ae5e21fcb395279587dd2a03d3b84ef308bd65.tar.gz enigma-15ae5e21fcb395279587dd2a03d3b84ef308bd65.tar.xz enigma-15ae5e21fcb395279587dd2a03d3b84ef308bd65.zip | |
Don't use custom editor fonts when they aren't enabled
3 files changed, 20 insertions, 3 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 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/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 3435012f..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 | |||
| @@ -79,7 +79,7 @@ public class JavadocDialog { | |||
| 79 | } | 79 | } |
| 80 | } | 80 | } |
| 81 | }); | 81 | }); |
| 82 | this.text.setFont(UiConfig.getEditorFont()); | 82 | this.text.setFont(UiConfig.shouldUseCustomFonts() ? UiConfig.getEditorFont() : UiConfig.getFallbackEditorFont()); |
| 83 | 83 | ||
| 84 | // buttons panel | 84 | // buttons panel |
| 85 | JPanel buttonsPanel = new JPanel(); | 85 | JPanel buttonsPanel = new JPanel(); |