diff options
| author | 2020-04-24 18:39:57 +0200 | |
|---|---|---|
| committer | 2020-04-24 17:39:57 +0100 | |
| commit | 04b01512c124c76f3b3d99ba07ef30ea6a90b52f (patch) | |
| tree | 33ffbe9fba1fd762cc7a7997db9764b181f29d7b /src/main/java/cuchaz/enigma/config | |
| parent | Update darcula to fix dark theme (diff) | |
| download | enigma-fork-04b01512c124c76f3b3d99ba07ef30ea6a90b52f.tar.gz enigma-fork-04b01512c124c76f3b3d99ba07ef30ea6a90b52f.tar.xz enigma-fork-04b01512c124c76f3b3d99ba07ef30ea6a90b52f.zip | |
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 <modmuss50@gmail.com>
Diffstat (limited to 'src/main/java/cuchaz/enigma/config')
| -rw-r--r-- | src/main/java/cuchaz/enigma/config/Config.java | 5 | ||||
| -rw-r--r-- | src/main/java/cuchaz/enigma/config/Themes.java | 66 |
2 files changed, 41 insertions, 30 deletions
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; | |||
| 7 | import cuchaz.enigma.source.Decompilers; | 7 | import cuchaz.enigma.source.Decompilers; |
| 8 | 8 | ||
| 9 | import cuchaz.enigma.utils.I18n; | 9 | import cuchaz.enigma.utils.I18n; |
| 10 | import cuchaz.enigma.gui.util.ScaleUtil; | ||
| 10 | 11 | ||
| 11 | import javax.swing.*; | 12 | import javax.swing.*; |
| 12 | import javax.swing.plaf.metal.MetalLookAndFeel; | 13 | import javax.swing.plaf.metal.MetalLookAndFeel; |
| @@ -78,7 +79,7 @@ public class Config { | |||
| 78 | public static boolean isDarkLaf() { | 79 | public static boolean isDarkLaf() { |
| 79 | // 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 | 80 | // 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 |
| 80 | JPanel panel = new JPanel(); | 81 | JPanel panel = new JPanel(); |
| 81 | panel.setSize(new Dimension(10, 10)); | 82 | panel.setSize(ScaleUtil.getDimension(10, 10)); |
| 82 | panel.doLayout(); | 83 | panel.doLayout(); |
| 83 | 84 | ||
| 84 | BufferedImage image = new BufferedImage(panel.getSize().width, panel.getSize().height, BufferedImage.TYPE_INT_RGB); | 85 | BufferedImage image = new BufferedImage(panel.getSize().width, panel.getSize().height, BufferedImage.TYPE_INT_RGB); |
| @@ -187,6 +188,8 @@ public class Config { | |||
| 187 | 188 | ||
| 188 | public LookAndFeel lookAndFeel = LookAndFeel.DEFAULT; | 189 | public LookAndFeel lookAndFeel = LookAndFeel.DEFAULT; |
| 189 | 190 | ||
| 191 | public float scaleFactor = 1.0f; | ||
| 192 | |||
| 190 | public Decompiler decompiler = Decompiler.PROCYON; | 193 | public Decompiler decompiler = Decompiler.PROCYON; |
| 191 | 194 | ||
| 192 | private Config() { | 195 | 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 @@ | |||
| 1 | package cuchaz.enigma.config; | 1 | package cuchaz.enigma.config; |
| 2 | 2 | ||
| 3 | import java.awt.Font; | ||
| 4 | import java.io.IOException; | ||
| 5 | import java.lang.reflect.Field; | ||
| 6 | |||
| 7 | import javax.swing.SwingUtilities; | ||
| 8 | |||
| 9 | import com.github.swingdpi.UiDefaultsScaler; | ||
| 3 | import com.google.common.collect.ImmutableMap; | 10 | import com.google.common.collect.ImmutableMap; |
| 4 | import cuchaz.enigma.gui.Gui; | ||
| 5 | import cuchaz.enigma.gui.EnigmaSyntaxKit; | 11 | import cuchaz.enigma.gui.EnigmaSyntaxKit; |
| 12 | import cuchaz.enigma.gui.Gui; | ||
| 6 | import cuchaz.enigma.gui.highlight.BoxHighlightPainter; | 13 | import cuchaz.enigma.gui.highlight.BoxHighlightPainter; |
| 7 | import cuchaz.enigma.gui.highlight.TokenHighlightType; | 14 | import cuchaz.enigma.gui.highlight.TokenHighlightType; |
| 15 | import cuchaz.enigma.gui.util.ScaleUtil; | ||
| 8 | import de.sciss.syntaxpane.DefaultSyntaxKit; | 16 | import de.sciss.syntaxpane.DefaultSyntaxKit; |
| 9 | 17 | ||
| 10 | import javax.swing.*; | ||
| 11 | import java.io.IOException; | ||
| 12 | |||
| 13 | public class Themes { | 18 | public class Themes { |
| 14 | 19 | ||
| 15 | public static void setLookAndFeel(Gui gui, Config.LookAndFeel lookAndFeel) { | 20 | public static void setLookAndFeel(Gui gui, Config.LookAndFeel lookAndFeel) { |
| 16 | Config.getInstance().lookAndFeel = lookAndFeel; | 21 | Config.getInstance().lookAndFeel = lookAndFeel; |
| 17 | updateTheme(gui); | 22 | updateTheme(gui); |
| 18 | } | 23 | } |
| 19 | 24 | ||
| 20 | public static void updateTheme(Gui gui) { | 25 | public static void updateTheme(Gui gui) { |
| 21 | Config config = Config.getInstance(); | 26 | Config config = Config.getInstance(); |
| 22 | config.lookAndFeel.setGlobalLAF(); | 27 | config.lookAndFeel.setGlobalLAF(); |
| 23 | config.lookAndFeel.apply(config); | 28 | config.lookAndFeel.apply(config); |
| 24 | try { | 29 | try { |
| 25 | config.saveConfig(); | 30 | config.saveConfig(); |
| 26 | } catch (IOException e) { | 31 | } catch (IOException e) { |
| 27 | e.printStackTrace(); | 32 | e.printStackTrace(); |
| 28 | } | 33 | } |
| 29 | EnigmaSyntaxKit.invalidate(); | 34 | EnigmaSyntaxKit.invalidate(); |
| 30 | DefaultSyntaxKit.initKit(); | 35 | DefaultSyntaxKit.initKit(); |
| 31 | DefaultSyntaxKit.registerContentType("text/enigma-sources", EnigmaSyntaxKit.class.getName()); | 36 | DefaultSyntaxKit.registerContentType("text/enigma-sources", EnigmaSyntaxKit.class.getName()); |
| 32 | gui.boxHighlightPainters = ImmutableMap.of( | 37 | gui.boxHighlightPainters = ImmutableMap.of( |
| 33 | TokenHighlightType.OBFUSCATED, BoxHighlightPainter.create(config.obfuscatedColor, config.obfuscatedColorOutline), | 38 | TokenHighlightType.OBFUSCATED, BoxHighlightPainter.create(config.obfuscatedColor, config.obfuscatedColorOutline), |
| 34 | TokenHighlightType.PROPOSED, BoxHighlightPainter.create(config.proposedColor, config.proposedColorOutline), | 39 | TokenHighlightType.PROPOSED, BoxHighlightPainter.create(config.proposedColor, config.proposedColorOutline), |
| 35 | TokenHighlightType.DEOBFUSCATED, BoxHighlightPainter.create(config.deobfuscatedColor, config.deobfuscatedColorOutline) | 40 | TokenHighlightType.DEOBFUSCATED, BoxHighlightPainter.create(config.deobfuscatedColor, config.deobfuscatedColorOutline) |
| 36 | ); | 41 | ); |
| 37 | gui.setEditorTheme(config.lookAndFeel); | 42 | gui.setEditorTheme(config.lookAndFeel); |
| 38 | SwingUtilities.updateComponentTreeUI(gui.getFrame()); | 43 | SwingUtilities.updateComponentTreeUI(gui.getFrame()); |
| 39 | } | 44 | ScaleUtil.applyScaling(); |
| 45 | } | ||
| 46 | |||
| 47 | |||
| 40 | } | 48 | } |