diff options
| author | 2018-11-28 10:11:47 +0100 | |
|---|---|---|
| committer | 2018-11-28 10:11:47 +0100 | |
| commit | ca75962a1dd8e5e629d6d4a794d7460dadf430a5 (patch) | |
| tree | 72c597c69809e1bf5765b21c3ab1756c1cf1c6b4 /src/main/java/cuchaz/enigma/config | |
| parent | Move to awt FileDialog (diff) | |
| download | enigma-fork-ca75962a1dd8e5e629d6d4a794d7460dadf430a5.tar.gz enigma-fork-ca75962a1dd8e5e629d6d4a794d7460dadf430a5.tar.xz enigma-fork-ca75962a1dd8e5e629d6d4a794d7460dadf430a5.zip | |
refactors and bugfixes
Diffstat (limited to 'src/main/java/cuchaz/enigma/config')
| -rw-r--r-- | src/main/java/cuchaz/enigma/config/Config.java | 106 | ||||
| -rw-r--r-- | src/main/java/cuchaz/enigma/config/Themes.java | 49 |
2 files changed, 87 insertions, 68 deletions
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 @@ | |||
| 1 | package cuchaz.enigma.config; | 1 | package cuchaz.enigma.config; |
| 2 | 2 | ||
| 3 | import com.bulenkov.darcula.DarculaLaf; | ||
| 3 | import com.google.common.io.Files; | 4 | import com.google.common.io.Files; |
| 4 | import com.google.gson.*; | 5 | import com.google.gson.*; |
| 5 | 6 | ||
| 7 | import javax.swing.*; | ||
| 8 | import javax.swing.plaf.metal.MetalLookAndFeel; | ||
| 6 | import java.io.File; | 9 | import java.io.File; |
| 7 | import java.io.IOException; | 10 | import java.io.IOException; |
| 8 | import java.lang.reflect.Type; | 11 | import java.lang.reflect.Type; |
| 9 | import java.nio.charset.Charset; | 12 | import java.nio.charset.Charset; |
| 10 | 13 | ||
| 11 | public class Config { | 14 | public class Config { |
| 15 | public enum LookAndFeel { | ||
| 16 | DEFAULT("Default"), | ||
| 17 | DARCULA("Dank"); | ||
| 18 | |||
| 19 | private final String name; | ||
| 20 | |||
| 21 | LookAndFeel(String name) { | ||
| 22 | this.name = name; | ||
| 23 | } | ||
| 24 | |||
| 25 | public String getName() { | ||
| 26 | return name; | ||
| 27 | } | ||
| 28 | |||
| 29 | public void setGlobalLAF() { | ||
| 30 | try { | ||
| 31 | switch (this) { | ||
| 32 | case DEFAULT: | ||
| 33 | UIManager.setLookAndFeel(new MetalLookAndFeel()); | ||
| 34 | break; | ||
| 35 | case DARCULA: | ||
| 36 | UIManager.setLookAndFeel(new DarculaLaf()); | ||
| 37 | break; | ||
| 38 | } | ||
| 39 | } catch (Exception e){ | ||
| 40 | throw new Error("Failed to set global look and feel", e); | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | public void apply(Config config) { | ||
| 45 | switch (this) { | ||
| 46 | case DEFAULT: | ||
| 47 | config.obfuscatedColor = 0xFFDCDC; | ||
| 48 | config.obfuscatedHiglightAlpha = 1.0F; | ||
| 49 | config.obfuscatedColorOutline = 0xA05050; | ||
| 50 | config.obfuscatedOutlineAlpha = 1.0F; | ||
| 51 | config.deobfuscatedColor = 0xDCFFDC; | ||
| 52 | config.deobfuscatedHiglightAlpha = 1.0F; | ||
| 53 | config.deobfuscatedColorOutline = 0x50A050; | ||
| 54 | config.deobfuscatedOutlineAlpha = 1.0F; | ||
| 55 | config.otherColorOutline = 0xB4B4B4; | ||
| 56 | config.otherOutlineAlpha = 1.0F; | ||
| 57 | config.editorBackground = 0xFFFFFF; | ||
| 58 | config.highlightColor = 0x3333EE; | ||
| 59 | config.stringColor = 0xCC6600; | ||
| 60 | config.numberColor = 0x999933; | ||
| 61 | config.operatorColor = 0x000000; | ||
| 62 | config.delimiterColor = 0x000000; | ||
| 63 | config.typeColor = 0x000000; | ||
| 64 | config.identifierColor = 0x000000; | ||
| 65 | config.defaultTextColor = 0x000000; | ||
| 66 | break; | ||
| 67 | case DARCULA: | ||
| 68 | //Based off colors found here: https://github.com/dracula/dracula-theme/ | ||
| 69 | config.obfuscatedColor = 0xFF5555; | ||
| 70 | config.obfuscatedHiglightAlpha = 0.3F; | ||
| 71 | config.obfuscatedColorOutline = 0xFF5555; | ||
| 72 | config.obfuscatedOutlineAlpha = 0.5F; | ||
| 73 | config.deobfuscatedColor = 0x50FA7B; | ||
| 74 | config.deobfuscatedHiglightAlpha = 0.3F; | ||
| 75 | config.deobfuscatedColorOutline = 0x50FA7B; | ||
| 76 | config.deobfuscatedOutlineAlpha = 0.5F; | ||
| 77 | config.otherColorOutline = 0xB4B4B4; | ||
| 78 | config.otherOutlineAlpha = 0.0F; | ||
| 79 | config.editorBackground = 0x282A36; | ||
| 80 | config.highlightColor = 0xFF79C6; | ||
| 81 | config.stringColor = 0xF1FA8C; | ||
| 82 | config.numberColor = 0xBD93F9; | ||
| 83 | config.operatorColor = 0xF8F8F2; | ||
| 84 | config.delimiterColor = 0xF8F8F2; | ||
| 85 | config.typeColor = 0xF8F8F2; | ||
| 86 | config.identifierColor = 0xF8F8F2; | ||
| 87 | config.defaultTextColor = 0xF8F8F2; | ||
| 88 | break; | ||
| 89 | } | ||
| 90 | } | ||
| 91 | } | ||
| 12 | 92 | ||
| 13 | private static final File DIR_HOME = new File(System.getProperty("user.home")); | 93 | private static final File DIR_HOME = new File(System.getProperty("user.home")); |
| 14 | private static final File ENIGMA_DIR = new File(DIR_HOME, ".enigma"); | 94 | private static final File ENIGMA_DIR = new File(DIR_HOME, ".enigma"); |
| @@ -40,8 +120,7 @@ public class Config { | |||
| 40 | public Integer identifierColor; | 120 | public Integer identifierColor; |
| 41 | public Integer defaultTextColor; | 121 | public Integer defaultTextColor; |
| 42 | 122 | ||
| 43 | public boolean useSystemLAF; | 123 | public LookAndFeel lookAndFeel = LookAndFeel.DEFAULT; |
| 44 | public boolean useDraculaLAF; | ||
| 45 | 124 | ||
| 46 | private Config() { | 125 | private Config() { |
| 47 | gson = new GsonBuilder() | 126 | gson = new GsonBuilder() |
| @@ -76,27 +155,8 @@ public class Config { | |||
| 76 | } | 155 | } |
| 77 | 156 | ||
| 78 | public void reset() throws IOException { | 157 | public void reset() throws IOException { |
| 79 | this.obfuscatedColor = 0xFFDCDC; | 158 | this.lookAndFeel = LookAndFeel.DEFAULT; |
| 80 | this.obfuscatedHiglightAlpha = 1.0F; | 159 | this.lookAndFeel.apply(this); |
| 81 | this.obfuscatedColorOutline = 0xA05050; | ||
| 82 | this.obfuscatedOutlineAlpha = 1.0F; | ||
| 83 | this.deobfuscatedColor = 0xDCFFDC; | ||
| 84 | this.deobfuscatedHiglightAlpha = 1.0F; | ||
| 85 | this.deobfuscatedColorOutline = 0x50A050; | ||
| 86 | this.deobfuscatedOutlineAlpha = 1.0F; | ||
| 87 | this.otherColorOutline = 0xB4B4B4; | ||
| 88 | this.otherOutlineAlpha = 1.0F; | ||
| 89 | this.editorBackground = 0xFFFFFF; | ||
| 90 | this.highlightColor = 0x3333EE; | ||
| 91 | this.stringColor = 0xCC6600; | ||
| 92 | this.numberColor = 0x999933; | ||
| 93 | this.operatorColor = 0x000000; | ||
| 94 | this.delimiterColor = 0x000000; | ||
| 95 | this.typeColor = 0x000000; | ||
| 96 | this.identifierColor = 0x000000; | ||
| 97 | this.defaultTextColor = 0x000000; | ||
| 98 | this.useSystemLAF = true; | ||
| 99 | this.useDraculaLAF = false; | ||
| 100 | this.saveConfig(); | 160 | this.saveConfig(); |
| 101 | } | 161 | } |
| 102 | 162 | ||
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; | |||
| 14 | 14 | ||
| 15 | public class Themes { | 15 | public class Themes { |
| 16 | 16 | ||
| 17 | public static void setDefault(Gui gui) { | 17 | public static void setLookAndFeel(Gui gui, Config.LookAndFeel lookAndFeel) { |
| 18 | // TODO set to default | 18 | Config.getInstance().lookAndFeel = lookAndFeel; |
| 19 | try { | ||
| 20 | Config.getInstance().reset(); | ||
| 21 | } catch (IOException e) { | ||
| 22 | e.printStackTrace(); | ||
| 23 | } | ||
| 24 | updateTheme(gui); | 19 | updateTheme(gui); |
| 25 | } | 20 | } |
| 26 | 21 | ||
| 27 | public static void setDark(Gui gui) { | ||
| 28 | //Based off colors found here: https://github.com/dracula/dracula-theme/ | ||
| 29 | Config.getInstance().obfuscatedColor = 0xFF5555; | ||
| 30 | Config.getInstance().obfuscatedHiglightAlpha = 0.3F; | ||
| 31 | Config.getInstance().obfuscatedColorOutline = 0xFF5555; | ||
| 32 | Config.getInstance().obfuscatedOutlineAlpha = 0.5F; | ||
| 33 | Config.getInstance().deobfuscatedColor = 0x50FA7B; | ||
| 34 | Config.getInstance().deobfuscatedHiglightAlpha = 0.3F; | ||
| 35 | Config.getInstance().deobfuscatedColorOutline = 0x50FA7B; | ||
| 36 | Config.getInstance().deobfuscatedOutlineAlpha = 0.5F; | ||
| 37 | Config.getInstance().otherColorOutline = 0xB4B4B4; | ||
| 38 | Config.getInstance().otherOutlineAlpha = 0.0F; | ||
| 39 | Config.getInstance().editorBackground = 0x282A36; | ||
| 40 | Config.getInstance().highlightColor = 0xFF79C6; | ||
| 41 | Config.getInstance().stringColor = 0xF1FA8C; | ||
| 42 | Config.getInstance().numberColor = 0xBD93F9; | ||
| 43 | Config.getInstance().operatorColor = 0xF8F8F2; | ||
| 44 | Config.getInstance().delimiterColor = 0xF8F8F2; | ||
| 45 | Config.getInstance().typeColor = 0xF8F8F2; | ||
| 46 | Config.getInstance().identifierColor = 0xF8F8F2; | ||
| 47 | Config.getInstance().defaultTextColor = 0xF8F8F2; | ||
| 48 | Config.getInstance().useDraculaLAF = true; | ||
| 49 | updateTheme(gui); | ||
| 50 | } | ||
| 51 | |||
| 52 | public static void updateTheme(Gui gui) { | 22 | public static void updateTheme(Gui gui) { |
| 23 | Config.getInstance().lookAndFeel.apply(Config.getInstance()); | ||
| 24 | Config.getInstance().lookAndFeel.setGlobalLAF(); | ||
| 53 | try { | 25 | try { |
| 54 | Config.getInstance().saveConfig(); | 26 | Config.getInstance().saveConfig(); |
| 55 | } catch (IOException e) { | 27 | } catch (IOException e) { |
| @@ -63,20 +35,7 @@ public class Themes { | |||
| 63 | gui.otherHighlightPainter = new OtherHighlightPainter(); | 35 | gui.otherHighlightPainter = new OtherHighlightPainter(); |
| 64 | gui.editor.updateUI(); | 36 | gui.editor.updateUI(); |
| 65 | gui.editor.setBackground(new Color(Config.getInstance().editorBackground)); | 37 | gui.editor.setBackground(new Color(Config.getInstance().editorBackground)); |
| 66 | setLAF(); | ||
| 67 | SwingUtilities.updateComponentTreeUI(gui.getFrame()); | 38 | SwingUtilities.updateComponentTreeUI(gui.getFrame()); |
| 68 | gui.getController().refreshCurrentClass(); | 39 | gui.getController().refreshCurrentClass(); |
| 69 | } | 40 | } |
| 70 | |||
| 71 | public static void setLAF(){ | ||
| 72 | try { | ||
| 73 | if (Config.getInstance().useDraculaLAF){ | ||
| 74 | UIManager.setLookAndFeel(new DarculaLaf()); | ||
| 75 | } else if (Config.getInstance().useSystemLAF) | ||
| 76 | UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | ||
| 77 | } catch (Exception e){ | ||
| 78 | throw new Error("Failed to set LAF", e); | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | } | 41 | } |