diff options
| author | 2017-06-04 16:36:21 +0100 | |
|---|---|---|
| committer | 2017-06-04 17:36:21 +0200 | |
| commit | e35b611da3c068bfea344be9a90c79fd68fac4ff (patch) | |
| tree | f0bf3d9a2fd6ebef0a38e771f5799c249cd81b92 /src/main/java/cuchaz/enigma/config | |
| parent | Remove the converter + some reorganization (diff) | |
| download | enigma-fork-e35b611da3c068bfea344be9a90c79fd68fac4ff.tar.gz enigma-fork-e35b611da3c068bfea344be9a90c79fd68fac4ff.tar.xz enigma-fork-e35b611da3c068bfea344be9a90c79fd68fac4ff.zip | |
Add support for custom themes (#59)
Diffstat (limited to 'src/main/java/cuchaz/enigma/config')
| -rw-r--r-- | src/main/java/cuchaz/enigma/config/Config.java | 72 |
1 files changed, 72 insertions, 0 deletions
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 0000000..307b221 --- /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 | } | ||