From ca75962a1dd8e5e629d6d4a794d7460dadf430a5 Mon Sep 17 00:00:00 2001 From: asie Date: Wed, 28 Nov 2018 10:11:47 +0100 Subject: refactors and bugfixes --- src/main/java/cuchaz/enigma/config/Config.java | 106 +++++++++++++++++++------ src/main/java/cuchaz/enigma/config/Themes.java | 49 +----------- 2 files changed, 87 insertions(+), 68 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 4441468..034d077 100644 --- a/src/main/java/cuchaz/enigma/config/Config.java +++ b/src/main/java/cuchaz/enigma/config/Config.java @@ -1,14 +1,94 @@ package cuchaz.enigma.config; +import com.bulenkov.darcula.DarculaLaf; import com.google.common.io.Files; import com.google.gson.*; +import javax.swing.*; +import javax.swing.plaf.metal.MetalLookAndFeel; import java.io.File; import java.io.IOException; import java.lang.reflect.Type; import java.nio.charset.Charset; public class Config { + public enum LookAndFeel { + DEFAULT("Default"), + DARCULA("Dank"); + + private final String name; + + LookAndFeel(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setGlobalLAF() { + try { + switch (this) { + case DEFAULT: + UIManager.setLookAndFeel(new MetalLookAndFeel()); + break; + case DARCULA: + UIManager.setLookAndFeel(new DarculaLaf()); + break; + } + } catch (Exception e){ + throw new Error("Failed to set global look and feel", e); + } + } + + public void apply(Config config) { + switch (this) { + case DEFAULT: + config.obfuscatedColor = 0xFFDCDC; + config.obfuscatedHiglightAlpha = 1.0F; + config.obfuscatedColorOutline = 0xA05050; + config.obfuscatedOutlineAlpha = 1.0F; + config.deobfuscatedColor = 0xDCFFDC; + config.deobfuscatedHiglightAlpha = 1.0F; + config.deobfuscatedColorOutline = 0x50A050; + config.deobfuscatedOutlineAlpha = 1.0F; + config.otherColorOutline = 0xB4B4B4; + config.otherOutlineAlpha = 1.0F; + config.editorBackground = 0xFFFFFF; + config.highlightColor = 0x3333EE; + config.stringColor = 0xCC6600; + config.numberColor = 0x999933; + config.operatorColor = 0x000000; + config.delimiterColor = 0x000000; + config.typeColor = 0x000000; + config.identifierColor = 0x000000; + config.defaultTextColor = 0x000000; + break; + case DARCULA: + //Based off colors found here: https://github.com/dracula/dracula-theme/ + config.obfuscatedColor = 0xFF5555; + config.obfuscatedHiglightAlpha = 0.3F; + config.obfuscatedColorOutline = 0xFF5555; + config.obfuscatedOutlineAlpha = 0.5F; + config.deobfuscatedColor = 0x50FA7B; + config.deobfuscatedHiglightAlpha = 0.3F; + config.deobfuscatedColorOutline = 0x50FA7B; + config.deobfuscatedOutlineAlpha = 0.5F; + config.otherColorOutline = 0xB4B4B4; + config.otherOutlineAlpha = 0.0F; + config.editorBackground = 0x282A36; + config.highlightColor = 0xFF79C6; + config.stringColor = 0xF1FA8C; + config.numberColor = 0xBD93F9; + config.operatorColor = 0xF8F8F2; + config.delimiterColor = 0xF8F8F2; + config.typeColor = 0xF8F8F2; + config.identifierColor = 0xF8F8F2; + config.defaultTextColor = 0xF8F8F2; + break; + } + } + } private static final File DIR_HOME = new File(System.getProperty("user.home")); private static final File ENIGMA_DIR = new File(DIR_HOME, ".enigma"); @@ -40,8 +120,7 @@ public class Config { public Integer identifierColor; public Integer defaultTextColor; - public boolean useSystemLAF; - public boolean useDraculaLAF; + public LookAndFeel lookAndFeel = LookAndFeel.DEFAULT; private Config() { gson = new GsonBuilder() @@ -76,27 +155,8 @@ public class Config { } public void reset() throws IOException { - this.obfuscatedColor = 0xFFDCDC; - this.obfuscatedHiglightAlpha = 1.0F; - this.obfuscatedColorOutline = 0xA05050; - this.obfuscatedOutlineAlpha = 1.0F; - this.deobfuscatedColor = 0xDCFFDC; - this.deobfuscatedHiglightAlpha = 1.0F; - this.deobfuscatedColorOutline = 0x50A050; - this.deobfuscatedOutlineAlpha = 1.0F; - this.otherColorOutline = 0xB4B4B4; - this.otherOutlineAlpha = 1.0F; - this.editorBackground = 0xFFFFFF; - this.highlightColor = 0x3333EE; - this.stringColor = 0xCC6600; - this.numberColor = 0x999933; - this.operatorColor = 0x000000; - this.delimiterColor = 0x000000; - this.typeColor = 0x000000; - this.identifierColor = 0x000000; - this.defaultTextColor = 0x000000; - this.useSystemLAF = true; - this.useDraculaLAF = false; + this.lookAndFeel = LookAndFeel.DEFAULT; + this.lookAndFeel.apply(this); this.saveConfig(); } diff --git a/src/main/java/cuchaz/enigma/config/Themes.java b/src/main/java/cuchaz/enigma/config/Themes.java index 4b1f478..b3132f2 100644 --- a/src/main/java/cuchaz/enigma/config/Themes.java +++ b/src/main/java/cuchaz/enigma/config/Themes.java @@ -14,42 +14,14 @@ import java.io.IOException; public class Themes { - public static void setDefault(Gui gui) { - // TODO set to default - try { - Config.getInstance().reset(); - } catch (IOException e) { - e.printStackTrace(); - } + public static void setLookAndFeel(Gui gui, Config.LookAndFeel lookAndFeel) { + Config.getInstance().lookAndFeel = lookAndFeel; updateTheme(gui); } - public static void setDark(Gui gui) { - //Based off colors found here: https://github.com/dracula/dracula-theme/ - Config.getInstance().obfuscatedColor = 0xFF5555; - Config.getInstance().obfuscatedHiglightAlpha = 0.3F; - Config.getInstance().obfuscatedColorOutline = 0xFF5555; - Config.getInstance().obfuscatedOutlineAlpha = 0.5F; - Config.getInstance().deobfuscatedColor = 0x50FA7B; - Config.getInstance().deobfuscatedHiglightAlpha = 0.3F; - Config.getInstance().deobfuscatedColorOutline = 0x50FA7B; - Config.getInstance().deobfuscatedOutlineAlpha = 0.5F; - Config.getInstance().otherColorOutline = 0xB4B4B4; - Config.getInstance().otherOutlineAlpha = 0.0F; - Config.getInstance().editorBackground = 0x282A36; - Config.getInstance().highlightColor = 0xFF79C6; - Config.getInstance().stringColor = 0xF1FA8C; - Config.getInstance().numberColor = 0xBD93F9; - Config.getInstance().operatorColor = 0xF8F8F2; - Config.getInstance().delimiterColor = 0xF8F8F2; - Config.getInstance().typeColor = 0xF8F8F2; - Config.getInstance().identifierColor = 0xF8F8F2; - Config.getInstance().defaultTextColor = 0xF8F8F2; - Config.getInstance().useDraculaLAF = true; - updateTheme(gui); - } - public static void updateTheme(Gui gui) { + Config.getInstance().lookAndFeel.apply(Config.getInstance()); + Config.getInstance().lookAndFeel.setGlobalLAF(); try { Config.getInstance().saveConfig(); } catch (IOException e) { @@ -63,20 +35,7 @@ public class Themes { gui.otherHighlightPainter = new OtherHighlightPainter(); gui.editor.updateUI(); gui.editor.setBackground(new Color(Config.getInstance().editorBackground)); - setLAF(); SwingUtilities.updateComponentTreeUI(gui.getFrame()); gui.getController().refreshCurrentClass(); } - - public static void setLAF(){ - try { - if (Config.getInstance().useDraculaLAF){ - UIManager.setLookAndFeel(new DarculaLaf()); - } else if (Config.getInstance().useSystemLAF) - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } catch (Exception e){ - throw new Error("Failed to set LAF", e); - } - } - } -- cgit v1.2.3