diff options
| author | 2017-06-04 16:36:21 +0100 | |
|---|---|---|
| committer | 2017-06-04 17:36:21 +0200 | |
| commit | e35b611da3c068bfea344be9a90c79fd68fac4ff (patch) | |
| tree | f0bf3d9a2fd6ebef0a38e771f5799c249cd81b92 | |
| parent | Remove the converter + some reorganization (diff) | |
| download | enigma-e35b611da3c068bfea344be9a90c79fd68fac4ff.tar.gz enigma-e35b611da3c068bfea344be9a90c79fd68fac4ff.tar.xz enigma-e35b611da3c068bfea344be9a90c79fd68fac4ff.zip | |
Add support for custom themes (#59)
9 files changed, 132 insertions, 10 deletions
diff --git a/build.gradle b/build.gradle index ce19a4c7..c1ec0252 100644 --- a/build.gradle +++ b/build.gradle | |||
| @@ -67,6 +67,8 @@ dependencies { | |||
| 67 | compile 'com.google.guava:guava:21.+' | 67 | compile 'com.google.guava:guava:21.+' |
| 68 | compile 'org.javassist:javassist:3.21.0-GA' | 68 | compile 'org.javassist:javassist:3.21.0-GA' |
| 69 | compile 'org.bitbucket.mstrobel:procyon-compilertools:0.5.33.8-enigma' | 69 | compile 'org.bitbucket.mstrobel:procyon-compilertools:0.5.33.8-enigma' |
| 70 | compile 'com.google.code.gson:gson:2.8.1' | ||
| 71 | |||
| 70 | 72 | ||
| 71 | application 'de.sciss:syntaxpane:1.1.+' | 73 | application 'de.sciss:syntaxpane:1.1.+' |
| 72 | 74 | ||
diff --git a/src/main/java/cuchaz/enigma/Main.java b/src/main/java/cuchaz/enigma/Main.java index fa8d0622..9f34cd3c 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.gui.Gui; | 15 | import cuchaz.enigma.gui.Gui; |
| 15 | 16 | ||
| 16 | import javax.swing.*; | 17 | import javax.swing.*; |
| @@ -20,7 +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 | if (System.getProperty("enigma.useSystemLookAndFeel", "true").equals("true")) | 24 | Config.loadConfig(); |
| 25 | if (Config.INSTANCE.useSystemLAF) | ||
| 24 | UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | 26 | UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
| 25 | Gui gui = new Gui(); | 27 | Gui gui = new Gui(); |
| 26 | 28 | ||
diff --git a/src/main/java/cuchaz/enigma/config/Config.java b/src/main/java/cuchaz/enigma/config/Config.java new file mode 100644 index 00000000..307b221d --- /dev/null +++ b/src/main/java/cuchaz/enigma/config/Config.java | |||
| @@ -0,0 +1,72 @@ | |||
| 1 | package cuchaz.enigma.config; | ||
| 2 | |||
| 3 | import com.google.common.io.Files; | ||
| 4 | import com.google.gson.*; | ||
| 5 | |||
| 6 | import java.io.File; | ||
| 7 | import java.io.IOException; | ||
| 8 | import java.lang.reflect.Type; | ||
| 9 | import java.nio.charset.Charset; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * Created by Mark on 04/06/2017. | ||
| 13 | */ | ||
| 14 | public class Config { | ||
| 15 | |||
| 16 | public static Config INSTANCE = new Config(); | ||
| 17 | |||
| 18 | public Integer obfuscatedColor = 0xFFDCDC; | ||
| 19 | public float obfuscatedHiglightAlpha = 1.0F; | ||
| 20 | public Integer obfuscatedColorOutline = 0xA05050; | ||
| 21 | public float obfuscatedOutlineAlpha = 1.0F; | ||
| 22 | |||
| 23 | public Integer deobfuscatedColor = 0xDCFFDC; | ||
| 24 | public float deobfuscatedHiglightAlpha = 1.0F; | ||
| 25 | public Integer deobfuscatedColorOutline = 0x50A050; | ||
| 26 | public float deobfuscatedOutlineAlpha = 1.0F; | ||
| 27 | |||
| 28 | public Integer otherColorOutline = 0xB4B4B4; | ||
| 29 | public float otherOutlineAlpha = 1.0F; | ||
| 30 | |||
| 31 | //Defaults found here: https://github.com/Sciss/SyntaxPane/blob/122da367ff7a5d31627a70c62a48a9f0f4f85a0a/src/main/resources/de/sciss/syntaxpane/defaultsyntaxkit/config.properties#L139 | ||
| 32 | public Integer editorBackground = 0xFFFFFF; | ||
| 33 | public Integer highlightColor = 0x3333EE; | ||
| 34 | public Integer stringColor = 0xCC6600; | ||
| 35 | public Integer numberColor = 0x999933; | ||
| 36 | public Integer operatorColor = 0x000000; | ||
| 37 | public Integer delimiterColor = 0x000000; | ||
| 38 | public Integer typeColor = 0x000000; | ||
| 39 | public Integer identifierColor = 0x000000; | ||
| 40 | public Integer defaultTextColor = 0x000000; | ||
| 41 | |||
| 42 | public boolean useSystemLAF = true; | ||
| 43 | |||
| 44 | public static void loadConfig() throws IOException { | ||
| 45 | Gson gson = new GsonBuilder().registerTypeAdapter(Integer.class, new IntSerializer()).registerTypeAdapter(Integer.class, new IntDeserializer()).setPrettyPrinting().create(); | ||
| 46 | File dirHome = new File(System.getProperty("user.home")); | ||
| 47 | File engimaDir = new File(dirHome, ".enigma"); | ||
| 48 | if(!engimaDir.exists()){ | ||
| 49 | engimaDir.mkdirs(); | ||
| 50 | } | ||
| 51 | File configFile = new File(engimaDir, "config.json"); | ||
| 52 | if (configFile.exists()) { | ||
| 53 | INSTANCE = gson.fromJson(Files.toString(configFile, Charset.defaultCharset()), Config.class); | ||
| 54 | } else { | ||
| 55 | Files.touch(configFile); | ||
| 56 | } | ||
| 57 | Files.write(gson.toJson(INSTANCE), configFile, Charset.defaultCharset()); | ||
| 58 | } | ||
| 59 | |||
| 60 | private static class IntSerializer implements JsonSerializer<Integer> { | ||
| 61 | public JsonElement serialize(Integer src, Type typeOfSrc, JsonSerializationContext context) { | ||
| 62 | return new JsonPrimitive("#" + Integer.toHexString(src).toUpperCase()); | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | private static class IntDeserializer implements JsonDeserializer<Integer> { | ||
| 67 | public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { | ||
| 68 | return (int) Long.parseLong(json.getAsString().replace("#", ""), 16); | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | } | ||
diff --git a/src/main/java/cuchaz/enigma/gui/Gui.java b/src/main/java/cuchaz/enigma/gui/Gui.java index 77065a90..86c97aa3 100644 --- a/src/main/java/cuchaz/enigma/gui/Gui.java +++ b/src/main/java/cuchaz/enigma/gui/Gui.java | |||
| @@ -15,6 +15,7 @@ import com.google.common.collect.Lists; | |||
| 15 | import cuchaz.enigma.Constants; | 15 | 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.gui.dialog.CrashDialog; | 19 | import cuchaz.enigma.gui.dialog.CrashDialog; |
| 19 | import cuchaz.enigma.gui.elements.MenuBar; | 20 | import cuchaz.enigma.gui.elements.MenuBar; |
| 20 | import cuchaz.enigma.gui.elements.PopupMenuBar; | 21 | import cuchaz.enigma.gui.elements.PopupMenuBar; |
| @@ -47,10 +48,8 @@ import java.awt.*; | |||
| 47 | import java.awt.event.*; | 48 | import java.awt.event.*; |
| 48 | import java.io.File; | 49 | import java.io.File; |
| 49 | import java.io.IOException; | 50 | import java.io.IOException; |
| 50 | import java.util.Collection; | 51 | import java.util.*; |
| 51 | import java.util.Collections; | ||
| 52 | import java.util.List; | 52 | import java.util.List; |
| 53 | import java.util.Vector; | ||
| 54 | import java.util.function.Function; | 53 | import java.util.function.Function; |
| 55 | 54 | ||
| 56 | public class Gui { | 55 | public class Gui { |
| @@ -127,13 +126,15 @@ public class Gui { | |||
| 127 | 126 | ||
| 128 | // init editor | 127 | // init editor |
| 129 | DefaultSyntaxKit.initKit(); | 128 | DefaultSyntaxKit.initKit(); |
| 129 | DefaultSyntaxKit.registerContentType("text/minecraft", MinecraftSyntaxKit.class.getName()); | ||
| 130 | obfuscatedHighlightPainter = new ObfuscatedHighlightPainter(); | 130 | obfuscatedHighlightPainter = new ObfuscatedHighlightPainter(); |
| 131 | deobfuscatedHighlightPainter = new DeobfuscatedHighlightPainter(); | 131 | deobfuscatedHighlightPainter = new DeobfuscatedHighlightPainter(); |
| 132 | otherHighlightPainter = new OtherHighlightPainter(); | 132 | otherHighlightPainter = new OtherHighlightPainter(); |
| 133 | selectionHighlightPainter = new SelectionHighlightPainter(); | 133 | selectionHighlightPainter = new SelectionHighlightPainter(); |
| 134 | this.editor = new PanelEditor(this); | 134 | this.editor = new PanelEditor(this); |
| 135 | JScrollPane sourceScroller = new JScrollPane(this.editor); | 135 | JScrollPane sourceScroller = new JScrollPane(this.editor); |
| 136 | this.editor.setContentType("text/java"); | 136 | this.editor.setContentType("text/minecraft"); |
| 137 | this.editor.setBackground(new Color(Config.INSTANCE.editorBackground)); | ||
| 137 | DefaultSyntaxKit kit = (DefaultSyntaxKit) this.editor.getEditorKit(); | 138 | DefaultSyntaxKit kit = (DefaultSyntaxKit) this.editor.getEditorKit(); |
| 138 | kit.toggleComponent(this.editor, "de.sciss.syntaxpane.components.TokenMarker"); | 139 | kit.toggleComponent(this.editor, "de.sciss.syntaxpane.components.TokenMarker"); |
| 139 | 140 | ||
diff --git a/src/main/java/cuchaz/enigma/gui/MinecraftSyntaxKit.java b/src/main/java/cuchaz/enigma/gui/MinecraftSyntaxKit.java new file mode 100644 index 00000000..41de0350 --- /dev/null +++ b/src/main/java/cuchaz/enigma/gui/MinecraftSyntaxKit.java | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | package cuchaz.enigma.gui; | ||
| 2 | |||
| 3 | import cuchaz.enigma.config.Config; | ||
| 4 | import de.sciss.syntaxpane.syntaxkits.JavaSyntaxKit; | ||
| 5 | import de.sciss.syntaxpane.util.Configuration; | ||
| 6 | |||
| 7 | /** | ||
| 8 | * Created by Mark on 04/06/2017. | ||
| 9 | */ | ||
| 10 | public class MinecraftSyntaxKit extends JavaSyntaxKit { | ||
| 11 | |||
| 12 | public Configuration configuration = null; | ||
| 13 | |||
| 14 | @Override | ||
| 15 | public Configuration getConfig() { | ||
| 16 | if(configuration == null){ | ||
| 17 | initConfig(super.getConfig(JavaSyntaxKit.class)); | ||
| 18 | } | ||
| 19 | return configuration; | ||
| 20 | } | ||
| 21 | |||
| 22 | public void initConfig(Configuration baseConfig){ | ||
| 23 | configuration = baseConfig; | ||
| 24 | //See de.sciss.syntaxpane.TokenType | ||
| 25 | configuration.put("Style.KEYWORD", Config.INSTANCE.highlightColor + ", 0"); | ||
| 26 | configuration.put("Style.KEYWORD2", Config.INSTANCE.highlightColor + ", 3"); | ||
| 27 | configuration.put("Style.STRING", Config.INSTANCE.stringColor + ", 0"); | ||
| 28 | configuration.put("Style.STRING2", Config.INSTANCE.stringColor + ", 1"); | ||
| 29 | configuration.put("Style.NUMBER", Config.INSTANCE.numberColor + ", 1"); | ||
| 30 | configuration.put("Style.OPERATOR", Config.INSTANCE.operatorColor + ", 0"); | ||
| 31 | configuration.put("Style.DELIMITER", Config.INSTANCE.delimiterColor + ", 1"); | ||
| 32 | configuration.put("Style.TYPE", Config.INSTANCE.typeColor + ", 2"); | ||
| 33 | configuration.put("Style.TYPE2", Config.INSTANCE.typeColor + ", 1"); | ||
| 34 | configuration.put("Style.IDENTIFIER", Config.INSTANCE.identifierColor + ", 0"); | ||
| 35 | configuration.put("Style.DEFAULT", Config.INSTANCE.defaultTextColor + ", 0"); | ||
| 36 | configuration.put("RightMarginColumn", "999"); //No need to have a right margin, if someone wants it add a config | ||
| 37 | } | ||
| 38 | } | ||
diff --git a/src/main/java/cuchaz/enigma/gui/highlight/BoxHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/highlight/BoxHighlightPainter.java index 0f649278..976c215e 100644 --- a/src/main/java/cuchaz/enigma/gui/highlight/BoxHighlightPainter.java +++ b/src/main/java/cuchaz/enigma/gui/highlight/BoxHighlightPainter.java | |||
| @@ -58,4 +58,9 @@ public abstract class BoxHighlightPainter implements Highlighter.HighlightPainte | |||
| 58 | g.setColor(this.borderColor); | 58 | g.setColor(this.borderColor); |
| 59 | g.drawRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4); | 59 | g.drawRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4); |
| 60 | } | 60 | } |
| 61 | |||
| 62 | protected static Color getColor(int rgb, float alpha){ | ||
| 63 | Color baseColor = new Color(rgb); | ||
| 64 | return new Color(baseColor.getRed(), baseColor.getGreen(), baseColor.getBlue(), (int)(255 * alpha)); | ||
| 65 | } | ||
| 61 | } | 66 | } |
diff --git a/src/main/java/cuchaz/enigma/gui/highlight/DeobfuscatedHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/highlight/DeobfuscatedHighlightPainter.java index a2d28844..ef651e3e 100644 --- a/src/main/java/cuchaz/enigma/gui/highlight/DeobfuscatedHighlightPainter.java +++ b/src/main/java/cuchaz/enigma/gui/highlight/DeobfuscatedHighlightPainter.java | |||
| @@ -11,11 +11,11 @@ | |||
| 11 | 11 | ||
| 12 | package cuchaz.enigma.gui.highlight; | 12 | package cuchaz.enigma.gui.highlight; |
| 13 | 13 | ||
| 14 | import java.awt.*; | 14 | import cuchaz.enigma.config.Config; |
| 15 | 15 | ||
| 16 | public class DeobfuscatedHighlightPainter extends BoxHighlightPainter { | 16 | public class DeobfuscatedHighlightPainter extends BoxHighlightPainter { |
| 17 | 17 | ||
| 18 | public DeobfuscatedHighlightPainter() { | 18 | public DeobfuscatedHighlightPainter() { |
| 19 | super(new Color(220, 255, 220), new Color(80, 160, 80)); | 19 | super(getColor(Config.INSTANCE.deobfuscatedColor, Config.INSTANCE.deobfuscatedHiglightAlpha), getColor(Config.INSTANCE.deobfuscatedColorOutline, Config.INSTANCE.deobfuscatedOutlineAlpha)); |
| 20 | } | 20 | } |
| 21 | } | 21 | } |
diff --git a/src/main/java/cuchaz/enigma/gui/highlight/ObfuscatedHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/highlight/ObfuscatedHighlightPainter.java index 0947d4b7..78879069 100644 --- a/src/main/java/cuchaz/enigma/gui/highlight/ObfuscatedHighlightPainter.java +++ b/src/main/java/cuchaz/enigma/gui/highlight/ObfuscatedHighlightPainter.java | |||
| @@ -11,11 +11,13 @@ | |||
| 11 | 11 | ||
| 12 | package cuchaz.enigma.gui.highlight; | 12 | package cuchaz.enigma.gui.highlight; |
| 13 | 13 | ||
| 14 | import cuchaz.enigma.config.Config; | ||
| 15 | |||
| 14 | import java.awt.*; | 16 | import java.awt.*; |
| 15 | 17 | ||
| 16 | public class ObfuscatedHighlightPainter extends BoxHighlightPainter { | 18 | public class ObfuscatedHighlightPainter extends BoxHighlightPainter { |
| 17 | 19 | ||
| 18 | public ObfuscatedHighlightPainter() { | 20 | public ObfuscatedHighlightPainter() { |
| 19 | super(new Color(255, 220, 220), new Color(160, 80, 80)); | 21 | super(getColor(Config.INSTANCE.obfuscatedColor, Config.INSTANCE.obfuscatedHiglightAlpha), getColor(Config.INSTANCE.obfuscatedColorOutline, Config.INSTANCE.obfuscatedOutlineAlpha)); |
| 20 | } | 22 | } |
| 21 | } | 23 | } |
diff --git a/src/main/java/cuchaz/enigma/gui/highlight/OtherHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/highlight/OtherHighlightPainter.java index 74e7273d..c5154e13 100644 --- a/src/main/java/cuchaz/enigma/gui/highlight/OtherHighlightPainter.java +++ b/src/main/java/cuchaz/enigma/gui/highlight/OtherHighlightPainter.java | |||
| @@ -11,11 +11,11 @@ | |||
| 11 | 11 | ||
| 12 | package cuchaz.enigma.gui.highlight; | 12 | package cuchaz.enigma.gui.highlight; |
| 13 | 13 | ||
| 14 | import java.awt.*; | 14 | import cuchaz.enigma.config.Config; |
| 15 | 15 | ||
| 16 | public class OtherHighlightPainter extends BoxHighlightPainter { | 16 | public class OtherHighlightPainter extends BoxHighlightPainter { |
| 17 | 17 | ||
| 18 | public OtherHighlightPainter() { | 18 | public OtherHighlightPainter() { |
| 19 | super(null, new Color(180, 180, 180)); | 19 | super(null, getColor(Config.INSTANCE.otherColorOutline, Config.INSTANCE.otherOutlineAlpha)); |
| 20 | } | 20 | } |
| 21 | } | 21 | } |