From 04b01512c124c76f3b3d99ba07ef30ea6a90b52f Mon Sep 17 00:00:00 2001 From: 2xsaiko Date: Fri, 24 Apr 2020 18:39:57 +0200 Subject: Add a configurable scale factor (#230) * Add swing-dpi dependency * Implement scale factor * Improve custom scale dialog, fix crash * Remove use of $ in identifiers * Use custom functional interface for scale listeners * Bump version Co-authored-by: modmuss50 --- src/main/java/cuchaz/enigma/config/Config.java | 5 +- src/main/java/cuchaz/enigma/config/Themes.java | 66 +++++++++++++++----------- 2 files changed, 41 insertions(+), 30 deletions(-) (limited to 'src/main/java/cuchaz/enigma/config') diff --git a/src/main/java/cuchaz/enigma/config/Config.java b/src/main/java/cuchaz/enigma/config/Config.java index 15a974c..20605b7 100644 --- a/src/main/java/cuchaz/enigma/config/Config.java +++ b/src/main/java/cuchaz/enigma/config/Config.java @@ -7,6 +7,7 @@ import cuchaz.enigma.source.DecompilerService; import cuchaz.enigma.source.Decompilers; import cuchaz.enigma.utils.I18n; +import cuchaz.enigma.gui.util.ScaleUtil; import javax.swing.*; import javax.swing.plaf.metal.MetalLookAndFeel; @@ -78,7 +79,7 @@ public class Config { public static boolean isDarkLaf() { // a bit of a hack because swing doesn't give any API for that, and we need colors that aren't defined in look and feel JPanel panel = new JPanel(); - panel.setSize(new Dimension(10, 10)); + panel.setSize(ScaleUtil.getDimension(10, 10)); panel.doLayout(); BufferedImage image = new BufferedImage(panel.getSize().width, panel.getSize().height, BufferedImage.TYPE_INT_RGB); @@ -187,6 +188,8 @@ public class Config { public LookAndFeel lookAndFeel = LookAndFeel.DEFAULT; + public float scaleFactor = 1.0f; + public Decompiler decompiler = Decompiler.PROCYON; private Config() { diff --git a/src/main/java/cuchaz/enigma/config/Themes.java b/src/main/java/cuchaz/enigma/config/Themes.java index 753654e..547a420 100644 --- a/src/main/java/cuchaz/enigma/config/Themes.java +++ b/src/main/java/cuchaz/enigma/config/Themes.java @@ -1,40 +1,48 @@ package cuchaz.enigma.config; +import java.awt.Font; +import java.io.IOException; +import java.lang.reflect.Field; + +import javax.swing.SwingUtilities; + +import com.github.swingdpi.UiDefaultsScaler; import com.google.common.collect.ImmutableMap; -import cuchaz.enigma.gui.Gui; import cuchaz.enigma.gui.EnigmaSyntaxKit; +import cuchaz.enigma.gui.Gui; import cuchaz.enigma.gui.highlight.BoxHighlightPainter; import cuchaz.enigma.gui.highlight.TokenHighlightType; +import cuchaz.enigma.gui.util.ScaleUtil; import de.sciss.syntaxpane.DefaultSyntaxKit; -import javax.swing.*; -import java.io.IOException; - public class Themes { - public static void setLookAndFeel(Gui gui, Config.LookAndFeel lookAndFeel) { - Config.getInstance().lookAndFeel = lookAndFeel; - updateTheme(gui); - } - - public static void updateTheme(Gui gui) { - Config config = Config.getInstance(); - config.lookAndFeel.setGlobalLAF(); - config.lookAndFeel.apply(config); - try { - config.saveConfig(); - } catch (IOException e) { - e.printStackTrace(); - } - EnigmaSyntaxKit.invalidate(); - DefaultSyntaxKit.initKit(); - DefaultSyntaxKit.registerContentType("text/enigma-sources", EnigmaSyntaxKit.class.getName()); - gui.boxHighlightPainters = ImmutableMap.of( - TokenHighlightType.OBFUSCATED, BoxHighlightPainter.create(config.obfuscatedColor, config.obfuscatedColorOutline), - TokenHighlightType.PROPOSED, BoxHighlightPainter.create(config.proposedColor, config.proposedColorOutline), - TokenHighlightType.DEOBFUSCATED, BoxHighlightPainter.create(config.deobfuscatedColor, config.deobfuscatedColorOutline) - ); - gui.setEditorTheme(config.lookAndFeel); - SwingUtilities.updateComponentTreeUI(gui.getFrame()); - } + public static void setLookAndFeel(Gui gui, Config.LookAndFeel lookAndFeel) { + Config.getInstance().lookAndFeel = lookAndFeel; + updateTheme(gui); + } + + public static void updateTheme(Gui gui) { + Config config = Config.getInstance(); + config.lookAndFeel.setGlobalLAF(); + config.lookAndFeel.apply(config); + try { + config.saveConfig(); + } catch (IOException e) { + e.printStackTrace(); + } + EnigmaSyntaxKit.invalidate(); + DefaultSyntaxKit.initKit(); + DefaultSyntaxKit.registerContentType("text/enigma-sources", EnigmaSyntaxKit.class.getName()); + gui.boxHighlightPainters = ImmutableMap.of( + TokenHighlightType.OBFUSCATED, BoxHighlightPainter.create(config.obfuscatedColor, config.obfuscatedColorOutline), + TokenHighlightType.PROPOSED, BoxHighlightPainter.create(config.proposedColor, config.proposedColorOutline), + TokenHighlightType.DEOBFUSCATED, BoxHighlightPainter.create(config.deobfuscatedColor, config.deobfuscatedColorOutline) + ); + gui.setEditorTheme(config.lookAndFeel); + SwingUtilities.updateComponentTreeUI(gui.getFrame()); + ScaleUtil.applyScaling(); + } + + } -- cgit v1.2.3