diff options
| -rw-r--r-- | src/main/java/cuchaz/enigma/Main.java | 3 | ||||
| -rw-r--r-- | src/main/java/cuchaz/enigma/config/Config.java | 106 | ||||
| -rw-r--r-- | src/main/java/cuchaz/enigma/config/Themes.java | 49 | ||||
| -rw-r--r-- | src/main/java/cuchaz/enigma/gui/Gui.java | 19 | ||||
| -rw-r--r-- | src/main/java/cuchaz/enigma/gui/elements/MenuBar.java | 24 |
5 files changed, 112 insertions, 89 deletions
diff --git a/src/main/java/cuchaz/enigma/Main.java b/src/main/java/cuchaz/enigma/Main.java index 339b15e0..8c5d813b 100644 --- a/src/main/java/cuchaz/enigma/Main.java +++ b/src/main/java/cuchaz/enigma/Main.java | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | 11 | ||
| 12 | package cuchaz.enigma; | 12 | package cuchaz.enigma; |
| 13 | 13 | ||
| 14 | import cuchaz.enigma.config.Config; | ||
| 14 | import cuchaz.enigma.config.Themes; | 15 | import cuchaz.enigma.config.Themes; |
| 15 | import cuchaz.enigma.gui.Gui; | 16 | import cuchaz.enigma.gui.Gui; |
| 16 | 17 | ||
| @@ -20,8 +21,8 @@ import java.util.jar.JarFile; | |||
| 20 | public class Main { | 21 | public class Main { |
| 21 | 22 | ||
| 22 | public static void main(String[] args) throws Exception { | 23 | public static void main(String[] args) throws Exception { |
| 23 | Themes.setLAF(); | ||
| 24 | Gui gui = new Gui(); | 24 | Gui gui = new Gui(); |
| 25 | Config.LookAndFeel.DEFAULT.setGlobalLAF(); | ||
| 25 | 26 | ||
| 26 | // parse command-line args | 27 | // parse command-line args |
| 27 | if (args.length >= 1) { | 28 | if (args.length >= 1) { |
diff --git a/src/main/java/cuchaz/enigma/config/Config.java b/src/main/java/cuchaz/enigma/config/Config.java index 44414682..034d077c 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 4b1f4784..b3132f24 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 | } |
diff --git a/src/main/java/cuchaz/enigma/gui/Gui.java b/src/main/java/cuchaz/enigma/gui/Gui.java index cac6ca1c..95fde436 100644 --- a/src/main/java/cuchaz/enigma/gui/Gui.java +++ b/src/main/java/cuchaz/enigma/gui/Gui.java | |||
| @@ -16,6 +16,7 @@ import cuchaz.enigma.Constants; | |||
| 16 | import cuchaz.enigma.ExceptionIgnorer; | 16 | import cuchaz.enigma.ExceptionIgnorer; |
| 17 | import cuchaz.enigma.analysis.*; | 17 | import cuchaz.enigma.analysis.*; |
| 18 | import cuchaz.enigma.config.Config; | 18 | import cuchaz.enigma.config.Config; |
| 19 | import cuchaz.enigma.config.Themes; | ||
| 19 | import cuchaz.enigma.gui.dialog.CrashDialog; | 20 | import cuchaz.enigma.gui.dialog.CrashDialog; |
| 20 | import cuchaz.enigma.gui.elements.MenuBar; | 21 | import cuchaz.enigma.gui.elements.MenuBar; |
| 21 | import cuchaz.enigma.gui.elements.PopupMenuBar; | 22 | import cuchaz.enigma.gui.elements.PopupMenuBar; |
| @@ -306,6 +307,9 @@ public class Gui { | |||
| 306 | panel.setLayout(new FlowLayout()); | 307 | panel.setLayout(new FlowLayout()); |
| 307 | panel.add(new JLabel("Loading...")); | 308 | panel.add(new JLabel("Loading...")); |
| 308 | this.classesPanel.add(panel); | 309 | this.classesPanel.add(panel); |
| 310 | |||
| 311 | Themes.updateTheme(this); | ||
| 312 | |||
| 309 | redraw(); | 313 | redraw(); |
| 310 | } | 314 | } |
| 311 | 315 | ||
| @@ -328,6 +332,8 @@ public class Gui { | |||
| 328 | this.menuBar.exportSourceMenu.setEnabled(true); | 332 | this.menuBar.exportSourceMenu.setEnabled(true); |
| 329 | this.menuBar.exportJarMenu.setEnabled(true); | 333 | this.menuBar.exportJarMenu.setEnabled(true); |
| 330 | 334 | ||
| 335 | Themes.updateTheme(this); | ||
| 336 | |||
| 331 | redraw(); | 337 | redraw(); |
| 332 | } | 338 | } |
| 333 | 339 | ||
| @@ -351,6 +357,8 @@ public class Gui { | |||
| 351 | this.menuBar.exportSourceMenu.setEnabled(false); | 357 | this.menuBar.exportSourceMenu.setEnabled(false); |
| 352 | this.menuBar.exportJarMenu.setEnabled(false); | 358 | this.menuBar.exportJarMenu.setEnabled(false); |
| 353 | 359 | ||
| 360 | Themes.updateTheme(this); | ||
| 361 | |||
| 354 | redraw(); | 362 | redraw(); |
| 355 | } | 363 | } |
| 356 | 364 | ||
| @@ -599,6 +607,8 @@ public class Gui { | |||
| 599 | else | 607 | else |
| 600 | text.selectAll(); | 608 | text.selectAll(); |
| 601 | 609 | ||
| 610 | Themes.updateTheme(this); | ||
| 611 | |||
| 602 | redraw(); | 612 | redraw(); |
| 603 | } | 613 | } |
| 604 | 614 | ||
| @@ -654,6 +664,9 @@ public class Gui { | |||
| 654 | } | 664 | } |
| 655 | 665 | ||
| 656 | tabs.setSelectedIndex(0); | 666 | tabs.setSelectedIndex(0); |
| 667 | |||
| 668 | Themes.updateTheme(this); | ||
| 669 | |||
| 657 | redraw(); | 670 | redraw(); |
| 658 | } | 671 | } |
| 659 | 672 | ||
| @@ -683,6 +696,9 @@ public class Gui { | |||
| 683 | } | 696 | } |
| 684 | 697 | ||
| 685 | tabs.setSelectedIndex(1); | 698 | tabs.setSelectedIndex(1); |
| 699 | |||
| 700 | Themes.updateTheme(this); | ||
| 701 | |||
| 686 | redraw(); | 702 | redraw(); |
| 687 | } | 703 | } |
| 688 | 704 | ||
| @@ -703,6 +719,9 @@ public class Gui { | |||
| 703 | } | 719 | } |
| 704 | 720 | ||
| 705 | tabs.setSelectedIndex(2); | 721 | tabs.setSelectedIndex(2); |
| 722 | |||
| 723 | Themes.updateTheme(this); | ||
| 724 | |||
| 706 | redraw(); | 725 | redraw(); |
| 707 | } | 726 | } |
| 708 | 727 | ||
diff --git a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java index 68742f42..609aecb2 100644 --- a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java +++ b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java | |||
| @@ -225,27 +225,11 @@ public class MenuBar extends JMenuBar { | |||
| 225 | { | 225 | { |
| 226 | JMenu themes = new JMenu("Themes"); | 226 | JMenu themes = new JMenu("Themes"); |
| 227 | menu.add(themes); | 227 | menu.add(themes); |
| 228 | { | 228 | for (Config.LookAndFeel lookAndFeel : Config.LookAndFeel.values()) { |
| 229 | JMenuItem defaultTheme = new JMenuItem("Default"); | 229 | JMenuItem theme = new JMenuItem(lookAndFeel.getName()); |
| 230 | themes.add(defaultTheme); | 230 | themes.add(theme); |
| 231 | defaultTheme.addActionListener(event -> Themes.setDefault(gui)); | 231 | theme.addActionListener(event -> Themes.setLookAndFeel(gui, lookAndFeel)); |
| 232 | JMenuItem dark = new JMenuItem("Dank"); | ||
| 233 | themes.add(dark); | ||
| 234 | dark.addActionListener(event -> Themes.setDark(gui)); | ||
| 235 | themes.addSeparator(); | ||
| 236 | JMenuItem refresh = new JMenuItem("Reload From config"); | ||
| 237 | themes.add(refresh); | ||
| 238 | refresh.addActionListener(event -> { | ||
| 239 | try { | ||
| 240 | Config.getInstance().reset(); | ||
| 241 | Config.getInstance().saveConfig(); | ||
| 242 | Themes.updateTheme(gui); | ||
| 243 | } catch (IOException e) { | ||
| 244 | e.printStackTrace(); | ||
| 245 | } | ||
| 246 | }); | ||
| 247 | } | 232 | } |
| 248 | |||
| 249 | } | 233 | } |
| 250 | } | 234 | } |
| 251 | { | 235 | { |