From ac72cac260e2826f4af542bb478c3d5e44f32312 Mon Sep 17 00:00:00 2001 From: ix0rai Date: Mon, 9 Oct 2023 20:39:05 -0500 Subject: [PATCH 01/25] toss current config stuff --- enigma-swing/build.gradle | 1 + .../quiltmc/enigma/gui/config/UiConfig.java | 6 +- enigma/build.gradle | 2 + .../enigma/api/config/ConfigContainer.java | 99 ------ .../enigma/api/config/ConfigSection.java | 195 ----------- .../enigma/impl/config/ConfigPaths.java | 44 --- .../enigma/impl/config/ConfigSerializer.java | 315 ------------------ .../impl/config/ConfigStructureVisitor.java | 9 - .../java/org/quiltmc/enigma/ConfigTest.java | 87 ----- gradle/libs.versions.toml | 3 + 10 files changed, 10 insertions(+), 751 deletions(-) delete mode 100644 enigma/src/main/java/org/quiltmc/enigma/api/config/ConfigContainer.java delete mode 100644 enigma/src/main/java/org/quiltmc/enigma/api/config/ConfigSection.java delete mode 100644 enigma/src/main/java/org/quiltmc/enigma/impl/config/ConfigPaths.java delete mode 100644 enigma/src/main/java/org/quiltmc/enigma/impl/config/ConfigSerializer.java delete mode 100644 enigma/src/main/java/org/quiltmc/enigma/impl/config/ConfigStructureVisitor.java delete mode 100644 enigma/src/test/java/org/quiltmc/enigma/ConfigTest.java diff --git a/enigma-swing/build.gradle b/enigma-swing/build.gradle index e0e50e9a6..62f4a2441 100644 --- a/enigma-swing/build.gradle +++ b/enigma-swing/build.gradle @@ -13,6 +13,7 @@ dependencies { implementation libs.jopt implementation libs.flatlaf implementation libs.flatlaf.extras // for SVG icons + implementation libs.quilt.config implementation libs.swing.dpi implementation libs.fontchooser testImplementation(testFixtures(project(':enigma'))) diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/UiConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/UiConfig.java index dd2cafb2f..8e0ca5f61 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/UiConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/UiConfig.java @@ -1,7 +1,7 @@ package org.quiltmc.enigma.gui.config; -import org.quiltmc.enigma.api.config.ConfigContainer; -import org.quiltmc.enigma.api.config.ConfigSection; +import org.quiltmc.config.api.Config; +import org.quiltmc.config.api.Configs; import org.quiltmc.enigma.gui.dialog.EnigmaQuickFindDialog; import org.quiltmc.enigma.gui.NotificationManager; import org.quiltmc.enigma.gui.docker.Dock; @@ -28,6 +28,8 @@ import java.util.OptionalInt; public final class UiConfig { + + Config // sections public static final String MAIN_WINDOW = "Main Window"; public static final String GENERAL = "General"; diff --git a/enigma/build.gradle b/enigma/build.gradle index ab61970cd..52bb6e946 100644 --- a/enigma/build.gradle +++ b/enigma/build.gradle @@ -15,6 +15,8 @@ dependencies { implementation libs.cfr implementation libs.procyon + implementation libs.quilt.config + proGuard libs.proguard testImplementation libs.jimfs diff --git a/enigma/src/main/java/org/quiltmc/enigma/api/config/ConfigContainer.java b/enigma/src/main/java/org/quiltmc/enigma/api/config/ConfigContainer.java deleted file mode 100644 index 622d60648..000000000 --- a/enigma/src/main/java/org/quiltmc/enigma/api/config/ConfigContainer.java +++ /dev/null @@ -1,99 +0,0 @@ -package org.quiltmc.enigma.api.config; - -import org.quiltmc.enigma.impl.config.ConfigSerializer; -import org.quiltmc.enigma.impl.config.ConfigStructureVisitor; -import org.quiltmc.enigma.impl.config.ConfigPaths; -import org.tinylog.Logger; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Deque; -import java.util.LinkedList; - -public class ConfigContainer { - private Path configPath; - private boolean existsOnDisk; - - private final ConfigSection root = new ConfigSection(); - - public ConfigSection data() { - return this.root; - } - - public void save() { - if (this.configPath == null) throw new IllegalStateException("File has no config path set!"); - try { - Files.createDirectories(this.configPath.getParent()); - Files.writeString(this.configPath, this.serialize()); - this.existsOnDisk = true; - } catch (IOException e) { - Logger.error(e, "Failed to save config file!"); - } - } - - public void saveAs(Path path) { - this.configPath = path; - this.save(); - } - - public boolean existsOnDisk() { - return this.existsOnDisk; - } - - public String serialize() { - return ConfigSerializer.structureToString(this.root); - } - - public static ConfigContainer create() { - return new ConfigContainer(); - } - - public static ConfigContainer getOrCreate(String name) { - return ConfigContainer.getOrCreate(ConfigPaths.getConfigFilePath(name)); - } - - public static ConfigContainer getOrCreate(Path path) { - ConfigContainer cc = null; - try { - if (Files.exists(path)) { - String s = String.join("\n", Files.readAllLines(path)); - cc = ConfigContainer.parse(s); - cc.existsOnDisk = true; - } - } catch (IOException e) { - Logger.error(e, "Failed to create config container!"); - } - - if (cc == null) { - cc = ConfigContainer.create(); - } - - cc.configPath = path; - return cc; - } - - public static ConfigContainer parse(String source) { - ConfigContainer cc = ConfigContainer.create(); - Deque stack = new LinkedList<>(); - stack.push(cc.root); - ConfigSerializer.parse(source, new ConfigStructureVisitor() { - @Override - public void visitKeyValue(String key, String value) { - stack.peekLast().setString(key, value); - } - - @Override - public void visitSection(String section) { - stack.add(stack.peekLast().section(section)); - } - - @Override - public void jumpToRootSection() { - stack.clear(); - stack.push(cc.root); - } - }); - return cc; - } -} diff --git a/enigma/src/main/java/org/quiltmc/enigma/api/config/ConfigSection.java b/enigma/src/main/java/org/quiltmc/enigma/api/config/ConfigSection.java deleted file mode 100644 index 8eee2abcc..000000000 --- a/enigma/src/main/java/org/quiltmc/enigma/api/config/ConfigSection.java +++ /dev/null @@ -1,195 +0,0 @@ -package org.quiltmc.enigma.api.config; - -import org.quiltmc.enigma.impl.config.ConfigSerializer; - -import java.awt.Color; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.OptionalDouble; -import java.util.OptionalInt; -import java.util.function.Function; - -public class ConfigSection { - private final Map values; - private final Map sections; - - private ConfigSection(Map values, Map sections) { - this.values = values; - this.sections = sections; - } - - public ConfigSection() { - this(new HashMap<>(), new HashMap<>()); - } - - public ConfigSection section(String name) { - return this.sections.computeIfAbsent(name, _s -> new ConfigSection()); - } - - public Map values() { - return Collections.unmodifiableMap(this.values); - } - - public Map sections() { - return Collections.unmodifiableMap(this.sections); - } - - public boolean remove(String key) { - return this.values.remove(key) != null; - } - - public boolean removeSection(String key) { - return this.sections.remove(key) != null; - } - - public Optional getString(String key) { - return Optional.ofNullable(this.values.get(key)); - } - - public void setString(String key, String value) { - this.values.put(key, value); - } - - public String setIfAbsentString(String key, String value) { - this.values.putIfAbsent(key, value); - return this.values.get(key); - } - - public Optional getBool(String key) { - return ConfigSerializer.parseBool(this.values.get(key)); - } - - public boolean setIfAbsentBool(String key, boolean value) { - return this.getBool(key).orElseGet(() -> { - this.setBool(key, value); - return value; - }); - } - - public void setBool(String key, boolean value) { - this.values.put(key, Boolean.toString(value)); - } - - public OptionalInt getInt(String key) { - return ConfigSerializer.parseInt(this.values.get(key)); - } - - public void setInt(String key, int value) { - this.values.put(key, Integer.toString(value)); - } - - public int setIfAbsentInt(String key, int value) { - return this.getInt(key).orElseGet(() -> { - this.setInt(key, value); - return value; - }); - } - - public OptionalDouble getDouble(String key) { - return ConfigSerializer.parseDouble(this.values.get(key)); - } - - public void setDouble(String key, double value) { - this.values.put(key, Double.toString(value)); - } - - public double setIfAbsentDouble(String key, double value) { - return this.getDouble(key).orElseGet(() -> { - this.setDouble(key, value); - return value; - }); - } - - public OptionalInt getRgbColor(String key) { - return ConfigSerializer.parseRgbColor(this.values.get(key)); - } - - public Color getColor(String key) { - OptionalInt rgbColor = this.getRgbColor(key); - return rgbColor.isPresent() ? new Color(rgbColor.getAsInt()) : null; - } - - public void setRgbColor(String key, int value) { - this.values.put(key, ConfigSerializer.rgbColorToString(value)); - } - - public int setIfAbsentRgbColor(String key, int value) { - return this.getRgbColor(key).orElseGet(() -> { - this.setRgbColor(key, value); - return value; - }); - } - - public Optional getArray(String key) { - return ConfigSerializer.parseArray(this.values.get(key)); - } - - public void setArray(String key, String[] value) { - this.values.put(key, ConfigSerializer.arrayToString(value)); - } - - public String[] setIfAbsentArray(String key, String[] value) { - return this.getArray(key).orElseGet(() -> { - this.setArray(key, value); - return value; - }); - } - - public Optional getIntArray(String key) { - return this.getArray(key).map(arr -> Arrays.stream(arr).mapToInt(s -> ConfigSerializer.parseInt(s).orElse(0)).toArray()); - } - - public void setIntArray(String key, int[] value) { - this.setArray(key, Arrays.stream(value).mapToObj(Integer::toString).toArray(String[]::new)); - } - - public int[] setIfAbsentIntArray(String key, int[] value) { - return this.getIntArray(key).orElseGet(() -> { - this.setIntArray(key, value); - return value; - }); - } - - public > Optional getEnum(Function byName, String key) { - return ConfigSerializer.parseEnum(byName, this.values.get(key)); - } - - public > void setEnum(String key, T value) { - this.values.put(key, value.name()); - } - - public > T setIfAbsentEnum(Function byName, String key, T value) { - return this.getEnum(byName, key).orElseGet(() -> { - this.setEnum(key, value); - return value; - }); - } - - public ConfigSection copy() { - Map sections = new HashMap<>(this.sections); - sections.replaceAll((k, v) -> v.copy()); - return new ConfigSection(new HashMap<>(this.values), sections); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ConfigSection that)) return false; - return this.values.equals(that.values) - && this.sections.equals(that.sections); - } - - @Override - public int hashCode() { - return Objects.hash(this.values, this.sections); - } - - @Override - public String toString() { - return String.format("ConfigSection { values: %s, sections: %s }", this.values, this.sections); - } -} diff --git a/enigma/src/main/java/org/quiltmc/enigma/impl/config/ConfigPaths.java b/enigma/src/main/java/org/quiltmc/enigma/impl/config/ConfigPaths.java deleted file mode 100644 index 55c05efee..000000000 --- a/enigma/src/main/java/org/quiltmc/enigma/impl/config/ConfigPaths.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.quiltmc.enigma.impl.config; - -import org.quiltmc.enigma.util.Os; - -import java.nio.file.Path; -import java.nio.file.Paths; - -public class ConfigPaths { - public static Path getConfigFilePath(String name) { - String fileName = Os.getOs() == Os.LINUX ? String.format("%src", name) : String.format("%s.ini", name); - return getConfigPathRoot().resolve(fileName); - } - - public static Path getConfigPathRoot() { - switch (Os.getOs()) { - case LINUX -> { - String configHome = System.getenv("XDG_CONFIG_HOME"); - if (configHome == null) { - return getUserHomeUnix().resolve(".config"); - } - - return Paths.get(configHome); - } - case MAC -> { - return getUserHomeUnix().resolve("Library").resolve("Application Support"); - } - case WINDOWS -> { - return Paths.get(System.getenv("LOCALAPPDATA")); - } - default -> { - return Paths.get(System.getProperty("user.dir")); - } - } - } - - private static Path getUserHomeUnix() { - String userHome = System.getenv("HOME"); - if (userHome == null) { - userHome = System.getProperty("user.dir"); - } - - return Paths.get(userHome); - } -} diff --git a/enigma/src/main/java/org/quiltmc/enigma/impl/config/ConfigSerializer.java b/enigma/src/main/java/org/quiltmc/enigma/impl/config/ConfigSerializer.java deleted file mode 100644 index e161b9f2d..000000000 --- a/enigma/src/main/java/org/quiltmc/enigma/impl/config/ConfigSerializer.java +++ /dev/null @@ -1,315 +0,0 @@ -package org.quiltmc.enigma.impl.config; - -import org.quiltmc.enigma.api.config.ConfigSection; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map.Entry; -import java.util.Optional; -import java.util.OptionalDouble; -import java.util.OptionalInt; -import java.util.function.Function; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - -public final class ConfigSerializer { - private static final Pattern FULL_RGB_COLOR = Pattern.compile("#[0-9A-Fa-f]{6}"); - private static final Pattern MIN_RGB_COLOR = Pattern.compile("#[0-9A-Fa-f]{3}"); - - private static final int UNEXPECTED_TOKEN = -1; - private static final int NO_MATCH = -2; - - public static void parse(String v, ConfigStructureVisitor visitor) { - String[] lines = v.split("\n"); - - // join escaped newlines - int len = lines.length; - for (int i = len - 2; i >= 0; i--) { - if (lines[i].endsWith("\\")) { - lines[i] = String.format("%s\n%s", lines[i], lines[i + 1]); - len -= 1; - } - } - - // parse for real - for (int i = 0; i < len; i++) { - String line = lines[i]; - - // skip empty lines and comment lines - if (line.trim().isEmpty() || line.trim().startsWith(";")) continue; - - int r; - boolean fail = (r = parseSectionLine(line, 0, visitor)) == NO_MATCH - && (r = parseKeyValue(line, 0, visitor)) == NO_MATCH; - } - } - - private static int parseSectionLine(String v, int idx, ConfigStructureVisitor visitor) { - if (v.startsWith("[")) { - List path = new ArrayList<>(); - while (idx < v.length() && v.charAt(idx) == '[') { - idx = parseSection(v, idx, path); - if (idx == UNEXPECTED_TOKEN) return UNEXPECTED_TOKEN; - } - - if (!path.isEmpty()) { - visitor.jumpToRootSection(); - for (String s : path) { - visitor.visitSection(s); - } - } - - return v.length(); - } else { - return NO_MATCH; - } - } - - private static int parseSection(String v, int idx, List path) { - idx += 1; // skip leading [ - StringBuilder sb = new StringBuilder(); - while (idx < v.length()) { - int nextCloseBracket = v.indexOf(']', idx); - int nextEscape = v.indexOf('\\', idx); - int next = optMin(nextCloseBracket, nextEscape); - if (next == -1) { - // unexpected - return UNEXPECTED_TOKEN; - } else if (next == nextCloseBracket) { - sb.append(v, idx, nextCloseBracket); - path.add(sb.toString()); - return nextCloseBracket + 1; - } else if (next == nextEscape) { - sb.append(v, idx, nextEscape); - idx = parseEscape(v, nextEscape, sb); - } - } - - return idx; - } - - private static int parseKeyValue(String v, int idx, ConfigStructureVisitor visitor) { - StringBuilder sb = new StringBuilder(); - String k = null; - while (idx < v.length()) { - int nextEq = v.indexOf('=', idx); - int nextEscape = v.indexOf('\\', idx); - int next = optMin(nextEq, nextEscape); - if (next == -1) { - break; - } else if (next == nextEq) { - sb.append(v, idx, nextEq); - k = sb.toString(); - sb.delete(0, sb.length()); - idx = nextEq + 1; - break; - } else if (next == nextEscape) { - sb.append(v, idx, nextEscape); - idx = parseEscape(v, nextEscape, sb); - } - } - - while (idx < v.length()) { - int nextEscape = v.indexOf('\\', idx); - if (nextEscape != -1) { - sb.append(v, idx, nextEscape); - idx = parseEscape(v, nextEscape, sb); - } else { - break; - } - } - - sb.append(v, idx, v.length()); - if (k == null) return NO_MATCH; - visitor.visitKeyValue(k, sb.toString()); - return idx; - } - - private static int parseEscape(String v, int idx, StringBuilder sb) { - if (idx + 1 < v.length()) { - if (v.charAt(idx + 1) == 'u') { - if (idx + 5 < v.length()) { - String codePoint = v.substring(idx + 2, idx + 6); - try { - int c = Integer.parseUnsignedInt(codePoint, 16); - sb.append((char) c); - } catch (NumberFormatException ignored) { - // ignored! - } - - idx = idx + 6; - } - } else if (v.charAt(idx + 1) == 'n') { - sb.append('\n'); - idx = idx + 2; - } else { - sb.append(v.charAt(idx + 1)); - idx = idx + 2; - } - } else { - idx = idx + 1; - } - - return idx; - } - - public static String structureToString(ConfigSection section) { - StringBuilder sb = new StringBuilder(); - structureToString(section, sb, new ArrayList<>()); - return sb.toString(); - } - - private static void structureToString(ConfigSection section, StringBuilder sb, List pathStack) { - if (!section.values().isEmpty()) { - if (sb.length() > 0) sb.append('\n'); - pathStack.forEach(n -> sb.append('[').append(escapeSection(n)).append(']')); - if (!pathStack.isEmpty()) sb.append('\n'); - section.values().entrySet().stream() - .sorted(Entry.comparingByKey()) - .forEach(e -> sb.append(escapeKey(e.getKey())).append('=').append(escapeValue(e.getValue())).append('\n')); - } - - section.sections().entrySet().stream().sorted(Entry.comparingByKey()).forEach(e -> { - pathStack.add(e.getKey()); - structureToString(e.getValue(), sb, pathStack); - pathStack.remove(pathStack.size() - 1); - }); - } - - private static String escapeSection(String s) { - return s - .replace("\\", "\\\\") - .replace("\n", "\\n") - .replace("]", "\\]") - .chars().mapToObj(c -> c >= 32 && c < 127 ? Character.toString((char) c) : String.format("\\u%04x", c)).collect(Collectors.joining()); - } - - private static String escapeKey(String s) { - return s - .replace("\\", "\\\\") - .replace("[", "\\[") - .replace("\n", "\\n") - .replace("=", "\\=") - .chars().mapToObj(c -> c >= 32 && c < 127 ? Character.toString((char) c) : String.format("\\u%04x", c)).collect(Collectors.joining()); - } - - private static String escapeValue(String s) { - return s - .replace("\\", "\\\\") - .replace("\n", "\\n") - .chars().mapToObj(c -> c >= 32 && c < 127 ? Character.toString((char) c) : String.format("\\u%04x", c)).collect(Collectors.joining()); - } - - public static Optional parseBool(String v) { - if (v == null) return Optional.empty(); - return switch (v) { - case "true" -> Optional.of(true); - case "false" -> Optional.of(false); - default -> Optional.empty(); - }; - } - - public static OptionalInt parseInt(String v) { - if (v == null) { - return OptionalInt.empty(); - } - - try { - return OptionalInt.of(Integer.parseInt(v)); - } catch (NumberFormatException e) { - return OptionalInt.empty(); - } - } - - public static OptionalDouble parseDouble(String v) { - if (v == null) return OptionalDouble.empty(); - try { - return OptionalDouble.of(Double.parseDouble(v)); - } catch (NumberFormatException e) { - return OptionalDouble.empty(); - } - } - - public static OptionalInt parseRgbColor(String v) { - if (v == null) return OptionalInt.empty(); - try { - if (FULL_RGB_COLOR.matcher(v).matches()) { - return OptionalInt.of(Integer.parseUnsignedInt(v.substring(1), 16)); - } else if (MIN_RGB_COLOR.matcher(v).matches()) { - int result = Integer.parseUnsignedInt(v.substring(1), 16); - // change 0xABC to 0xAABBCC - result = (result & 0x00F) | (result & 0x0F0) << 4 | (result & 0xF00) << 8; - result = result | result << 4; - return OptionalInt.of(result); - } else { - return OptionalInt.empty(); - } - } catch (NumberFormatException e) { - return OptionalInt.empty(); - } - } - - public static String rgbColorToString(int color) { - color = color & 0xFFFFFF; - boolean isShort = ((color & 0xF0F0F0) >> 4 ^ color & 0x0F0F0F) == 0; - if (isShort) { - int packed = color & 0x0F0F0F; - packed = packed & 0xF | packed >> 4; - packed = packed & 0xFF | (packed & ~0xFF) >> 4; - return String.format("#%03x", packed); - } else { - return String.format("#%06x", color); - } - } - - public static Optional parseArray(String v) { - if (v == null) return Optional.empty(); - List l = new ArrayList<>(); - int idx = 0; - StringBuilder cur = new StringBuilder(); - while (true) { - int nextSep = v.indexOf(',', idx); - int nextEsc = v.indexOf('\\', idx); - int next = optMin(nextSep, nextEsc); - if (next == -1) { - cur.append(v, idx, v.length()); - l.add(cur.toString()); - return Optional.of(l.toArray(new String[0])); - } else if (next == nextSep) { - cur.append(v, idx, nextSep); - l.add(cur.toString()); - cur.delete(0, cur.length()); - idx = nextSep + 1; - } else if (next == nextEsc) { - cur.append(v, idx, nextEsc); - if (nextEsc + 1 < v.length()) { - cur.append(v.charAt(nextEsc + 1)); - } - - idx = nextEsc + 2; - } - } - } - - public static String arrayToString(String[] values) { - return Arrays.stream(values) - .map(s -> s.replace("\\", "\\\\").replace(",", "\\,")) - .collect(Collectors.joining(",")); - } - - public static > Optional parseEnum(Function byName, String v) { - if (v == null) return Optional.empty(); - try { - return Optional.of(byName.apply(v)); - } catch (IllegalArgumentException e) { - return Optional.empty(); - } - } - - private static int optMin(int v1, int v2) { - if (v1 == -1) return v2; - if (v2 == -1) return v1; - return Math.min(v1, v2); - } -} diff --git a/enigma/src/main/java/org/quiltmc/enigma/impl/config/ConfigStructureVisitor.java b/enigma/src/main/java/org/quiltmc/enigma/impl/config/ConfigStructureVisitor.java deleted file mode 100644 index e6325489c..000000000 --- a/enigma/src/main/java/org/quiltmc/enigma/impl/config/ConfigStructureVisitor.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.quiltmc.enigma.impl.config; - -public interface ConfigStructureVisitor { - void visitKeyValue(String key, String value); - - void visitSection(String section); - - void jumpToRootSection(); -} diff --git a/enigma/src/test/java/org/quiltmc/enigma/ConfigTest.java b/enigma/src/test/java/org/quiltmc/enigma/ConfigTest.java deleted file mode 100644 index e8db9a1c3..000000000 --- a/enigma/src/test/java/org/quiltmc/enigma/ConfigTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.quiltmc.enigma; - -import org.quiltmc.enigma.api.config.ConfigContainer; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class ConfigTest { - @Test - public void serialize() { - ConfigContainer cc = new ConfigContainer(); - cc.data().setString("a", "a"); - cc.data().section("a").section("b").section("c").setString("a", "abcd"); - cc.data().section("a").section("b").section("c").setBool("b", true); - cc.data().section("a").section("b").section("c").setInt("c", 5); - cc.data().section("a").section("b").section("c").setDouble("d", 3.5); - cc.data().section("a").section("b").section("c").setRgbColor("e", 0x123456); - assertEquals(""" - a=a - - [a][b][c] - a=abcd - b=true - c=5 - d=3.5 - e=#123456 - """, cc.serialize()); - } - - @Test - public void deserialize() { - ConfigContainer cc = new ConfigContainer(); - cc.data().setString("a", "a"); - cc.data().section("a").section("b").section("c").setString("a", "abcd"); - cc.data().section("a").section("b").section("c").setBool("b", true); - cc.data().section("a").section("b").section("c").setInt("c", 5); - cc.data().section("a").section("b").section("c").setDouble("d", 3.5); - cc.data().section("a").section("b").section("c").setRgbColor("e", 0x123456); - assertEquals(ConfigContainer.parse(""" - a=a - - [a][b][c] - a=abcd - b=true - c=5 - d=3.5 - e=#123456 - """).data(), cc.data()); - } - - @Test - public void weirdChars() { - ConfigContainer cc = new ConfigContainer(); - String thing = "\\[],\\,./'\"`~!@#$%^&*()_+-=|}{\n\\\\\r\b\u0000\uffff\u1234"; - cc.data().section(thing).setString(thing, thing); - cc.data().section(thing).setArray("arr", new String[] { thing, thing, thing, thing }); - - assertEquals( - """ - [\\\\[\\],\\\\,./'"`~!@#$%^&*()_+-=|}{\\n\\\\\\\\\\u000d\\u0008\\u0000\\uffff\\u1234] - \\\\\\[],\\\\,./'"`~!@#$%^&*()_+-\\=|}{\\n\\\\\\\\\\u000d\\u0008\\u0000\\uffff\\u1234=\\\\[],\\\\,./'"`~!@#$%^&*()_+-=|}{\\n\\\\\\\\\\u000d\\u0008\\u0000\\uffff\\u1234 - arr=\\\\\\\\[]\\\\,\\\\\\\\\\\\,./'"`~!@#$%^&*()_+-=|}{\\n\\\\\\\\\\\\\\\\\\u000d\\u0008\\u0000\\uffff\\u1234,\\\\\\\\[]\\\\,\\\\\\\\\\\\,./'"`~!@#$%^&*()_+-=|}{\\n\\\\\\\\\\\\\\\\\\u000d\\u0008\\u0000\\uffff\\u1234,\\\\\\\\[]\\\\,\\\\\\\\\\\\,./'"`~!@#$%^&*()_+-=|}{\\n\\\\\\\\\\\\\\\\\\u000d\\u0008\\u0000\\uffff\\u1234,\\\\\\\\[]\\\\,\\\\\\\\\\\\,./'"`~!@#$%^&*()_+-=|}{\\n\\\\\\\\\\\\\\\\\\u000d\\u0008\\u0000\\uffff\\u1234 - """, - cc.serialize()); - - ConfigContainer cc1 = ConfigContainer.parse(cc.serialize()); - assertEquals(cc.data(), cc1.data()); - - cc1 = ConfigContainer.parse(cc1.serialize()); - assertEquals(cc.data(), cc1.data()); - } - - @Test - public void syntaxErrors() { - assertEquals("", ConfigContainer.parse("abcde").serialize()); - assertEquals("", ConfigContainer.parse("what\\=?").serialize()); - - assertEquals("[a]\nb=c\n", ConfigContainer.parse("[a] what is this\nb=c").serialize()); - assertEquals("b=c\n", ConfigContainer.parse("[a][ what is this\nb=c").serialize()); - assertEquals("", ConfigContainer.parse("[").serialize()); - assertEquals("[a]\na=b\nc=d\n", ConfigContainer.parse("[a]\na=b\n[\nc=d").serialize()); - - // not technically syntax errors but never something that gets generated - assertEquals("", ConfigContainer.parse("[a]").serialize()); - assertEquals("", ConfigContainer.parse("[a]\n[b]").serialize()); - } -} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3d7bbeced..aab3ed69d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,6 +10,7 @@ syntaxpain = "0.1.1" swing_dpi = "0.10" fontchooser = "2.5.2" tinylog = "2.6.2" +quilt_config = "1.1.0-beta.3" vineflower = "1.10.0-20230713.053900-2" cfr = "0.2.1" @@ -32,6 +33,8 @@ asm_util = { module = "org.ow2.asm:asm-util", version.ref = "asm" } tinylog_api = { module = "org.tinylog:tinylog-api", version.ref = "tinylog" } tinylog_impl = { module = "org.tinylog:tinylog-impl", version.ref = "tinylog" } +quilt_config = { module = "org.quiltmc:quilt-config", version.ref = "quilt_config" } + jopt = { module = "net.sf.jopt-simple:jopt-simple", version.ref = "jopt" } flatlaf = { module = "com.formdev:flatlaf", version.ref = "flatlaf" } flatlaf_extras = { module = "com.formdev:flatlaf-extras", version.ref = "flatlaf" } From f639b387919d9a353276d3ed067af73f866be696 Mon Sep 17 00:00:00 2001 From: ix0rai Date: Sun, 15 Oct 2023 21:12:19 -0500 Subject: [PATCH 02/25] wip migrating config to quilt-config --- .../main/java/org/quiltmc/enigma/gui/Gui.java | 2 + .../quiltmc/enigma/gui/config/Decompiler.java | 10 - .../enigma/gui/config/DecompilerConfig.java | 8 +- .../enigma/gui/config/DockerConfig.java | 36 ++ .../enigma/gui/config/RecentFiles.java | 76 +++++ .../enigma/gui/config/ThemeColors.java | 106 ++++++ .../quiltmc/enigma/gui/config/UiConfig.java | 312 ++---------------- .../quiltmc/enigma/gui/config/nonsense.java | 67 ++++ 8 files changed, 312 insertions(+), 305 deletions(-) create mode 100644 enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java create mode 100644 enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/RecentFiles.java create mode 100644 enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/ThemeColors.java create mode 100644 enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/nonsense.java diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java index 4ef942c2d..2f8c1a413 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java @@ -154,6 +154,8 @@ private void setupDockers() { for (Docker.Side side : Docker.Side.values()) { this.mainWindow.getDockerSelector(side).configure(); } + + //todo: setup default docker config } private void setupUi() { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Decompiler.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Decompiler.java index ee34e1928..978b8989c 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Decompiler.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Decompiler.java @@ -15,8 +15,6 @@ public enum Decompiler { PROCYON("Procyon", Decompilers.PROCYON), BYTECODE("Bytecode", Decompilers.BYTECODE); - private static final Map LEGACY_ALIASES = Map.of("QUILTFLOWER", VINEFLOWER); - public final DecompilerService service; public final String name; public final BiConsumer settingsDialog; @@ -31,14 +29,6 @@ public enum Decompiler { this.settingsDialog = settingsDialog; } - public static Decompiler valueOfLegacy(String name) { - if (LEGACY_ALIASES.containsKey(name)) { - return LEGACY_ALIASES.get(name); - } - - return valueOf(name); - } - static { DecompilerConfig.bootstrap(); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java index 7cb05d9dd..220c702da 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java @@ -1,5 +1,7 @@ package org.quiltmc.enigma.gui.config; +import org.quiltmc.config.api.ReflectiveConfig; +import org.quiltmc.config.api.values.TrackedValue; import org.quiltmc.enigma.api.config.ConfigContainer; import org.quiltmc.enigma.api.config.ConfigSection; import org.quiltmc.enigma.impl.source.vineflower.VineflowerPreferences; @@ -7,8 +9,10 @@ import java.util.HashSet; import java.util.Map; -public class DecompilerConfig { - private static final String VINEFLOWER = "Vineflower"; +public class DecompilerConfig extends ReflectiveConfig.Section { + public final TrackedValue decompiler = this.value(Decompiler.VINEFLOWER); + + private static final String VINEFLOWER = Decompiler.VINEFLOWER.name(); private DecompilerConfig() { } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java new file mode 100644 index 000000000..6570e7b18 --- /dev/null +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java @@ -0,0 +1,36 @@ +package org.quiltmc.enigma.gui.config; + +import org.quiltmc.config.api.ReflectiveConfig; +import org.quiltmc.config.api.values.TrackedValue; +import org.quiltmc.config.api.values.ValueMap; +import org.quiltmc.enigma.gui.docker.Docker; +import org.quiltmc.enigma.gui.docker.DockerManager; +import org.quiltmc.enigma.gui.docker.ObfuscatedClassesDocker; +import org.quiltmc.enigma.util.Pair; + +public class DockerConfig extends ReflectiveConfig.Section { + public final TrackedValue leftVerticalDividerLocation = this.value(300); + public final TrackedValue rightVerticalDividerLocation = this.value(300); + public final TrackedValue leftHorizontalDividerLocation = this.value(300); + public final TrackedValue rightHorizontalDividerLocation = this.value(700); + public final TrackedValue savedWithLeftDockerOpen = this.value(true); + + public final TrackedValue>> dockerLocations = this.map(new Pair<>("", "")).build(); + + public void putDockerLocation(String id, Docker.Location location) { + putDockerLocation(this.dockerLocations, id, location); + } + + private static void putDockerLocation(TrackedValue>> locations, String id, Docker.Location location) { + if (location.verticalLocation() == Docker.VerticalLocation.FULL) { + throw new RuntimeException(); + } + + locations.value().put(id, new Pair<>(location.side().toString(), location.verticalLocation().toString())); + } + + public static DockerConfig getDefault(DockerManager manager) { + DockerConfig defaultConfig = new DockerConfig(); + putDockerLocation(defaultConfig.dockerLocations, manager.getDocker(ObfuscatedClassesDocker.class).getId(), new Docker.Location(Docker.Side.LEFT, Docker.VerticalLocation.TOP)); + } +} diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/RecentFiles.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/RecentFiles.java new file mode 100644 index 000000000..3c7c10a1a --- /dev/null +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/RecentFiles.java @@ -0,0 +1,76 @@ +package org.quiltmc.enigma.gui.config; + +import org.quiltmc.enigma.util.Pair; +import org.tinylog.Logger; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +public class RecentFiles { + /** + * Adds a new file pair first in the recent files list, limiting the new list's size to {@link #MAX_RECENT_FILES}. If the pair is already in the list, moves it to the top. + * @param jar a path to the jar being mapped + * @param mappings a path to the mappings save location + */ + public static void addRecentFilePair(Path jar, Path mappings) { + var pairs = getRecentFilePairs(); + var pair = new Pair<>(jar, mappings); + + pairs.remove(pair); + pairs.add(0, pair); + + ui.data().setArray(RECENT_FILES, pairs.stream().limit(getMaxRecentFiles()).map(p -> p.a().toString() + PAIR_SEPARATOR + p.b().toString()).toArray(String[]::new)); + } + + /** + * Returns the most recently accessed project. + * @return A pair containing the jar path as its left element and the mappings path as its right element. + */ + public static Optional> getMostRecentFilePair() { + var recentFilePairs = getRecentFilePairs(); + if (recentFilePairs.isEmpty()) { + return Optional.empty(); + } + + return Optional.of(recentFilePairs.get(0)); + } + + /** + * Returns all recently accessed projects, up to a limit of {@link #MAX_RECENT_FILES}. + * @return a list of pairs containing the jar path as their left element and the mappings path as their right element. + */ + public static List> getRecentFilePairs() { + List> pairs = new ArrayList<>(); + + String[] pairsArray = ui.data().getArray(RECENT_FILES).orElse(new String[0]); + + for (String filePair : pairsArray) { + if (!filePair.isBlank()) { + var pairOptional = parseFilePair(filePair); + + if (pairOptional.isPresent()) { + pairs.add(pairOptional.get()); + } else { + Logger.error("failed to read recent file state for {}, ignoring!", filePair); + } + } + } + + return pairs; + } + + private static Optional> parseFilePair(String pair) { + String[] split = pair.split(PAIR_SEPARATOR); + + if (split.length != 2) { + return Optional.empty(); + } + + String jar = split[0]; + String mappings = split[1]; + return Optional.of(new Pair<>(Paths.get(jar), Paths.get(mappings))); + } +} diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/ThemeColors.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/ThemeColors.java new file mode 100644 index 000000000..c70ad455d --- /dev/null +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/ThemeColors.java @@ -0,0 +1,106 @@ +package org.quiltmc.enigma.gui.config; + +import org.quiltmc.config.api.ReflectiveConfig; +import org.quiltmc.config.api.values.TrackedValue; + +import java.awt.Color; + +public class ThemeColors extends ReflectiveConfig.Section { + private final TrackedValue lineNumbersForeground = this.value(new Color(0xFF333300, true)); + private final TrackedValue lineNumbersBackground = this.value(new Color(0xFFEEEEFF, true)); + private final TrackedValue lineNumbersSelected = this.value(new Color(0xFFCCCCEE, true)); + + private final TrackedValue obfuscated = this.value(new Color(0xFFFFDCDC, true)); + private final TrackedValue obfuscatedOutline = this.value(new Color(0xFFA05050, true)); + + private final TrackedValue proposed = this.value(new Color(0xFF000000, true)); + private final TrackedValue proposedOutline = this.value(new Color(0xBF000000, true)); + + private final TrackedValue deobfuscated = this.value(new Color(0xFFDCFFDC, true)); + private final TrackedValue deobfuscatedOutline = this.value(new Color(0xFF50A050, true)); + + private final TrackedValue editorBackground = this.value(new Color(0xFF50A050, true)); + private final TrackedValue highlight = this.value(new Color(0xFF50A050, true)); + private final TrackedValue caret = this.value(new Color(0xFF50A050, true)); + private final TrackedValue selectionHighlight = this.value(new Color(0xFF50A050, true)); + private final TrackedValue string = this.value(new Color(0xFFCC6600, true)); + private final TrackedValue number = this.value(new Color(0xFF999933, true)); + private final TrackedValue operator = this.value(new Color(0xFF000000, true)); + private final TrackedValue delimiter = this.value(new Color(0xFF000000, true)); + private final TrackedValue type = this.value(new Color(0xFF000000, true)); + private final TrackedValue identifier = this.value(new Color(0xFF000000, true)); + private final TrackedValue text = this.value(new Color(0xFF000000, true)); + + private final TrackedValue debugToken = this.value(new Color(0xFFD9BEF9, true)); + private final TrackedValue debugTokenOutline = this.value(new Color(0xFFBD93F9, true)); + + public void configure(boolean dark) { + if (dark) { + setIfAbsent(this.lineNumbersForeground, new Color(0xFFA4A4A3)); + setIfAbsent(this.lineNumbersBackground, new Color(0xFF313335)); + setIfAbsent(this.lineNumbersSelected, new Color(0xFF606366)); + + setIfAbsent(this.obfuscated, new Color(0x4DFF5555, true)); + setIfAbsent(this.obfuscatedOutline, new Color(0x80FF5555, true)); + + setIfAbsent(this.proposed, new Color(0x4D606366)); + setIfAbsent(this.proposedOutline, new Color(0x80606366)); + + setIfAbsent(this.deobfuscated, new Color(0x4D50FA7B)); + setIfAbsent(this.deobfuscatedOutline, new Color(0x50FA7B)); + + setIfAbsent(this.editorBackground, new Color(0xFF282A36)); + setIfAbsent(this.highlight, new Color(0xFFFF79C6)); + setIfAbsent(this.caret, new Color(0xFFF8F8F2)); + setIfAbsent(this.selectionHighlight, new Color(0xFFF8F8F2)); + setIfAbsent(this.string, new Color(0xFFF1FA8C)); + setIfAbsent(this.number, new Color(0xFFBD93F9)); + setIfAbsent(this.operator, new Color(0xFFF8F8F2)); + setIfAbsent(this.delimiter, new Color(0xFFF8F8F2)); + setIfAbsent(this.type, new Color(0xFFF8F8F2)); + setIfAbsent(this.identifier, new Color(0xFFF8F8F2)); + setIfAbsent(this.text, new Color(0xFFF8F8F2)); + + setIfAbsent(this.debugToken, new Color(0x804B1370)); + setIfAbsent(this.debugTokenOutline, new Color(0x80701367)); + } else { + resetIfAbsent(this.lineNumbersForeground); + resetIfAbsent(this.lineNumbersBackground); + resetIfAbsent(this.lineNumbersSelected); + + resetIfAbsent(this.obfuscated); + resetIfAbsent(this.obfuscatedOutline); + + resetIfAbsent(this.proposed); + resetIfAbsent(this.proposedOutline); + + resetIfAbsent(this.deobfuscated); + resetIfAbsent(this.deobfuscatedOutline); + + resetIfAbsent(this.editorBackground); + resetIfAbsent(this.highlight); + resetIfAbsent(this.caret); + resetIfAbsent(this.selectionHighlight); + resetIfAbsent(this.string); + resetIfAbsent(this.number); + resetIfAbsent(this.operator); + resetIfAbsent(this.delimiter); + resetIfAbsent(this.type); + resetIfAbsent(this.identifier); + resetIfAbsent(this.text); + + resetIfAbsent(this.debugToken); + resetIfAbsent(this.debugTokenOutline); + } + } + + private static void resetIfAbsent(TrackedValue value) { + setIfAbsent(value, value.getDefaultValue()); + } + + private static void setIfAbsent(TrackedValue value, T newValue) { + if (value.getDefaultValue().equals(value.value())) { + value.setValue(newValue, true); + } + } +} diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/UiConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/UiConfig.java index 8e0ca5f61..ac5c3f59f 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/UiConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/UiConfig.java @@ -2,6 +2,9 @@ import org.quiltmc.config.api.Config; import org.quiltmc.config.api.Configs; +import org.quiltmc.config.api.ReflectiveConfig; +import org.quiltmc.config.api.values.TrackedValue; +import org.quiltmc.enigma.api.source.Decompilers; import org.quiltmc.enigma.gui.dialog.EnigmaQuickFindDialog; import org.quiltmc.enigma.gui.NotificationManager; import org.quiltmc.enigma.gui.docker.Dock; @@ -27,309 +30,32 @@ import java.util.Optional; import java.util.OptionalInt; -public final class UiConfig { - - Config - // sections - public static final String MAIN_WINDOW = "Main Window"; - public static final String GENERAL = "General"; - public static final String LANGUAGE = "Language"; - public static final String SCALE_FACTOR = "Scale Factor"; - public static final String VERTICAL_DIVIDER_LOCATIONS = "Vertical Divider Locations"; - public static final String HORIZONTAL_DIVIDER_LOCATIONS = "Horizontal Divider Locations"; - public static final String HOSTED_DOCKERS = "Hosted Dockers"; - public static final String DOCKER_BUTTON_LOCATIONS = "Docker Button Locations"; - public static final String THEMES = "Themes"; - public static final String COLORS = "Colors"; - public static final String DECOMPILER = "Decompiler"; - public static final String FONTS = "Fonts"; - public static final String FILE_DIALOG = "File Dialog"; - public static final String MAPPING_STATS = "Mapping Stats"; - - // fields - public static final String CURRENT = "Current"; - public static final String SELECTED = "Selected"; - public static final String USE_CUSTOM = "Use Custom"; - public static final String DEFAULT = "Default"; - public static final String DEFAULT_2 = "Default 2"; - public static final String SMALL = "Small"; - public static final String EDITOR = "Editor"; - public static final String SAVED_WITH_LEFT_OPEN = "Saved With Left Open"; - public static final String TOP_LEVEL_PACKAGE = "Top Level Package"; - public static final String SYNTHETIC_PARAMETERS = "Synthetic Parameters"; - public static final String LINE_NUMBERS_FOREGROUND = "Line Numbers Foreground"; - public static final String LINE_NUMBERS_BACKGROUND = "Line Numbers Background"; - public static final String LINE_NUMBERS_SELECTED = "Line Numbers Selected"; - public static final String OBFUSCATED = "Obfuscated"; - public static final String OBFUSCATED_ALPHA = "Obfuscated Alpha"; - public static final String OBFUSCATED_OUTLINE = "Obfuscated Outline"; - public static final String OBFUSCATED_OUTLINE_ALPHA = "Obfuscated Outline Alpha"; - public static final String PROPOSED = "Proposed"; - public static final String PROPOSED_ALPHA = "Proposed Alpha"; - public static final String PROPOSED_OUTLINE = "Proposed Outline"; - public static final String PROPOSED_OUTLINE_ALPHA = "Proposed Outline Alpha"; - public static final String DEOBFUSCATED = "Deobfuscated"; - public static final String DEOBFUSCATED_ALPHA = "Deobfuscated Alpha"; - public static final String DEOBFUSCATED_OUTLINE = "Deobfuscated Outline"; - public static final String DEOBFUSCATED_OUTLINE_ALPHA = "Deobfuscated Outline Alpha"; - public static final String EDITOR_BACKGROUND = "Editor Background"; - public static final String HIGHLIGHT = "Highlight"; - public static final String CARET = "Caret"; - public static final String SELECTION_HIGHLIGHT = "Selection Highlight"; - public static final String STRING = "String"; - public static final String NUMBER = "Number"; - public static final String OPERATOR = "Operator"; - public static final String DELIMITER = "Delimiter"; - public static final String TYPE = "Type"; - public static final String IDENTIFIER = "Identifier"; - public static final String TEXT = "Text"; - public static final String COMMENT = "Comment"; - public static final String DEBUG_TOKEN = "Debug Token"; - public static final String DEBUG_TOKEN_ALPHA = "Debug Token Alpha"; - public static final String DEBUG_TOKEN_OUTLINE = "Debug Token Outline"; - public static final String DEBUG_TOKEN_OUTLINE_ALPHA = "Debug Token Outline Alpha"; - public static final String DOCK_HIGHLIGHT = "Dock Highlight"; - public static final String SERVER_NOTIFICATION_LEVEL = "Server Notification Level"; - public static final String RECENT_FILES = "Recent Files"; - public static final String MAX_RECENT_FILES = "Max Recent Files"; - - public static final String PAIR_SEPARATOR = ";"; - - private UiConfig() { - } - - // General UI configuration such as localization - private static final ConfigContainer ui = ConfigContainer.getOrCreate("enigma/enigmaui"); - // Swing specific configuration such as theming - private static final ConfigContainer swing = ConfigContainer.getOrCreate("enigma/enigmaswing"); - - // These are used for getting stuff that needs to stay constant for the - // runtime of the program, e.g. the current theme, because changing of these - // settings without a restart isn't implemented correctly yet. - // Don't change the values in this container with the expectation that they - // get saved, this is purely a backup of the configuration that existed at - // startup. - private static ConfigSection runningSwing; +public final class UiConfig extends ReflectiveConfig { + static { - UiConfig.snapshotConfig(); updateSyntaxpain(); } - // Saves the current configuration state so a consistent user interface can - // be provided for parts of the interface that don't support changing the - // configuration at runtime. Calling this after any UI elements are - // displayed can lead to visual glitches! - public static void snapshotConfig() { - runningSwing = swing.data().copy(); - } - - public static void save() { - ui.save(); - swing.save(); - } - - public static String getLanguage() { - return ui.data().section(GENERAL).setIfAbsentString(LANGUAGE, I18n.DEFAULT_LANGUAGE); - } - - public static void setLanguage(String language) { - ui.data().section(GENERAL).setString(LANGUAGE, language); - } - - public static float getScaleFactor() { - return (float) swing.data().section(GENERAL).setIfAbsentDouble(SCALE_FACTOR, 1.0); - } - - public static float getActiveScaleFactor() { - return (float) swing.data().section(GENERAL).setIfAbsentDouble(SCALE_FACTOR, 1.0); - } - - public static void setScaleFactor(float scale) { - swing.data().section(GENERAL).setDouble(SCALE_FACTOR, scale); - } - - public static void setHostedDockers(Docker.Side side, Docker[] dockers) { - String[] dockerData = new String[]{"", ""}; - for (int i = 0; i < dockers.length; i++) { - Docker docker = dockers[i]; - - if (docker != null) { - Docker.Location location = Dock.Util.findLocation(docker); - if (location != null) { - dockerData[i] = (docker.getId() + PAIR_SEPARATOR + location.verticalLocation()); - } - } - } - - swing.data().section(HOSTED_DOCKERS).setArray(side.name(), dockerData); - } - - public static Optional> getHostedDockers(DockerManager manager, Docker.Side side) { - Optional hostedDockers = swing.data().section(HOSTED_DOCKERS).getArray(side.name()); - - if (hostedDockers.isEmpty()) { - return Optional.empty(); - } - - Map dockers = new HashMap<>(); - - for (String dockInfo : hostedDockers.get()) { - if (!dockInfo.isBlank()) { - String[] split = dockInfo.split(PAIR_SEPARATOR); - - try { - Docker.VerticalLocation location = Docker.VerticalLocation.valueOf(split[1]); - Docker docker = manager.getDocker(split[0]); - - dockers.put(docker, location); - } catch (Exception e) { - Logger.error("failed to read docker state for {}, ignoring! ({})", dockInfo, e.getMessage()); - } - } - } - - return Optional.of(dockers); - } - - public static void setDockerButtonLocation(Docker docker, Docker.Location location) { - swing.data().section(DOCKER_BUTTON_LOCATIONS).setString(docker.getId(), location.toString()); - } - - public static Docker.Location getButtonLocation(Docker docker) { - String location = swing.data().section(DOCKER_BUTTON_LOCATIONS).setIfAbsentString(docker.getId(), docker.getPreferredButtonLocation().toString()); - - try { - return Docker.Location.parse(location); - } catch (Exception e) { - Logger.error("invalid docker button location: {}, ignoring!", location); - setDockerButtonLocation(docker, docker.getPreferredButtonLocation()); - return docker.getPreferredButtonLocation(); - } - } - - public static void setVerticalDockDividerLocation(Docker.Side side, int location) { - swing.data().section(VERTICAL_DIVIDER_LOCATIONS).setInt(side.name(), location); - } - - public static int getVerticalDockDividerLocation(Docker.Side side) { - return swing.data().section(VERTICAL_DIVIDER_LOCATIONS).setIfAbsentInt(side.name(), 300); - } - - public static void setHorizontalDividerLocation(Docker.Side side, int location) { - swing.data().section(HORIZONTAL_DIVIDER_LOCATIONS).setInt(side.name(), location); - } - - public static int getHorizontalDividerLocation(Docker.Side side) { - return swing.data().section(HORIZONTAL_DIVIDER_LOCATIONS).setIfAbsentInt(side.name(), side == Docker.Side.LEFT ? 300 : 700); - } - - public static void setSavedWithLeftOpen(boolean open) { - swing.data().section(GENERAL).setBool(SAVED_WITH_LEFT_OPEN, open); - } - - public static boolean getSavedWithLeftOpen() { - return swing.data().section(GENERAL).setIfAbsentBool(SAVED_WITH_LEFT_OPEN, false); - } - - public static void setMaxRecentFiles(int max) { - ui.data().setInt(MAX_RECENT_FILES, max); - } - - public static int getMaxRecentFiles() { - return ui.data().setIfAbsentInt(MAX_RECENT_FILES, 10); - } - - /** - * Adds a new file pair first in the recent files list, limiting the new list's size to {@link #MAX_RECENT_FILES}. If the pair is already in the list, moves it to the top. - * @param jar a path to the jar being mapped - * @param mappings a path to the mappings save location - */ - public static void addRecentFilePair(Path jar, Path mappings) { - var pairs = getRecentFilePairs(); - var pair = new Pair<>(jar, mappings); - - pairs.remove(pair); - pairs.add(0, pair); - - ui.data().setArray(RECENT_FILES, pairs.stream().limit(getMaxRecentFiles()).map(p -> p.a().toString() + PAIR_SEPARATOR + p.b().toString()).toArray(String[]::new)); - } - - /** - * Returns the most recently accessed project. - * @return A pair containing the jar path as its left element and the mappings path as its right element. - */ - public static Optional> getMostRecentFilePair() { - var recentFilePairs = getRecentFilePairs(); - if (recentFilePairs.isEmpty()) { - return Optional.empty(); - } - - return Optional.of(recentFilePairs.get(0)); - } - - /** - * Returns all recently accessed projects, up to a limit of {@link #MAX_RECENT_FILES}. - * @return a list of pairs containing the jar path as their left element and the mappings path as their right element. - */ - public static List> getRecentFilePairs() { - List> pairs = new ArrayList<>(); - - String[] pairsArray = ui.data().getArray(RECENT_FILES).orElse(new String[0]); - - for (String filePair : pairsArray) { - if (!filePair.isBlank()) { - var pairOptional = parseFilePair(filePair); - - if (pairOptional.isPresent()) { - pairs.add(pairOptional.get()); - } else { - Logger.error("failed to read recent file state for {}, ignoring!", filePair); - } - } - } - - return pairs; - } - - private static Optional> parseFilePair(String pair) { - String[] split = pair.split(PAIR_SEPARATOR); - - if (split.length != 2) { - return Optional.empty(); - } - - String jar = split[0]; - String mappings = split[1]; - return Optional.of(new Pair<>(Paths.get(jar), Paths.get(mappings))); - } + public final TrackedValue language = this.value(I18n.DEFAULT_LANGUAGE); + public final TrackedValue scaleFactor = this.value(1.0); + public final TrackedValue dockerConfig = this.value(new DockerConfig()); + public final TrackedValue maxRecentFiles = this.value(10); + public final TrackedValue recentFiles = this.value(new RecentFiles()); + public final TrackedValue lookAndFeel = this.value(LookAndFeel.DEFAULT); + public final LookAndFeel activeLookAndFeel = lookAndFeel.value(); - public static LookAndFeel getLookAndFeel() { - return swing.data().section(THEMES).setIfAbsentEnum(LookAndFeel::valueOf, CURRENT, LookAndFeel.NONE); - } + public final TrackedValue serverNotificationLevel = this.value(NotificationManager.ServerNotificationLevel.FULL); - public static LookAndFeel getActiveLookAndFeel() { - return swing.data().section(THEMES).setIfAbsentEnum(LookAndFeel::valueOf, CURRENT, LookAndFeel.NONE); - } + public final TrackedValue defaultColors = this.value(new ThemeColors()); + public final TrackedValue darculaColors = this.value(new ThemeColors()); + public final TrackedValue metalColors = this.value(new ThemeColors()); + public final TrackedValue systemColors = this.value(new ThemeColors()); + public final TrackedValue noneColors = this.value(new ThemeColors()); - public static void setLookAndFeel(LookAndFeel laf) { - swing.data().section(THEMES).setEnum(CURRENT, laf); - } - public static Decompiler getDecompiler() { - return ui.data().section(DECOMPILER).setIfAbsentEnum(Decompiler::valueOfLegacy, CURRENT, Decompiler.VINEFLOWER); - } - - public static void setDecompiler(Decompiler d) { - ui.data().section(DECOMPILER).setEnum(CURRENT, d); - } - - public static NotificationManager.ServerNotificationLevel getServerNotificationLevel() { - return swing.data().section(GENERAL).setIfAbsentEnum(NotificationManager.ServerNotificationLevel::valueOf, SERVER_NOTIFICATION_LEVEL, NotificationManager.ServerNotificationLevel.FULL); - } + public static final class Colors extends Section { - public static void setServerNotificationLevel(NotificationManager.ServerNotificationLevel level) { - swing.data().section(GENERAL).setEnum(SERVER_NOTIFICATION_LEVEL, level); } private static Color fromComponents(int rgb, double alpha) { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/nonsense.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/nonsense.java new file mode 100644 index 000000000..314a56a2c --- /dev/null +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/nonsense.java @@ -0,0 +1,67 @@ +package org.quiltmc.enigma.gui.config; + +import org.quiltmc.enigma.gui.docker.Dock; +import org.quiltmc.enigma.gui.docker.Docker; +import org.quiltmc.enigma.gui.docker.DockerManager; +import org.tinylog.Logger; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +public class nonsense { + public static void setHostedDockers(Docker.Side side, Docker[] dockers) { + String[] dockerData = new String[]{"", ""}; + for (int i = 0; i < dockers.length; i++) { + Docker docker = dockers[i]; + + if (docker != null) { + Docker.Location location = Dock.Util.findLocation(docker); + if (location != null) { + dockerData[i] = (docker.getId() + PAIR_SEPARATOR + location.verticalLocation()); + } + } + } + + swing.data().section(HOSTED_DOCKERS).setArray(side.name(), dockerData); + } + + public static Optional> getHostedDockers(DockerManager manager, Docker.Side side) { + Optional hostedDockers = swing.data().section(HOSTED_DOCKERS).getArray(side.name()); + + if (hostedDockers.isEmpty()) { + return Optional.empty(); + } + + Map dockers = new HashMap<>(); + + for (String dockInfo : hostedDockers.get()) { + if (!dockInfo.isBlank()) { + String[] split = dockInfo.split(PAIR_SEPARATOR); + + try { + Docker.VerticalLocation location = Docker.VerticalLocation.valueOf(split[1]); + Docker docker = manager.getDocker(split[0]); + + dockers.put(docker, location); + } catch (Exception e) { + Logger.error("failed to read docker state for {}, ignoring! ({})", dockInfo, e.getMessage()); + } + } + } + + return Optional.of(dockers); + } + + public static Docker.Location getButtonLocation(Docker docker) { + String location = swing.data().section(DOCKER_BUTTON_LOCATIONS).setIfAbsentString(docker.getId(), docker.getPreferredButtonLocation().toString()); + + try { + return Docker.Location.parse(location); + } catch (Exception e) { + Logger.error("invalid docker button location: {}, ignoring!", location); + setDockerButtonLocation(docker, docker.getPreferredButtonLocation()); + return docker.getPreferredButtonLocation(); + } + } +} From 293af44f46c8fcb431f4dc8babe7d95127b06d06 Mon Sep 17 00:00:00 2001 From: ix0rai Date: Tue, 17 Oct 2023 21:20:57 -0500 Subject: [PATCH 03/25] more work --- .../main/java/org/quiltmc/enigma/gui/Gui.java | 11 +++++-- .../java/org/quiltmc/enigma/gui/Main.java | 2 +- .../enigma/gui/config/DecompilerConfig.java | 18 +++++------ .../enigma/gui/config/DockerConfig.java | 31 +++++++++++++++++-- .../quiltmc/enigma/gui/config/UiConfig.java | 2 +- .../org/quiltmc/enigma/TestPackageRename.java | 2 +- 6 files changed, 48 insertions(+), 18 deletions(-) diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java index 2f8c1a413..bb5a77617 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java @@ -3,6 +3,7 @@ import org.quiltmc.enigma.api.Enigma; import org.quiltmc.enigma.api.EnigmaProfile; import org.quiltmc.enigma.api.analysis.EntryReference; +import org.quiltmc.enigma.gui.config.DockerConfig; import org.quiltmc.enigma.gui.config.NetConfig; import org.quiltmc.enigma.gui.config.Themes; import org.quiltmc.enigma.gui.config.UiConfig; @@ -67,6 +68,7 @@ public class Gui { private final MainWindow mainWindow; private final GuiController controller; + private final UiConfig config; private ConnectionState connectionState; private boolean isJarOpen; @@ -99,7 +101,8 @@ public class Gui { public final JFileChooser exportJarFileChooser; public final SearchDialog searchDialog; - public Gui(EnigmaProfile profile, Set editableTypes, boolean visible) { + public Gui(EnigmaProfile profile, Set editableTypes, boolean visible, UiConfig config) { + this.config = config; this.dockerManager = new DockerManager(this); this.mainWindow = new MainWindow(this, Enigma.NAME); this.centerPanel = new JPanel(new BorderLayout()); @@ -145,6 +148,10 @@ private void setupDockers() { this.dockerManager.registerDocker(new AllClassesDocker(this)); this.dockerManager.registerDocker(new DeobfuscatedClassesDocker(this)); + if (this.config.dockerConfig.dockerLocations.value().isEmpty()) { + this.config.dockerConfig.dockerLocations.value().setValue(DockerConfig.getDefaultLocations(this.dockerManager)); + } + // set default docker sizes for (Docker docker : this.dockerManager.getDockers()) { docker.setPreferredSize(new Dimension(300, 100)); @@ -154,8 +161,6 @@ private void setupDockers() { for (Docker.Side side : Docker.Side.values()) { this.mainWindow.getDockerSelector(side).configure(); } - - //todo: setup default docker config } private void setupUi() { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java index b7ef1c0c2..c2e0535dd 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java @@ -105,7 +105,7 @@ public static void main(String[] args) throws IOException { KeyBinds.loadConfig(); - Gui gui = new Gui(parsedProfile, editables, true); + Gui gui = new Gui(parsedProfile, editables, true, config); GuiController controller = gui.getController(); if (options.has("hide-progress-bars")) { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java index 220c702da..82407715e 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java @@ -2,34 +2,32 @@ import org.quiltmc.config.api.ReflectiveConfig; import org.quiltmc.config.api.values.TrackedValue; +import org.quiltmc.config.api.values.ValueMap; import org.quiltmc.enigma.api.config.ConfigContainer; import org.quiltmc.enigma.api.config.ConfigSection; import org.quiltmc.enigma.impl.source.vineflower.VineflowerPreferences; +import javax.sound.midi.Track; import java.util.HashSet; import java.util.Map; public class DecompilerConfig extends ReflectiveConfig.Section { public final TrackedValue decompiler = this.value(Decompiler.VINEFLOWER); + public final VineflowerSection vineflowerSection = new VineflowerSection(); private static final String VINEFLOWER = Decompiler.VINEFLOWER.name(); private DecompilerConfig() { } - private static final ConfigContainer cfg = ConfigContainer.getOrCreate("enigma/decompilers"); - - public static void save() { - cfg.save(); - } - - private static ConfigSection getVineflowerSection() { - return cfg.data().section(VINEFLOWER); + private class VineflowerSection extends ReflectiveConfig.Section { + public final TrackedValue> stringValues; + public final TrackedValue> intValues; + public final TrackedValue> } public static void updateVineflowerValues(Map options) { - ConfigSection section = getVineflowerSection(); - new HashSet<>(section.values().keySet()).forEach(section::remove); + this.vineflowerSection. for (Map.Entry entry : options.entrySet()) { if (entry.getValue() instanceof String s) { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java index 6570e7b18..cdeae0cb8 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java @@ -3,9 +3,17 @@ import org.quiltmc.config.api.ReflectiveConfig; import org.quiltmc.config.api.values.TrackedValue; import org.quiltmc.config.api.values.ValueMap; +import org.quiltmc.enigma.gui.docker.CallsTreeDocker; +import org.quiltmc.enigma.gui.docker.ClassesDocker; +import org.quiltmc.enigma.gui.docker.CollabDocker; +import org.quiltmc.enigma.gui.docker.DeobfuscatedClassesDocker; import org.quiltmc.enigma.gui.docker.Docker; import org.quiltmc.enigma.gui.docker.DockerManager; +import org.quiltmc.enigma.gui.docker.ImplementationsTreeDocker; +import org.quiltmc.enigma.gui.docker.InheritanceTreeDocker; +import org.quiltmc.enigma.gui.docker.NotificationsDocker; import org.quiltmc.enigma.gui.docker.ObfuscatedClassesDocker; +import org.quiltmc.enigma.gui.docker.StructureDocker; import org.quiltmc.enigma.util.Pair; public class DockerConfig extends ReflectiveConfig.Section { @@ -29,8 +37,27 @@ private static void putDockerLocation(TrackedValue locations.value().put(id, new Pair<>(location.side().toString(), location.verticalLocation().toString())); } - public static DockerConfig getDefault(DockerManager manager) { + private static void putDockerLocation(DockerConfig config, Docker docker, Docker.Side side, Docker.VerticalLocation verticalLocation) { + putDockerLocation(config.dockerLocations, docker.getId(), new Docker.Location(side, verticalLocation)); + } + + public static TrackedValue>> getDefaultLocations(DockerManager manager) { DockerConfig defaultConfig = new DockerConfig(); - putDockerLocation(defaultConfig.dockerLocations, manager.getDocker(ObfuscatedClassesDocker.class).getId(), new Docker.Location(Docker.Side.LEFT, Docker.VerticalLocation.TOP)); + + // left + putDockerLocation(defaultConfig, manager.getDocker(ObfuscatedClassesDocker.class), Docker.Side.LEFT, Docker.VerticalLocation.TOP); + putDockerLocation(defaultConfig, manager.getDocker(ClassesDocker.class), Docker.Side.LEFT, Docker.VerticalLocation.TOP); + putDockerLocation(defaultConfig, manager.getDocker(DeobfuscatedClassesDocker.class), Docker.Side.LEFT, Docker.VerticalLocation.BOTTOM); + + // right + putDockerLocation(defaultConfig, manager.getDocker(StructureDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); + putDockerLocation(defaultConfig, manager.getDocker(InheritanceTreeDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); + putDockerLocation(defaultConfig, manager.getDocker(ImplementationsTreeDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); + putDockerLocation(defaultConfig, manager.getDocker(CallsTreeDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); + + putDockerLocation(defaultConfig, manager.getDocker(CollabDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.BOTTOM); + putDockerLocation(defaultConfig, manager.getDocker(NotificationsDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.BOTTOM); + + return defaultConfig.dockerLocations; } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/UiConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/UiConfig.java index ac5c3f59f..9ce2232cf 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/UiConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/UiConfig.java @@ -39,7 +39,7 @@ public final class UiConfig extends ReflectiveConfig { public final TrackedValue language = this.value(I18n.DEFAULT_LANGUAGE); public final TrackedValue scaleFactor = this.value(1.0); - public final TrackedValue dockerConfig = this.value(new DockerConfig()); + public final DockerConfig dockerConfig = new DockerConfig(); public final TrackedValue maxRecentFiles = this.value(10); public final TrackedValue recentFiles = this.value(new RecentFiles()); public final TrackedValue lookAndFeel = this.value(LookAndFeel.DEFAULT); diff --git a/enigma-swing/src/test/java/org/quiltmc/enigma/TestPackageRename.java b/enigma-swing/src/test/java/org/quiltmc/enigma/TestPackageRename.java index c650e14b4..5c73574df 100644 --- a/enigma-swing/src/test/java/org/quiltmc/enigma/TestPackageRename.java +++ b/enigma-swing/src/test/java/org/quiltmc/enigma/TestPackageRename.java @@ -118,7 +118,7 @@ private static void renamePackage(String packageName, String newName, PackageRen private static ClassSelectorPopupMenu setupMenu() throws InterruptedException { Set editables = EnumSet.allOf(EditableType.class); editables.addAll(List.of(EditableType.values())); - Gui gui = new Gui(EnigmaProfile.EMPTY, editables, false); + Gui gui = new Gui(EnigmaProfile.EMPTY, editables, false, config); gui.setShowsProgressBars(false); CountDownLatch latch = new CountDownLatch(1); From b43db59a24d527da870e4c6502ae2f93f7c466a6 Mon Sep 17 00:00:00 2001 From: ix0rai Date: Tue, 21 Nov 2023 20:46:56 -0600 Subject: [PATCH 04/25] wip stuff --- .../main/java/org/quiltmc/enigma/gui/Gui.java | 28 +- .../org/quiltmc/enigma/gui/GuiController.java | 10 +- .../java/org/quiltmc/enigma/gui/Main.java | 8 +- .../org/quiltmc/enigma/gui/config/Config.java | 81 ++++ .../enigma/gui/config/DecompilerConfig.java | 37 +- .../enigma/gui/config/KeyBindsConfig.java | 16 +- .../quiltmc/enigma/gui/config/NetConfig.java | 58 +-- .../enigma/gui/config/RecentFiles.java | 76 ---- .../enigma/gui/config/ThemeColors.java | 106 ----- .../quiltmc/enigma/gui/config/UiConfig.java | 380 ------------------ .../gui/config/{ => theme}/LookAndFeel.java | 5 +- .../enigma/gui/config/theme/Theme.java | 14 + .../enigma/gui/config/theme/ThemeColors.java | 108 +++++ .../enigma/gui/config/theme/ThemeFonts.java | 13 + .../enigma/gui/config/{ => theme}/Themes.java | 29 +- .../quiltmc/enigma/gui/dialog/FontDialog.java | 24 +- .../enigma/gui/dialog/JavadocDialog.java | 4 +- .../enigma/gui/dialog/StatsDialog.java | 18 +- .../decompiler/VineflowerSettingsDialog.java | 1 - .../org/quiltmc/enigma/gui/docker/Dock.java | 24 +- .../org/quiltmc/enigma/gui/docker/Docker.java | 8 +- .../gui/docker/component/DockerButton.java | 8 +- .../gui/docker/component/DockerSelector.java | 6 +- .../quiltmc/enigma/gui/element/MenuBar.java | 62 +-- .../enigma/gui/event/ThemeChangeListener.java | 2 +- .../highlight/SelectionHighlightPainter.java | 4 +- .../quiltmc/enigma/gui/panel/EditorPanel.java | 12 +- .../gui/renderer/CallsTreeCellRenderer.java | 4 +- .../ImplementationsTreeCellRenderer.java | 4 +- .../renderer/InheritanceTreeCellRenderer.java | 6 +- .../org/quiltmc/enigma/gui/util/GuiUtil.java | 2 +- .../quiltmc/enigma/gui/util/ScaleUtil.java | 28 +- enigma/src/main/resources/lang/de_de.json | 1 - enigma/src/main/resources/lang/en_us.json | 1 - enigma/src/main/resources/lang/fr_fr.json | 1 - enigma/src/main/resources/lang/ja_jp.json | 1 - 36 files changed, 396 insertions(+), 794 deletions(-) create mode 100644 enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java delete mode 100644 enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/RecentFiles.java delete mode 100644 enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/ThemeColors.java delete mode 100644 enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/UiConfig.java rename enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/{ => theme}/LookAndFeel.java (94%) create mode 100644 enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java create mode 100644 enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/ThemeColors.java create mode 100644 enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/ThemeFonts.java rename enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/{ => theme}/Themes.java (75%) diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java index 9e8fff3d3..f5a668c4c 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java @@ -7,8 +7,8 @@ import org.quiltmc.enigma.api.translation.mapping.EntryRemapper; import org.quiltmc.enigma.gui.config.DockerConfig; import org.quiltmc.enigma.gui.config.NetConfig; -import org.quiltmc.enigma.gui.config.Themes; -import org.quiltmc.enigma.gui.config.UiConfig; +import org.quiltmc.enigma.gui.config.theme.Themes; +import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.dialog.JavadocDialog; import org.quiltmc.enigma.gui.dialog.SearchDialog; import org.quiltmc.enigma.gui.docker.AllClassesDocker; @@ -70,7 +70,7 @@ public class Gui { private final MainWindow mainWindow; private final GuiController controller; - private final UiConfig config; + private final Config config; private ConnectionState connectionState; private boolean isJarOpen; @@ -103,7 +103,7 @@ public class Gui { public final JFileChooser exportJarFileChooser; public final SearchDialog searchDialog; - public Gui(EnigmaProfile profile, Set editableTypes, boolean visible, UiConfig config) { + public Gui(EnigmaProfile profile, Set editableTypes, boolean visible, Config config) { this.config = config; this.dockerManager = new DockerManager(this); this.mainWindow = new MainWindow(this, Enigma.NAME); @@ -197,7 +197,7 @@ private void setupUi() { this.splitRight.setResizeWeight(1); this.splitLeft.setResizeWeight(0); - if (UiConfig.getHostedDockers(this.dockerManager, Docker.Side.LEFT).isPresent() || UiConfig.getHostedDockers(this.dockerManager, Docker.Side.RIGHT).isPresent()) { + if (Config.getHostedDockers(this.dockerManager, Docker.Side.LEFT).isPresent() || Config.getHostedDockers(this.dockerManager, Docker.Side.RIGHT).isPresent()) { this.dockerManager.restoreStateFromConfig(); } else { this.dockerManager.setupDefaultConfiguration(); @@ -210,11 +210,11 @@ private void setupUi() { JFrame frame = this.mainWindow.getFrame(); frame.addWindowListener(GuiUtil.onWindowClose(e -> this.close())); - frame.setSize(UiConfig.getWindowSize(UiConfig.MAIN_WINDOW, ScaleUtil.getDimension(1024, 576))); + frame.setSize(Config.getWindowSize(Config.MAIN_WINDOW, ScaleUtil.getDimension(1024, 576))); frame.setMinimumSize(ScaleUtil.getDimension(640, 480)); frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - Point windowPos = UiConfig.getWindowPos(UiConfig.MAIN_WINDOW, null); + Point windowPos = Config.getWindowPos(Config.MAIN_WINDOW, null); if (windowPos != null) { frame.setLocation(windowPos); } else { @@ -521,11 +521,11 @@ public void close() { } private void exit() { - UiConfig.setWindowPos(UiConfig.MAIN_WINDOW, this.mainWindow.getFrame().getLocationOnScreen()); - UiConfig.setWindowSize(UiConfig.MAIN_WINDOW, this.mainWindow.getFrame().getSize()); + Config.setWindowPos(Config.MAIN_WINDOW, this.mainWindow.getFrame().getLocationOnScreen()); + Config.setWindowSize(Config.MAIN_WINDOW, this.mainWindow.getFrame().getSize()); this.dockerManager.saveStateToConfig(); - UiConfig.save(); + Config.save(); this.searchDialog.dispose(); this.mainWindow.getFrame().dispose(); @@ -621,17 +621,17 @@ public void addMessage(ServerMessage message) { // popup notifications switch (message.getType()) { case CHAT -> { - if (UiConfig.getServerNotificationLevel().equals(NotificationManager.ServerNotificationLevel.FULL) && !message.user.equals(NetConfig.getUsername())) { + if (Config.getServerNotificationLevel().equals(NotificationManager.ServerNotificationLevel.FULL) && !message.user.equals(NetConfig.getUsername())) { this.notificationManager.notify(new ParameterizedMessage(Message.MULTIPLAYER_CHAT, message.translate())); } } case CONNECT -> { - if (UiConfig.getServerNotificationLevel() != NotificationManager.ServerNotificationLevel.NONE) { + if (Config.getServerNotificationLevel() != NotificationManager.ServerNotificationLevel.NONE) { this.notificationManager.notify(new ParameterizedMessage(Message.MULTIPLAYER_USER_CONNECTED, message.translate())); } } case DISCONNECT -> { - if (UiConfig.getServerNotificationLevel() != NotificationManager.ServerNotificationLevel.NONE) { + if (Config.getServerNotificationLevel() != NotificationManager.ServerNotificationLevel.NONE) { this.notificationManager.notify(new ParameterizedMessage(Message.MULTIPLAYER_USER_LEFT, message.translate())); } } @@ -705,7 +705,7 @@ public void reloadKeyBinds() { } public void openMostRecentFiles() { - var pair = UiConfig.getMostRecentFilePair(); + var pair = Config.getMostRecentFilePair(); if (pair.isPresent()) { this.getNotificationManager().notify(ParameterizedMessage.openedProject(pair.get().a().toString(), pair.get().b().toString())); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java index 7ef9d303b..15fce76c0 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java @@ -23,7 +23,7 @@ import org.quiltmc.enigma.api.class_handle.ClassHandleProvider; import org.quiltmc.enigma.api.class_provider.ClasspathClassProvider; import org.quiltmc.enigma.gui.config.NetConfig; -import org.quiltmc.enigma.gui.config.UiConfig; +import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.dialog.ProgressDialog; import org.quiltmc.enigma.gui.docker.CollabDocker; import org.quiltmc.enigma.api.stats.StatType; @@ -125,7 +125,7 @@ public CompletableFuture openJar(final Path jarPath) { return ProgressDialog.runOffThread(this.gui, progress -> { this.project = this.enigma.openJar(jarPath, new ClasspathClassProvider(), progress); this.indexTreeBuilder = new IndexTreeBuilder(this.project.getJarIndex()); - this.chp = new ClassHandleProvider(this.project, UiConfig.getDecompiler().service); + this.chp = new ClassHandleProvider(this.project, Config.getDecompiler().service); this.statsGenerator = new StatsGenerator(this.project); SwingUtilities.invokeLater(() -> { @@ -153,7 +153,7 @@ public CompletableFuture openMappings(MappingFormat format, Path path) { } this.gui.setMappingsFile(path); - UiConfig.addRecentFilePair(this.project.getJarPath(), path); + Config.addRecentFilePair(this.project.getJarPath(), path); this.gui.getMenuBar().reloadOpenRecentMenu(this.gui); return ProgressDialog.runOffThread(this.gui, progress -> { @@ -557,7 +557,7 @@ private void applyChange0(ValidationContext vc, EntryChange change, boolean u public void openStatsTree(Set includedTypes) { ProgressDialog.runOffThread(this.gui, progress -> { StatsResult overall = this.getStatsGenerator().getResultNullable().getOverall(); - StatsTree tree = overall.buildTree(UiConfig.getLastTopLevelPackage(), includedTypes); + StatsTree tree = overall.buildTree(Config.getLastTopLevelPackage(), includedTypes); String treeJson = GSON.toJson(tree.root); try { @@ -648,7 +648,7 @@ public synchronized void disconnectIfConnected(String reason) { }); this.gui.setUserList(new ArrayList<>()); - if (UiConfig.getServerNotificationLevel() != NotificationManager.ServerNotificationLevel.NONE) { + if (Config.getServerNotificationLevel() != NotificationManager.ServerNotificationLevel.NONE) { this.gui.getNotificationManager().notify(new ParameterizedMessage(Message.LEFT_SERVER)); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java index c2e0535dd..29fac472d 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java @@ -2,8 +2,8 @@ import org.quiltmc.enigma.api.EnigmaProfile; import org.quiltmc.enigma.gui.config.keybind.KeyBinds; -import org.quiltmc.enigma.gui.config.Themes; -import org.quiltmc.enigma.gui.config.UiConfig; +import org.quiltmc.enigma.gui.config.theme.Themes; +import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.dialog.CrashDialog; import org.quiltmc.enigma.util.I18n; import org.quiltmc.enigma.util.validation.Message; @@ -96,7 +96,7 @@ public static void main(String[] args) throws IOException { EnigmaProfile parsedProfile = EnigmaProfile.read(options.valueOf(profile)); - I18n.setLanguage(UiConfig.getLanguage()); + I18n.setLanguage(Config.getLanguage()); setDefaultSystemProperty("apple.laf.useScreenMenuBar", "true"); setDefaultSystemProperty("awt.useSystemAAFontSettings", "on"); setDefaultSystemProperty("swing.aatext", "true"); @@ -131,7 +131,7 @@ public static void main(String[] args) throws IOException { gui.getNotificationManager().notify(ParameterizedMessage.openedProject(jarPath.toString(), mappingsPath.toString())); } else { // search for mappings that are associated with the jar - for (var pair : UiConfig.getRecentFilePairs()) { + for (var pair : Config.getRecentFilePairs()) { if (pair.a().equals(jarPath)) { gui.getNotificationManager().notify(ParameterizedMessage.openedProject(pair.a().toString(), pair.b().toString())); gui.getController().openMappings(pair.b()); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java new file mode 100644 index 000000000..1fbf1baf4 --- /dev/null +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java @@ -0,0 +1,81 @@ +package org.quiltmc.enigma.gui.config; + +import org.quiltmc.config.api.ReflectiveConfig; +import org.quiltmc.config.api.values.TrackedValue; +import org.quiltmc.config.api.values.ValueMap; +import org.quiltmc.enigma.gui.NotificationManager; +import org.quiltmc.enigma.gui.config.theme.LookAndFeel; +import org.quiltmc.enigma.gui.config.theme.Theme; +import org.quiltmc.enigma.gui.config.theme.ThemeColors; +import org.quiltmc.enigma.gui.config.theme.ThemeFonts; +import org.quiltmc.enigma.gui.dialog.EnigmaQuickFindDialog; +import org.quiltmc.enigma.gui.util.ScaleUtil; +import org.quiltmc.enigma.util.I18n; +import org.quiltmc.syntaxpain.SyntaxpainConfiguration; + +import java.awt.Dimension; + +public final class Config extends ReflectiveConfig { + public static final Config INSTANCE = new Config(); + + public Config() { + this.updateSyntaxpain(); + } + + public final TrackedValue language = this.value(I18n.DEFAULT_LANGUAGE); + public final TrackedValue scaleFactor = this.value(1.0); + public final DockerConfig dockerConfig = new DockerConfig(); + public final TrackedValue maxRecentFiles = this.value(10); + public final TrackedValue> recentFiles = this.map("").build(); + public final TrackedValue serverNotificationLevel = this.value(NotificationManager.ServerNotificationLevel.FULL); + public final TrackedValue useCustomFonts = this.value(false); + public final TrackedValue windowSize = this.value(ScaleUtil.getDimension(1024, 576)); + public final TrackedValue lastSelectedDir = this.value(""); + public final TrackedValue lastTopLevelPackage = this.value(""); + public final TrackedValue shouldIncludeSyntheticParameters = this.value(false); + + public final TrackedValue lookAndFeel = this.value(LookAndFeel.DEFAULT); + // todo laf can't be changed while running + public final LookAndFeel activeLookAndFeel = this.lookAndFeel.value(); + + public final TrackedValue defaultTheme = this.value(new Theme(LookAndFeel.DEFAULT)); + public final TrackedValue darculaTheme = this.value(new Theme(LookAndFeel.DEFAULT)); + public final TrackedValue metalTheme = this.value(new Theme(LookAndFeel.METAL)); + public final TrackedValue systemTheme = this.value(new Theme(LookAndFeel.SYSTEM)); + public final TrackedValue noneTheme = this.value(new Theme(LookAndFeel.NONE)); + + public Theme getCurrentTheme() { + return switch (this.activeLookAndFeel) { + case DEFAULT -> this.defaultTheme.value(); + case DARCULA -> this.darculaTheme.value(); + case METAL -> this.metalTheme.value(); + case SYSTEM -> this.systemTheme.value(); + case NONE -> this.noneTheme.value(); + }; + } + + /** + * Updates the backend library Syntaxpain, used for code highlighting and other editor things. + */ + private void updateSyntaxpain() { + ThemeFonts fonts = this.getCurrentTheme().fonts.value(); + ThemeColors colors = this.getCurrentTheme().colors.value(); + + SyntaxpainConfiguration.setEditorFont(fonts.editor.value()); + SyntaxpainConfiguration.setQuickFindDialogFactory(EnigmaQuickFindDialog::new); + + SyntaxpainConfiguration.setLineRulerPrimaryColor(colors.lineNumbersForeground.value()); + SyntaxpainConfiguration.setLineRulerSecondaryColor(colors.lineNumbersBackground.value()); + SyntaxpainConfiguration.setLineRulerSelectionColor(colors.lineNumbersSelected.value()); + + SyntaxpainConfiguration.setHighlightColor(colors.highlight.value()); + SyntaxpainConfiguration.setStringColor(colors.string.value()); + SyntaxpainConfiguration.setNumberColor(colors.number.value()); + SyntaxpainConfiguration.setOperatorColor(colors.operator.value()); + SyntaxpainConfiguration.setDelimiterColor(colors.delimiter.value()); + SyntaxpainConfiguration.setTypeColor(colors.type.value()); + SyntaxpainConfiguration.setIdentifierColor(colors.identifier.value()); + SyntaxpainConfiguration.setCommentColour(colors.comment.value()); + SyntaxpainConfiguration.setTextColor(colors.text.value()); + } +} diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java index 82407715e..0a813b7df 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java @@ -3,48 +3,47 @@ import org.quiltmc.config.api.ReflectiveConfig; import org.quiltmc.config.api.values.TrackedValue; import org.quiltmc.config.api.values.ValueMap; -import org.quiltmc.enigma.api.config.ConfigContainer; -import org.quiltmc.enigma.api.config.ConfigSection; import org.quiltmc.enigma.impl.source.vineflower.VineflowerPreferences; -import javax.sound.midi.Track; -import java.util.HashSet; import java.util.Map; public class DecompilerConfig extends ReflectiveConfig.Section { public final TrackedValue decompiler = this.value(Decompiler.VINEFLOWER); - public final VineflowerSection vineflowerSection = new VineflowerSection(); + public final TrackedValue vineflowerSection = this.value(new VineflowerSection()); - private static final String VINEFLOWER = Decompiler.VINEFLOWER.name(); - - private DecompilerConfig() { - } - - private class VineflowerSection extends ReflectiveConfig.Section { - public final TrackedValue> stringValues; - public final TrackedValue> intValues; - public final TrackedValue> + private static class VineflowerSection extends ReflectiveConfig.Section { + public final TrackedValue> stringValues = this.map("").build(); + public final TrackedValue> intValues = this.map(0).build(); + public final TrackedValue> booleanValues = this.map(true).build(); } public static void updateVineflowerValues(Map options) { - this.vineflowerSection. + VineflowerSection section = // statically get it + null; for (Map.Entry entry : options.entrySet()) { if (entry.getValue() instanceof String s) { - section.setString(entry.getKey(), s); + section.stringValues.value().put(entry.getKey(), s); } else if (entry.getValue() instanceof Integer i) { - section.setInt(entry.getKey(), i); + section.intValues.value().put(entry.getKey(), i); } else if (entry.getValue() instanceof Boolean b) { - section.setBool(entry.getKey(), b); + section.booleanValues.value().put(entry.getKey(), b); } } } + public static VineflowerSection getVineflowerSection() { + // todo + return null; + } + public static void bootstrap() { // Just run the static initialization } static { - VineflowerPreferences.OPTIONS.putAll(getVineflowerSection().values()); + VineflowerPreferences.OPTIONS.putAll(getVineflowerSection().stringValues.value()); + VineflowerPreferences.OPTIONS.putAll(getVineflowerSection().intValues.value()); + VineflowerPreferences.OPTIONS.putAll(getVineflowerSection().booleanValues.value()); } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindsConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindsConfig.java index fd5064ea7..5dd312c3e 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindsConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindsConfig.java @@ -1,18 +1,14 @@ package org.quiltmc.enigma.gui.config; -import org.quiltmc.enigma.api.config.ConfigContainer; -import org.quiltmc.enigma.api.config.ConfigSection; +import org.quiltmc.config.api.ReflectiveConfig; +import org.quiltmc.config.api.values.TrackedValue; import org.quiltmc.enigma.gui.config.keybind.KeyBind; -public final class KeyBindsConfig { +public final class KeyBindsConfig extends ReflectiveConfig.Section { + private KeyBindsConfig() { } - private static final ConfigContainer cfg = ConfigContainer.getOrCreate("enigma/enigmakeybinds"); - - public static void save() { - cfg.save(); - } private static ConfigSection getSection(KeyBind keyBind) { return keyBind.category().isEmpty() ? cfg.data() : cfg.data().section(keyBind.category()); @@ -25,4 +21,8 @@ public static String[] getKeyBindCodes(KeyBind keyBind) { public static void setKeyBind(KeyBind keyBind) { getSection(keyBind).setArray(keyBind.name(), keyBind.serializeCombinations()); } + + private static class KeyBindConfig extends ReflectiveConfig.Section { + public final TrackedValue + } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NetConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NetConfig.java index 12172531c..17fd4cfa2 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NetConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NetConfig.java @@ -1,55 +1,13 @@ package org.quiltmc.enigma.gui.config; -import org.quiltmc.enigma.api.config.ConfigContainer; +import org.quiltmc.config.api.ReflectiveConfig; +import org.quiltmc.config.api.values.TrackedValue; import org.quiltmc.enigma.network.EnigmaServer; -public final class NetConfig { - private NetConfig() { - } - - private static final ConfigContainer cfg = ConfigContainer.getOrCreate("enigma/net"); - - public static void save() { - cfg.save(); - } - - public static String getUsername() { - return cfg.data().section("User").setIfAbsentString("Username", System.getProperty("user.name", "user")); - } - - public static void setUsername(String username) { - cfg.data().section("User").setString("Username", username); - } - - public static String getPassword() { - return cfg.data().section("Remote").getString("Password").orElse(""); - } - - public static void setPassword(String password) { - cfg.data().section("Remote").setString("Password", password); - } - - public static String getRemoteAddress() { - return cfg.data().section("Remote").getString("Address").orElse(""); - } - - public static void setRemoteAddress(String address) { - cfg.data().section("Remote").setString("Address", address); - } - - public static String getServerPassword() { - return cfg.data().section("Server").getString("Password").orElse(""); - } - - public static void setServerPassword(String password) { - cfg.data().section("Server").setString("Password", password); - } - - public static int getServerPort() { - return cfg.data().section("Server").setIfAbsentInt("Port", EnigmaServer.DEFAULT_PORT); - } - - public static void setServerPort(int port) { - cfg.data().section("Server").setInt("Port", port); - } +public final class NetConfig extends ReflectiveConfig.Section { + public final TrackedValue username = this.value(System.getProperty("user.name", "user")); + public final TrackedValue password = this.value(""); + public final TrackedValue remoteAddress = this.value(""); + public final TrackedValue serverPassword = this.value(""); + public final TrackedValue serverPort = this.value(EnigmaServer.DEFAULT_PORT); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/RecentFiles.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/RecentFiles.java deleted file mode 100644 index 3c7c10a1a..000000000 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/RecentFiles.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.quiltmc.enigma.gui.config; - -import org.quiltmc.enigma.util.Pair; -import org.tinylog.Logger; - -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -public class RecentFiles { - /** - * Adds a new file pair first in the recent files list, limiting the new list's size to {@link #MAX_RECENT_FILES}. If the pair is already in the list, moves it to the top. - * @param jar a path to the jar being mapped - * @param mappings a path to the mappings save location - */ - public static void addRecentFilePair(Path jar, Path mappings) { - var pairs = getRecentFilePairs(); - var pair = new Pair<>(jar, mappings); - - pairs.remove(pair); - pairs.add(0, pair); - - ui.data().setArray(RECENT_FILES, pairs.stream().limit(getMaxRecentFiles()).map(p -> p.a().toString() + PAIR_SEPARATOR + p.b().toString()).toArray(String[]::new)); - } - - /** - * Returns the most recently accessed project. - * @return A pair containing the jar path as its left element and the mappings path as its right element. - */ - public static Optional> getMostRecentFilePair() { - var recentFilePairs = getRecentFilePairs(); - if (recentFilePairs.isEmpty()) { - return Optional.empty(); - } - - return Optional.of(recentFilePairs.get(0)); - } - - /** - * Returns all recently accessed projects, up to a limit of {@link #MAX_RECENT_FILES}. - * @return a list of pairs containing the jar path as their left element and the mappings path as their right element. - */ - public static List> getRecentFilePairs() { - List> pairs = new ArrayList<>(); - - String[] pairsArray = ui.data().getArray(RECENT_FILES).orElse(new String[0]); - - for (String filePair : pairsArray) { - if (!filePair.isBlank()) { - var pairOptional = parseFilePair(filePair); - - if (pairOptional.isPresent()) { - pairs.add(pairOptional.get()); - } else { - Logger.error("failed to read recent file state for {}, ignoring!", filePair); - } - } - } - - return pairs; - } - - private static Optional> parseFilePair(String pair) { - String[] split = pair.split(PAIR_SEPARATOR); - - if (split.length != 2) { - return Optional.empty(); - } - - String jar = split[0]; - String mappings = split[1]; - return Optional.of(new Pair<>(Paths.get(jar), Paths.get(mappings))); - } -} diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/ThemeColors.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/ThemeColors.java deleted file mode 100644 index c70ad455d..000000000 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/ThemeColors.java +++ /dev/null @@ -1,106 +0,0 @@ -package org.quiltmc.enigma.gui.config; - -import org.quiltmc.config.api.ReflectiveConfig; -import org.quiltmc.config.api.values.TrackedValue; - -import java.awt.Color; - -public class ThemeColors extends ReflectiveConfig.Section { - private final TrackedValue lineNumbersForeground = this.value(new Color(0xFF333300, true)); - private final TrackedValue lineNumbersBackground = this.value(new Color(0xFFEEEEFF, true)); - private final TrackedValue lineNumbersSelected = this.value(new Color(0xFFCCCCEE, true)); - - private final TrackedValue obfuscated = this.value(new Color(0xFFFFDCDC, true)); - private final TrackedValue obfuscatedOutline = this.value(new Color(0xFFA05050, true)); - - private final TrackedValue proposed = this.value(new Color(0xFF000000, true)); - private final TrackedValue proposedOutline = this.value(new Color(0xBF000000, true)); - - private final TrackedValue deobfuscated = this.value(new Color(0xFFDCFFDC, true)); - private final TrackedValue deobfuscatedOutline = this.value(new Color(0xFF50A050, true)); - - private final TrackedValue editorBackground = this.value(new Color(0xFF50A050, true)); - private final TrackedValue highlight = this.value(new Color(0xFF50A050, true)); - private final TrackedValue caret = this.value(new Color(0xFF50A050, true)); - private final TrackedValue selectionHighlight = this.value(new Color(0xFF50A050, true)); - private final TrackedValue string = this.value(new Color(0xFFCC6600, true)); - private final TrackedValue number = this.value(new Color(0xFF999933, true)); - private final TrackedValue operator = this.value(new Color(0xFF000000, true)); - private final TrackedValue delimiter = this.value(new Color(0xFF000000, true)); - private final TrackedValue type = this.value(new Color(0xFF000000, true)); - private final TrackedValue identifier = this.value(new Color(0xFF000000, true)); - private final TrackedValue text = this.value(new Color(0xFF000000, true)); - - private final TrackedValue debugToken = this.value(new Color(0xFFD9BEF9, true)); - private final TrackedValue debugTokenOutline = this.value(new Color(0xFFBD93F9, true)); - - public void configure(boolean dark) { - if (dark) { - setIfAbsent(this.lineNumbersForeground, new Color(0xFFA4A4A3)); - setIfAbsent(this.lineNumbersBackground, new Color(0xFF313335)); - setIfAbsent(this.lineNumbersSelected, new Color(0xFF606366)); - - setIfAbsent(this.obfuscated, new Color(0x4DFF5555, true)); - setIfAbsent(this.obfuscatedOutline, new Color(0x80FF5555, true)); - - setIfAbsent(this.proposed, new Color(0x4D606366)); - setIfAbsent(this.proposedOutline, new Color(0x80606366)); - - setIfAbsent(this.deobfuscated, new Color(0x4D50FA7B)); - setIfAbsent(this.deobfuscatedOutline, new Color(0x50FA7B)); - - setIfAbsent(this.editorBackground, new Color(0xFF282A36)); - setIfAbsent(this.highlight, new Color(0xFFFF79C6)); - setIfAbsent(this.caret, new Color(0xFFF8F8F2)); - setIfAbsent(this.selectionHighlight, new Color(0xFFF8F8F2)); - setIfAbsent(this.string, new Color(0xFFF1FA8C)); - setIfAbsent(this.number, new Color(0xFFBD93F9)); - setIfAbsent(this.operator, new Color(0xFFF8F8F2)); - setIfAbsent(this.delimiter, new Color(0xFFF8F8F2)); - setIfAbsent(this.type, new Color(0xFFF8F8F2)); - setIfAbsent(this.identifier, new Color(0xFFF8F8F2)); - setIfAbsent(this.text, new Color(0xFFF8F8F2)); - - setIfAbsent(this.debugToken, new Color(0x804B1370)); - setIfAbsent(this.debugTokenOutline, new Color(0x80701367)); - } else { - resetIfAbsent(this.lineNumbersForeground); - resetIfAbsent(this.lineNumbersBackground); - resetIfAbsent(this.lineNumbersSelected); - - resetIfAbsent(this.obfuscated); - resetIfAbsent(this.obfuscatedOutline); - - resetIfAbsent(this.proposed); - resetIfAbsent(this.proposedOutline); - - resetIfAbsent(this.deobfuscated); - resetIfAbsent(this.deobfuscatedOutline); - - resetIfAbsent(this.editorBackground); - resetIfAbsent(this.highlight); - resetIfAbsent(this.caret); - resetIfAbsent(this.selectionHighlight); - resetIfAbsent(this.string); - resetIfAbsent(this.number); - resetIfAbsent(this.operator); - resetIfAbsent(this.delimiter); - resetIfAbsent(this.type); - resetIfAbsent(this.identifier); - resetIfAbsent(this.text); - - resetIfAbsent(this.debugToken); - resetIfAbsent(this.debugTokenOutline); - } - } - - private static void resetIfAbsent(TrackedValue value) { - setIfAbsent(value, value.getDefaultValue()); - } - - private static void setIfAbsent(TrackedValue value, T newValue) { - if (value.getDefaultValue().equals(value.value())) { - value.setValue(newValue, true); - } - } -} diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/UiConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/UiConfig.java deleted file mode 100644 index 9ce2232cf..000000000 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/UiConfig.java +++ /dev/null @@ -1,380 +0,0 @@ -package org.quiltmc.enigma.gui.config; - -import org.quiltmc.config.api.Config; -import org.quiltmc.config.api.Configs; -import org.quiltmc.config.api.ReflectiveConfig; -import org.quiltmc.config.api.values.TrackedValue; -import org.quiltmc.enigma.api.source.Decompilers; -import org.quiltmc.enigma.gui.dialog.EnigmaQuickFindDialog; -import org.quiltmc.enigma.gui.NotificationManager; -import org.quiltmc.enigma.gui.docker.Dock; -import org.quiltmc.enigma.gui.docker.Docker; -import org.quiltmc.enigma.gui.docker.DockerManager; -import org.quiltmc.enigma.gui.util.ScaleUtil; -import org.quiltmc.enigma.util.I18n; -import org.quiltmc.enigma.util.Pair; -import org.quiltmc.syntaxpain.SyntaxpainConfiguration; -import org.tinylog.Logger; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Point; -import java.awt.Toolkit; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.OptionalInt; - -public final class UiConfig extends ReflectiveConfig { - - - static { - updateSyntaxpain(); - } - - public final TrackedValue language = this.value(I18n.DEFAULT_LANGUAGE); - public final TrackedValue scaleFactor = this.value(1.0); - public final DockerConfig dockerConfig = new DockerConfig(); - public final TrackedValue maxRecentFiles = this.value(10); - public final TrackedValue recentFiles = this.value(new RecentFiles()); - public final TrackedValue lookAndFeel = this.value(LookAndFeel.DEFAULT); - public final LookAndFeel activeLookAndFeel = lookAndFeel.value(); - - public final TrackedValue serverNotificationLevel = this.value(NotificationManager.ServerNotificationLevel.FULL); - - public final TrackedValue defaultColors = this.value(new ThemeColors()); - public final TrackedValue darculaColors = this.value(new ThemeColors()); - public final TrackedValue metalColors = this.value(new ThemeColors()); - public final TrackedValue systemColors = this.value(new ThemeColors()); - public final TrackedValue noneColors = this.value(new ThemeColors()); - - - public static final class Colors extends Section { - - } - - private static Color fromComponents(int rgb, double alpha) { - int rgba = rgb & 0xFFFFFF | (int) (alpha * 255) << 24; - return new Color(rgba, true); - } - - private static Color getThemeColorRgba(String colorName) { - ConfigSection s = swing.data().section(THEMES).section(getActiveLookAndFeel().name()).section(COLORS); - return fromComponents(s.getRgbColor(colorName).orElse(0), s.getDouble(String.format("%s Alpha", colorName)).orElse(0)); - } - - private static Color getThemeColorRgb(String colorName) { - ConfigSection s = swing.data().section(THEMES).section(getActiveLookAndFeel().name()).section(COLORS); - return new Color(s.getRgbColor(colorName).orElse(0)); - } - - public static Color getObfuscatedColor() { - return getThemeColorRgba(OBFUSCATED); - } - - public static Color getObfuscatedOutlineColor() { - return getThemeColorRgba(OBFUSCATED_OUTLINE); - } - - public static Color getProposedColor() { - return getThemeColorRgba(PROPOSED); - } - - public static Color getProposedOutlineColor() { - return getThemeColorRgba(PROPOSED_OUTLINE); - } - - public static Color getDeobfuscatedColor() { - return getThemeColorRgba(DEOBFUSCATED); - } - - public static Color getDeobfuscatedOutlineColor() { - return getThemeColorRgba(DEOBFUSCATED_OUTLINE); - } - - public static Color getDebugTokenColor() { - return getThemeColorRgba(DEBUG_TOKEN); - } - - public static Color getDebugTokenOutlineColor() { - return getThemeColorRgba(DEBUG_TOKEN_OUTLINE); - } - - public static Color getEditorBackgroundColor() { - return getThemeColorRgb(EDITOR_BACKGROUND); - } - - public static Color getCaretColor() { - return getThemeColorRgb(CARET); - } - - public static Color getSelectionHighlightColor() { - return getThemeColorRgb(SELECTION_HIGHLIGHT); - } - - public static Color getNumberColor() { - return getThemeColorRgb(NUMBER); - } - - public static Color getTextColor() { - return getThemeColorRgb(TEXT); - } - - public static Color getDockHighlightColor() { - return getThemeColorRgb(DOCK_HIGHLIGHT); - } - - public static boolean useCustomFonts() { - return swing.data().section(THEMES).section(getActiveLookAndFeel().name()).section(FONTS).setIfAbsentBool(USE_CUSTOM, false); - } - - public static boolean activeUseCustomFonts() { - return swing.data().section(THEMES).section(getActiveLookAndFeel().name()).section(FONTS).setIfAbsentBool(USE_CUSTOM, false); - } - - public static void setUseCustomFonts(boolean b) { - swing.data().section(THEMES).section(getActiveLookAndFeel().name()).section(FONTS).setBool(USE_CUSTOM, b); - } - - public static Optional getFont(String name) { - Optional spec = swing.data().section(THEMES).section(getActiveLookAndFeel().name()).section(FONTS).getString(name); - return spec.map(Font::decode); - } - - public static Optional getActiveFont(String name) { - Optional spec = swing.data().section(THEMES).section(getActiveLookAndFeel().name()).section(FONTS).getString(name); - return spec.map(Font::decode); - } - - public static void setFont(String name, Font font) { - swing.data().section(THEMES).section(getLookAndFeel().name()).section(FONTS).setString(name, encodeFont(font)); - } - - public static Font getDefaultFont() { - return getActiveFont(DEFAULT).orElseGet(() -> ScaleUtil.scaleFont(Font.decode(Font.DIALOG).deriveFont(Font.BOLD))); - } - - public static Font getDefault2Font() { - return getActiveFont(DEFAULT_2).orElseGet(() -> ScaleUtil.scaleFont(Font.decode(Font.DIALOG))); - } - - public static Font getSmallFont() { - return getActiveFont(SMALL).orElseGet(() -> ScaleUtil.scaleFont(Font.decode(Font.DIALOG))); - } - - public static Font getEditorFont() { - return getActiveFont(EDITOR).orElseGet(UiConfig::getFallbackEditorFont); - } - - /** - * Gets the fallback editor font. - * It is used: - *
    - *
  • when there is no custom editor font chosen
  • - *
  • when custom fonts are disabled
  • - *
- * - * @return the fallback editor font - */ - public static Font getFallbackEditorFont() { - return ScaleUtil.scaleFont(Font.decode(Font.MONOSPACED)); - } - - public static String encodeFont(Font font) { - int style = font.getStyle(); - String s = switch (style) { - case Font.BOLD | Font.ITALIC -> "bolditalic"; - case Font.BOLD -> "bold"; - case Font.ITALIC -> "italic"; - default -> "plain"; - }; - - return String.format("%s-%s-%s", font.getName(), s, font.getSize()); - } - - public static Dimension getWindowSize(String window, Dimension fallback) { - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - ConfigSection section = swing.data().section(window); - OptionalInt width = section.getInt(String.format("Width %s", screenSize.width)); - OptionalInt height = section.getInt(String.format("Height %s", screenSize.height)); - if (width.isPresent() && height.isPresent()) { - return new Dimension(width.getAsInt(), height.getAsInt()); - } else { - return fallback; - } - } - - public static void setWindowSize(String window, Dimension dim) { - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - ConfigSection section = swing.data().section(window); - section.setInt(String.format("Width %s", screenSize.width), dim.width); - section.setInt(String.format("Height %s", screenSize.height), dim.height); - } - - public static Point getWindowPos(String window, Point fallback) { - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - ConfigSection section = swing.data().section(window); - OptionalInt x = section.getInt(String.format("X %s", screenSize.width)); - OptionalInt y = section.getInt(String.format("Y %s", screenSize.height)); - if (x.isPresent() && y.isPresent()) { - int ix = x.getAsInt(); - int iy = y.getAsInt(); - - // Ensure that the position is on the screen. - if (ix < 0 || iy < 0 || ix > screenSize.width || iy > screenSize.height) { - return fallback; - } - - return new Point(ix, iy); - } else { - return fallback; - } - } - - public static void setWindowPos(String window, Point rect) { - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - ConfigSection section = swing.data().section(window); - section.setInt(String.format("X %s", screenSize.width), rect.x); - section.setInt(String.format("Y %s", screenSize.height), rect.y); - } - - public static String getLastSelectedDir() { - return swing.data().section(FILE_DIALOG).getString(SELECTED).orElse(""); - } - - public static void setLastSelectedDir(String directory) { - swing.data().section(FILE_DIALOG).setString(SELECTED, directory); - } - - public static String getLastTopLevelPackage() { - return swing.data().section(MAPPING_STATS).getString(TOP_LEVEL_PACKAGE).orElse(""); - } - - public static void setLastTopLevelPackage(String topLevelPackage) { - swing.data().section(MAPPING_STATS).setString(TOP_LEVEL_PACKAGE, topLevelPackage); - } - - public static boolean shouldIncludeSyntheticParameters() { - return swing.data().section(MAPPING_STATS).setIfAbsentBool(SYNTHETIC_PARAMETERS, false); - } - - public static void setIncludeSyntheticParameters(boolean b) { - swing.data().section(MAPPING_STATS).setBool(SYNTHETIC_PARAMETERS, b); - } - - public static void setLookAndFeelDefaults(LookAndFeel laf, boolean isDark) { - ConfigSection s = swing.data().section(THEMES).section(laf.name()).section(COLORS); - - // theme-dependent colors - if (!isDark) { - // Defaults found here: https://github.com/Sciss/SyntaxPane/blob/122da367ff7a5d31627a70c62a48a9f0f4f85a0a/src/main/resources/de/sciss/syntaxpane/defaultsyntaxkit/config.properties#L139 - s.setIfAbsentRgbColor(LINE_NUMBERS_FOREGROUND, 0x333300); - s.setIfAbsentRgbColor(LINE_NUMBERS_BACKGROUND, 0xEEEEFF); - s.setIfAbsentRgbColor(LINE_NUMBERS_SELECTED, 0xCCCCEE); - - s.setIfAbsentRgbColor(OBFUSCATED, 0xFFDCDC); - s.setIfAbsentDouble(OBFUSCATED_ALPHA, 1.0); - s.setIfAbsentRgbColor(OBFUSCATED_OUTLINE, 0xA05050); - s.setIfAbsentDouble(OBFUSCATED_OUTLINE_ALPHA, 1.0); - - s.setIfAbsentRgbColor(PROPOSED, 0x000000); - s.setIfAbsentDouble(PROPOSED_ALPHA, 0.15); - s.setIfAbsentRgbColor(PROPOSED_OUTLINE, 0x000000); - s.setIfAbsentDouble(PROPOSED_OUTLINE_ALPHA, 0.75); - - s.setIfAbsentRgbColor(DEOBFUSCATED, 0xDCFFDC); - s.setIfAbsentDouble(DEOBFUSCATED_ALPHA, 1.0); - s.setIfAbsentRgbColor(DEOBFUSCATED_OUTLINE, 0x50A050); - s.setIfAbsentDouble(DEOBFUSCATED_OUTLINE_ALPHA, 1.0); - - s.setIfAbsentRgbColor(EDITOR_BACKGROUND, 0xFFFFFF); - s.setIfAbsentRgbColor(HIGHLIGHT, 0x3333EE); - s.setIfAbsentRgbColor(CARET, 0x000000); - s.setIfAbsentRgbColor(SELECTION_HIGHLIGHT, 0x000000); - s.setIfAbsentRgbColor(STRING, 0xCC6600); - s.setIfAbsentRgbColor(NUMBER, 0x999933); - s.setIfAbsentRgbColor(OPERATOR, 0x000000); - s.setIfAbsentRgbColor(DELIMITER, 0x000000); - s.setIfAbsentRgbColor(TYPE, 0x000000); - s.setIfAbsentRgbColor(IDENTIFIER, 0x000000); - s.setIfAbsentRgbColor(TEXT, 0x000000); - - s.setIfAbsentRgbColor(DEBUG_TOKEN, 0xD9BEF9); - s.setIfAbsentDouble(DEBUG_TOKEN_ALPHA, 1.0); - s.setIfAbsentRgbColor(DEBUG_TOKEN_OUTLINE, 0xBD93F9); - s.setIfAbsentDouble(DEBUG_TOKEN_OUTLINE_ALPHA, 1.0); - } else { - // Based off colors found here: https://github.com/dracula/dracula-theme/ - s.setIfAbsentRgbColor(LINE_NUMBERS_FOREGROUND, 0xA4A4A3); - s.setIfAbsentRgbColor(LINE_NUMBERS_BACKGROUND, 0x313335); - s.setIfAbsentRgbColor(LINE_NUMBERS_SELECTED, 0x606366); - - s.setIfAbsentRgbColor(OBFUSCATED, 0xFF5555); - s.setIfAbsentDouble(OBFUSCATED_ALPHA, 0.3); - s.setIfAbsentRgbColor(OBFUSCATED_OUTLINE, 0xFF5555); - s.setIfAbsentDouble(OBFUSCATED_OUTLINE_ALPHA, 0.5); - - s.setIfAbsentRgbColor(PROPOSED, 0x606366); - s.setIfAbsentDouble(PROPOSED_ALPHA, 0.3); - s.setIfAbsentRgbColor(PROPOSED_OUTLINE, 0x606366); - s.setIfAbsentDouble(PROPOSED_OUTLINE_ALPHA, 0.5); - - s.setIfAbsentRgbColor(DEOBFUSCATED, 0x50FA7B); - s.setIfAbsentDouble(DEOBFUSCATED_ALPHA, 0.3); - s.setIfAbsentRgbColor(DEOBFUSCATED_OUTLINE, 0x50FA7B); - s.setIfAbsentDouble(DEOBFUSCATED_OUTLINE_ALPHA, 0.5); - - s.setIfAbsentRgbColor(EDITOR_BACKGROUND, 0x282A36); - s.setIfAbsentRgbColor(HIGHLIGHT, 0xFF79C6); - s.setIfAbsentRgbColor(CARET, 0xF8F8F2); - s.setIfAbsentRgbColor(SELECTION_HIGHLIGHT, 0xF8F8F2); - s.setIfAbsentRgbColor(STRING, 0xF1FA8C); - s.setIfAbsentRgbColor(NUMBER, 0xBD93F9); - s.setIfAbsentRgbColor(OPERATOR, 0xF8F8F2); - s.setIfAbsentRgbColor(DELIMITER, 0xF8F8F2); - s.setIfAbsentRgbColor(TYPE, 0xF8F8F2); - s.setIfAbsentRgbColor(IDENTIFIER, 0xF8F8F2); - s.setIfAbsentRgbColor(TEXT, 0xF8F8F2); - - s.setIfAbsentRgbColor(DEBUG_TOKEN, 0x4B1370); - s.setIfAbsentDouble(DEBUG_TOKEN_ALPHA, 0.5); - s.setIfAbsentRgbColor(DEBUG_TOKEN_OUTLINE, 0x701367); - s.setIfAbsentDouble(DEBUG_TOKEN_OUTLINE_ALPHA, 0.5); - } - - // theme-independent colors - s.setIfAbsentRgbColor(DOCK_HIGHLIGHT, 0x0000FF); - s.setIfAbsentRgbColor(COMMENT, 0x339933); - - updateSyntaxpain(); - } - - /** - * Updates the backend library Syntaxpain, used for code highlighting and other editor things. - */ - private static void updateSyntaxpain() { - SyntaxpainConfiguration.setEditorFont(getEditorFont()); - SyntaxpainConfiguration.setQuickFindDialogFactory(EnigmaQuickFindDialog::new); - - ConfigSection colors = swing.data().section(THEMES).section(getLookAndFeel().name()).section(COLORS); - - SyntaxpainConfiguration.setLineRulerPrimaryColor(colors.getColor(LINE_NUMBERS_FOREGROUND)); - SyntaxpainConfiguration.setLineRulerSecondaryColor(colors.getColor(LINE_NUMBERS_BACKGROUND)); - SyntaxpainConfiguration.setLineRulerSelectionColor(colors.getColor(LINE_NUMBERS_SELECTED)); - - SyntaxpainConfiguration.setHighlightColor(colors.getColor(HIGHLIGHT)); - SyntaxpainConfiguration.setStringColor(colors.getColor(STRING)); - SyntaxpainConfiguration.setNumberColor(colors.getColor(NUMBER)); - SyntaxpainConfiguration.setOperatorColor(colors.getColor(OPERATOR)); - SyntaxpainConfiguration.setDelimiterColor(colors.getColor(DELIMITER)); - SyntaxpainConfiguration.setTypeColor(colors.getColor(TYPE)); - SyntaxpainConfiguration.setIdentifierColor(colors.getColor(IDENTIFIER)); - SyntaxpainConfiguration.setCommentColour(colors.getColor(COMMENT)); - SyntaxpainConfiguration.setTextColor(colors.getColor(TEXT)); - } -} diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/LookAndFeel.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/LookAndFeel.java similarity index 94% rename from enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/LookAndFeel.java rename to enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/LookAndFeel.java index edf2eb3ad..bfd6ace34 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/LookAndFeel.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/LookAndFeel.java @@ -1,8 +1,9 @@ -package org.quiltmc.enigma.gui.config; +package org.quiltmc.enigma.gui.config.theme; import com.formdev.flatlaf.FlatDarkLaf; import com.formdev.flatlaf.FlatLightLaf; import com.formdev.flatlaf.FlatSystemProperties; +import org.quiltmc.enigma.gui.config.Config; import java.awt.Color; import java.awt.Dimension; @@ -35,7 +36,7 @@ public boolean needsScaling() { public void setGlobalLAF() { // Configure FlatLaf's UI scale to be our scale factor. // This is also used for the SVG icons, so it applies even when some other LaF is active. - System.setProperty(FlatSystemProperties.UI_SCALE, Float.toString(UiConfig.getActiveScaleFactor())); + System.setProperty(FlatSystemProperties.UI_SCALE, Float.toString(Config.getActiveScaleFactor())); try { switch (this) { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java new file mode 100644 index 000000000..8450c3a80 --- /dev/null +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java @@ -0,0 +1,14 @@ +package org.quiltmc.enigma.gui.config.theme; + +import org.quiltmc.config.api.ReflectiveConfig; +import org.quiltmc.config.api.values.TrackedValue; + +public class Theme extends ReflectiveConfig.Section { + public final LookAndFeel lookAndFeel; + public Theme(LookAndFeel lookAndFeel) { + this.lookAndFeel = lookAndFeel; + } + + public final TrackedValue colors = this.value(new ThemeColors()); + public final TrackedValue fonts = this.value(new ThemeFonts()); +} diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/ThemeColors.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/ThemeColors.java new file mode 100644 index 000000000..949219ab7 --- /dev/null +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/ThemeColors.java @@ -0,0 +1,108 @@ +package org.quiltmc.enigma.gui.config.theme; + +import org.quiltmc.config.api.ReflectiveConfig; +import org.quiltmc.config.api.values.TrackedValue; + +import java.awt.Color; + +public class ThemeColors extends ReflectiveConfig.Section { + public final TrackedValue lineNumbersForeground = this.value(new Color(0xFF333300, true)); + public final TrackedValue lineNumbersBackground = this.value(new Color(0xFFEEEEFF, true)); + public final TrackedValue lineNumbersSelected = this.value(new Color(0xFFCCCCEE, true)); + + public final TrackedValue obfuscated = this.value(new Color(0xFFFFDCDC, true)); + public final TrackedValue obfuscatedOutline = this.value(new Color(0xFFA05050, true)); + + public final TrackedValue proposed = this.value(new Color(0xFF000000, true)); + public final TrackedValue proposedOutline = this.value(new Color(0xBF000000, true)); + + public final TrackedValue deobfuscated = this.value(new Color(0xFFDCFFDC, true)); + public final TrackedValue deobfuscatedOutline = this.value(new Color(0xFF50A050, true)); + + public final TrackedValue editorBackground = this.value(new Color(0xFF50A050, true)); + public final TrackedValue highlight = this.value(new Color(0xFF50A050, true)); + public final TrackedValue caret = this.value(new Color(0xFF50A050, true)); + public final TrackedValue selectionHighlight = this.value(new Color(0xFF50A050, true)); + public final TrackedValue string = this.value(new Color(0xFFCC6600, true)); + public final TrackedValue number = this.value(new Color(0xFF999933, true)); + public final TrackedValue operator = this.value(new Color(0xFF000000, true)); + public final TrackedValue delimiter = this.value(new Color(0xFF000000, true)); + public final TrackedValue type = this.value(new Color(0xFF000000, true)); + public final TrackedValue identifier = this.value(new Color(0xFF000000, true)); + public final TrackedValue comment = this.value(new Color(0xFF339933, true)); + public final TrackedValue text = this.value(new Color(0xFF000000, true)); + + private final TrackedValue debugToken = this.value(new Color(0xFFD9BEF9, true)); + private final TrackedValue debugTokenOutline = this.value(new Color(0xFFBD93F9, true)); + + public void configure(boolean dark) { + if (dark) { + setIfAbsent(this.lineNumbersForeground, new Color(0xFFA4A4A3, true)); + setIfAbsent(this.lineNumbersBackground, new Color(0xFF313335, true)); + setIfAbsent(this.lineNumbersSelected, new Color(0xFF606366, true)); + + setIfAbsent(this.obfuscated, new Color(0x4DFF5555, true)); + setIfAbsent(this.obfuscatedOutline, new Color(0x80FF5555, true)); + + setIfAbsent(this.proposed, new Color(0x4D606366, true)); + setIfAbsent(this.proposedOutline, new Color(0x80606366, true)); + + setIfAbsent(this.deobfuscated, new Color(0x4D50FA7B, true)); + setIfAbsent(this.deobfuscatedOutline, new Color(0x50FA7B, true)); + + setIfAbsent(this.editorBackground, new Color(0xFF282A36, true)); + setIfAbsent(this.highlight, new Color(0xFFFF79C6, true)); + setIfAbsent(this.caret, new Color(0xFFF8F8F2, true)); + setIfAbsent(this.selectionHighlight, new Color(0xFFF8F8F2)); + setIfAbsent(this.string, new Color(0xFFF1FA8C, true)); + setIfAbsent(this.number, new Color(0xFFBD93F9, true)); + setIfAbsent(this.operator, new Color(0xFFF8F8F2, true)); + setIfAbsent(this.delimiter, new Color(0xFFF8F8F2, true)); + setIfAbsent(this.type, new Color(0xFFF8F8F2, true)); + setIfAbsent(this.identifier, new Color(0xFFF8F8F2, true)); + setIfAbsent(this.comment, new Color(0xFF339933, true)); + setIfAbsent(this.text, new Color(0xFFF8F8F2, true)); + + setIfAbsent(this.debugToken, new Color(0x804B1370, true)); + setIfAbsent(this.debugTokenOutline, new Color(0x80701367, true)); + } else { + resetIfAbsent(this.lineNumbersForeground); + resetIfAbsent(this.lineNumbersBackground); + resetIfAbsent(this.lineNumbersSelected); + + resetIfAbsent(this.obfuscated); + resetIfAbsent(this.obfuscatedOutline); + + resetIfAbsent(this.proposed); + resetIfAbsent(this.proposedOutline); + + resetIfAbsent(this.deobfuscated); + resetIfAbsent(this.deobfuscatedOutline); + + resetIfAbsent(this.editorBackground); + resetIfAbsent(this.highlight); + resetIfAbsent(this.caret); + resetIfAbsent(this.selectionHighlight); + resetIfAbsent(this.string); + resetIfAbsent(this.number); + resetIfAbsent(this.operator); + resetIfAbsent(this.delimiter); + resetIfAbsent(this.type); + resetIfAbsent(this.identifier); + resetIfAbsent(this.text); + + resetIfAbsent(this.debugToken); + resetIfAbsent(this.debugTokenOutline); + } + } + + private static void resetIfAbsent(TrackedValue value) { + setIfAbsent(value, value.getDefaultValue()); + } + + private static void setIfAbsent(TrackedValue value, T newValue) { + if (value.getDefaultValue().equals(value.value())) { + value.setValue(newValue, true); + } + } +} diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/ThemeFonts.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/ThemeFonts.java new file mode 100644 index 000000000..27538634c --- /dev/null +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/ThemeFonts.java @@ -0,0 +1,13 @@ +package org.quiltmc.enigma.gui.config.theme; + +import org.quiltmc.config.api.ReflectiveConfig; +import org.quiltmc.config.api.values.TrackedValue; +import org.quiltmc.enigma.gui.util.ScaleUtil; + +import java.awt.Font; + +public class ThemeFonts extends ReflectiveConfig.Section { + public final TrackedValue defaultFont = this.value(Font.decode(Font.DIALOG).deriveFont(Font.BOLD)); + public final TrackedValue small = this.value(ScaleUtil.scaleFont(Font.decode(Font.DIALOG))); + public final TrackedValue editor = this.value(Font.decode(Font.MONOSPACED)); +} diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Themes.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java similarity index 75% rename from enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Themes.java rename to enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java index 6a457e76b..5d8cc67c1 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Themes.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java @@ -1,5 +1,6 @@ -package org.quiltmc.enigma.gui.config; +package org.quiltmc.enigma.gui.config.theme; +import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.event.ThemeChangeListener; import org.quiltmc.enigma.gui.highlight.BoxHighlightPainter; import org.quiltmc.enigma.gui.util.ScaleUtil; @@ -19,24 +20,24 @@ public class Themes { // Calling this after the UI is initialized (e.g. when the user changes // theme settings) is currently not functional. public static void setupTheme() { - LookAndFeel laf = UiConfig.getActiveLookAndFeel(); + LookAndFeel laf = Config.getActiveLookAndFeel(); laf.setGlobalLAF(); - UiConfig.setLookAndFeelDefaults(UiConfig.getLookAndFeel(), LookAndFeel.isDarkLaf()); - UiConfig.snapshotConfig(); + Config.setLookAndFeelDefaults(Config.getLookAndFeel(), LookAndFeel.isDarkLaf()); + Config.snapshotConfig(); Themes.setFonts(); UIManager.put("ScrollBar.showButtons", true); JEditorPane.registerEditorKitForContentType("text/enigma-sources", JavaSyntaxKit.class.getName()); Map boxHighlightPainters = getBoxHighlightPainters(); listeners.forEach(l -> l.onThemeChanged(laf, boxHighlightPainters)); ScaleUtil.applyScaling(); - UiConfig.save(); + Config.save(); } private static void setFonts() { - if (UiConfig.activeUseCustomFonts()) { - Font small = UiConfig.getSmallFont(); - Font bold = UiConfig.getDefaultFont(); - Font normal = UiConfig.getDefault2Font(); + if (Config.activeUseCustomFonts()) { + Font small = Config.getSmallFont(); + Font bold = Config.getDefaultFont(); + Font normal = Config.getDefault2Font(); UIManager.put("CheckBox.font", bold); UIManager.put("CheckBoxMenuItem.font", bold); @@ -83,11 +84,11 @@ private static void setFonts() { public static Map getBoxHighlightPainters() { return Map.of( - TokenType.OBFUSCATED, BoxHighlightPainter.create(UiConfig.getObfuscatedColor(), UiConfig.getObfuscatedOutlineColor()), - TokenType.JAR_PROPOSED, BoxHighlightPainter.create(UiConfig.getProposedColor(), UiConfig.getProposedOutlineColor()), - TokenType.DYNAMIC_PROPOSED, BoxHighlightPainter.create(UiConfig.getProposedColor(), UiConfig.getProposedOutlineColor()), - TokenType.DEOBFUSCATED, BoxHighlightPainter.create(UiConfig.getDeobfuscatedColor(), UiConfig.getDeobfuscatedOutlineColor()), - TokenType.DEBUG, BoxHighlightPainter.create(UiConfig.getDebugTokenColor(), UiConfig.getDebugTokenOutlineColor()) + TokenType.OBFUSCATED, BoxHighlightPainter.create(Config.getObfuscatedColor(), Config.getObfuscatedOutlineColor()), + TokenType.JAR_PROPOSED, BoxHighlightPainter.create(Config.getProposedColor(), Config.getProposedOutlineColor()), + TokenType.DYNAMIC_PROPOSED, BoxHighlightPainter.create(Config.getProposedColor(), Config.getProposedOutlineColor()), + TokenType.DEOBFUSCATED, BoxHighlightPainter.create(Config.getDeobfuscatedColor(), Config.getDeobfuscatedOutlineColor()), + TokenType.DEBUG, BoxHighlightPainter.create(Config.getDebugTokenColor(), Config.getDebugTokenOutlineColor()) ); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java index da9dc73f6..e06ab286c 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java @@ -1,6 +1,6 @@ package org.quiltmc.enigma.gui.dialog; -import org.quiltmc.enigma.gui.config.UiConfig; +import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.util.GridBagConstraintsBuilder; import org.quiltmc.enigma.gui.util.ScaleUtil; import org.quiltmc.enigma.util.I18n; @@ -19,16 +19,14 @@ import javax.swing.JList; public class FontDialog extends JDialog { - private static final List CATEGORIES = List.of( - "Default", - "Default 2", - "Small", - "Editor" + private static final List FONTS = List.of( + Config.INSTANCE.getCurrentTheme().fonts.value().defaultFont.value(), + Config.INSTANCE.getCurrentTheme().fonts.value().small.value(), + Config.INSTANCE.getCurrentTheme().fonts.value().editor.value() ); private static final List CATEGORY_TEXTS = List.of( "fonts.cat.default", - "fonts.cat.default2", "fonts.cat.small", "fonts.cat.editor" ); @@ -39,12 +37,10 @@ public class FontDialog extends JDialog { private final JButton okButton = new JButton(I18n.translate("prompt.ok")); private final JButton cancelButton = new JButton(I18n.translate("prompt.cancel")); - private final Font[] fonts = CATEGORIES.stream().map(name -> UiConfig.getFont(name).orElseGet(() -> ScaleUtil.scaleFont(Font.decode(Font.DIALOG)))).toArray(Font[]::new); - public FontDialog(Frame owner) { super(owner, "Fonts", true); - this.customCheckBox.setSelected(UiConfig.useCustomFonts()); + this.customCheckBox.setSelected(Config.INSTANCE.useCustomFonts.value()); this.entries.setPreferredSize(ScaleUtil.getDimension(100, 0)); @@ -97,12 +93,12 @@ private void updateUiState() { } private void apply() { - for (int i = 0; i < CATEGORIES.size(); i++) { - UiConfig.setFont(CATEGORIES.get(i), this.fonts[i]); + for (int i = 0; i < FONTS.size(); i++) { + Config.setFont(FONTS.get(i), this.fonts[i]); } - UiConfig.setUseCustomFonts(this.customCheckBox.isSelected()); - UiConfig.save(); + Config.setUseCustomFonts(this.customCheckBox.isSelected()); + Config.save(); ChangeDialog.show(this); this.dispose(); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/JavadocDialog.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/JavadocDialog.java index ac779d8cf..46de41a32 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/JavadocDialog.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/JavadocDialog.java @@ -3,7 +3,7 @@ import com.google.common.base.Strings; import org.quiltmc.enigma.api.analysis.EntryReference; import org.quiltmc.enigma.gui.GuiController; -import org.quiltmc.enigma.gui.config.UiConfig; +import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.config.keybind.KeyBinds; import org.quiltmc.enigma.gui.util.GuiUtil; import org.quiltmc.enigma.gui.util.ScaleUtil; @@ -65,7 +65,7 @@ private JavadocDialog(JFrame parent, GuiController controller, Entry entry, S this.close(); } })); - this.text.setFont(UiConfig.activeUseCustomFonts() ? UiConfig.getEditorFont() : UiConfig.getFallbackEditorFont()); + this.text.setFont(Config.activeUseCustomFonts() ? Config.getEditorFont() : Config.getFallbackEditorFont()); // buttons panel JPanel buttonsPanel = new JPanel(); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/StatsDialog.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/StatsDialog.java index 48a688d86..19ac0cab4 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/StatsDialog.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/StatsDialog.java @@ -1,7 +1,7 @@ package org.quiltmc.enigma.gui.dialog; import org.quiltmc.enigma.gui.Gui; -import org.quiltmc.enigma.gui.config.UiConfig; +import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.api.stats.ProjectStatsResult; import org.quiltmc.enigma.api.stats.StatType; import org.quiltmc.enigma.gui.util.GridBagConstraintsBuilder; @@ -65,12 +65,12 @@ public static void show(Gui gui, ProjectStatsResult result, String packageName) contentPane.add(topLevelPackageOption, cb1.pos(0, result.getOverall().getTypes().size() + 1).build()); JTextField topLevelPackage = new JTextField(); - topLevelPackage.setText(UiConfig.getLastTopLevelPackage()); + topLevelPackage.setText(Config.INSTANCE.lastTopLevelPackage.value()); contentPane.add(topLevelPackage, cb1.pos(0, result.getOverall().getTypes().size() + 2).fill(GridBagConstraints.HORIZONTAL).build()); // show synthetic members option JCheckBox syntheticParametersOption = new JCheckBox(I18n.translate("menu.file.stats.synthetic_parameters")); - syntheticParametersOption.setSelected(UiConfig.shouldIncludeSyntheticParameters()); + syntheticParametersOption.setSelected(Config.INSTANCE.shouldIncludeSyntheticParameters.value()); contentPane.add(syntheticParametersOption, cb1.pos(0, result.getOverall().getTypes().size() + 4).build()); // show filter button @@ -78,11 +78,10 @@ public static void show(Gui gui, ProjectStatsResult result, String packageName) filterButton.addActionListener(action -> { dialog.dispose(); ProgressDialog.runOffThread(gui, listener -> { - UiConfig.setLastTopLevelPackage(topLevelPackage.getText()); - UiConfig.save(); + Config.INSTANCE.lastTopLevelPackage.setValue(topLevelPackage.getText(), true); - ProjectStatsResult projectResult = gui.getController().getStatsGenerator().getResult(syntheticParametersOption.isSelected()).filter(UiConfig.getLastTopLevelPackage()); - SwingUtilities.invokeLater(() -> show(gui, projectResult, UiConfig.getLastTopLevelPackage())); + ProjectStatsResult projectResult = gui.getController().getStatsGenerator().getResult(syntheticParametersOption.isSelected()).filter(Config.INSTANCE.lastTopLevelPackage.value()); + SwingUtilities.invokeLater(() -> show(gui, projectResult, Config.INSTANCE.lastTopLevelPackage.value())); }); }); contentPane.add(filterButton, cb1.pos(0, result.getOverall().getTypes().size() + 3).anchor(GridBagConstraints.EAST).build()); @@ -93,9 +92,8 @@ public static void show(Gui gui, ProjectStatsResult result, String packageName) button.addActionListener(action -> { dialog.dispose(); - UiConfig.setLastTopLevelPackage(topLevelPackage.getText()); - UiConfig.setIncludeSyntheticParameters(syntheticParametersOption.isSelected()); - UiConfig.save(); + Config.INSTANCE.lastTopLevelPackage.setValue(topLevelPackage.getText(), true); + Config.INSTANCE.shouldIncludeSyntheticParameters.setValue(syntheticParametersOption.isSelected(), true); generateStats(gui, checkboxes); }); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/decompiler/VineflowerSettingsDialog.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/decompiler/VineflowerSettingsDialog.java index b0ed369d5..c3056e03a 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/decompiler/VineflowerSettingsDialog.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/decompiler/VineflowerSettingsDialog.java @@ -137,7 +137,6 @@ private void save() { VineflowerPreferences.OPTIONS.putAll(this.options); DecompilerConfig.updateVineflowerValues(VineflowerPreferences.OPTIONS); - DecompilerConfig.save(); this.dispose(); } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Dock.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Dock.java index 93a2ec6b4..1658cf2c3 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Dock.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Dock.java @@ -1,7 +1,7 @@ package org.quiltmc.enigma.gui.docker; import org.quiltmc.enigma.gui.Gui; -import org.quiltmc.enigma.gui.config.UiConfig; +import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.docker.component.DockerButton; import org.quiltmc.enigma.gui.docker.component.DockerSelector; import org.quiltmc.enigma.gui.docker.component.Draggable; @@ -64,7 +64,7 @@ public Dock(Gui gui, Docker.Side side) { */ public void restoreState() { // restore docker state - Optional> hostedDockers = UiConfig.getHostedDockers(this.gui.getDockerManager(), this.side); + Optional> hostedDockers = Config.getHostedDockers(this.gui.getDockerManager(), this.side); hostedDockers.ifPresent(m -> m.forEach(this::host)); this.restoreDividerState(true); @@ -78,25 +78,25 @@ public void restoreState() { * Saves the state of this dock to the config file. */ public void saveState() { - UiConfig.setHostedDockers(this.side, this.getDockers()); + Config.setHostedDockers(this.side, this.getDockers()); this.saveDividerState(); } public void restoreDividerState(boolean init) { // restore vertical divider state if (this.isSplit) { - this.splitPane.setDividerLocation(UiConfig.getVerticalDockDividerLocation(this.side)); + this.splitPane.setDividerLocation(Config.getVerticalDockDividerLocation(this.side)); } // restore horizontal divider state JSplitPane parentSplitPane = this.getParentSplitPane(); - int location = UiConfig.getHorizontalDividerLocation(this.side); + int location = Config.getHorizontalDividerLocation(this.side); // hack fix: if the right dock is closed while the left dock is open, the divider location is saved as if the left dock is open, // thereby offsetting the divider location by the width of the left dock. which means, if the right dock is reopened while the left dock is closed, // the divider location is too far to the left by the width of the left dock. so here we offset the location to avoid that. - if (init && this.side == Docker.Side.RIGHT && !this.gui.getSplitLeft().getLeftComponent().isVisible() && UiConfig.getSavedWithLeftOpen()) { - location += UiConfig.getHorizontalDividerLocation(Docker.Side.LEFT); + if (init && this.side == Docker.Side.RIGHT && !this.gui.getSplitLeft().getLeftComponent().isVisible() && Config.getSavedWithLeftOpen()) { + location += Config.getHorizontalDividerLocation(Docker.Side.LEFT); } parentSplitPane.setDividerLocation(location); @@ -106,16 +106,16 @@ public void saveDividerState() { if (this.isVisible()) { // save vertical divider state if (this.isSplit) { - UiConfig.setVerticalDockDividerLocation(this.side, this.splitPane.getDividerLocation()); + Config.setVerticalDockDividerLocation(this.side, this.splitPane.getDividerLocation()); } // save horizontal divider state JSplitPane parentSplitPane = this.getParentSplitPane(); - UiConfig.setHorizontalDividerLocation(this.side, parentSplitPane.getDividerLocation()); + Config.setHorizontalDividerLocation(this.side, parentSplitPane.getDividerLocation()); // hack if (this.side == Docker.Side.RIGHT) { - UiConfig.setSavedWithLeftOpen(this.gui.getSplitLeft().getLeftComponent().isVisible()); + Config.setSavedWithLeftOpen(this.gui.getSplitLeft().getLeftComponent().isVisible()); } } } @@ -184,7 +184,7 @@ public void host(Docker docker, Docker.VerticalLocation verticalLocation, boolea parent.remove(button); (verticalLocation == Docker.VerticalLocation.TOP ? selector.getTopSelector() : selector.getBottomSelector()).add(button); button.setSide(this.side); - UiConfig.setDockerButtonLocation(docker, new Docker.Location(this.side, verticalLocation)); + Config.setDockerButtonLocation(docker, new Docker.Location(this.side, verticalLocation)); button.getParent().revalidate(); button.getParent().repaint(); @@ -357,7 +357,7 @@ public void paint(Graphics graphics) { if (this.hovered != null) { Rectangle paintedBounds = this.getHighlightBoundsFor(new Point(0, 0), this.hovered); - Color color = UiConfig.getDockHighlightColor(); + Color color = Config.getDockHighlightColor(); graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 100)); graphics.fillRect(paintedBounds.x, paintedBounds.y, paintedBounds.width, paintedBounds.height); this.repaint(); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java index ea96cd120..066f53395 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java @@ -1,7 +1,7 @@ package org.quiltmc.enigma.gui.docker; import org.quiltmc.enigma.gui.Gui; -import org.quiltmc.enigma.gui.config.UiConfig; +import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.docker.component.DockerButton; import org.quiltmc.enigma.gui.docker.component.DockerTitleBar; import org.quiltmc.enigma.util.I18n; @@ -70,7 +70,7 @@ public DockerButton getButton() { * @return the position of the docker's button in the selector panels. this also represents where the docker will open when its button is clicked cannot use {@link Docker.VerticalLocation#FULL} */ public final Location getButtonLocation() { - return UiConfig.getButtonLocation(this); + return Config.getButtonLocation(this); } public abstract Location getPreferredButtonLocation(); @@ -105,13 +105,13 @@ public int hashCode() { */ public record Location(Side side, VerticalLocation verticalLocation) { public static Location parse(String string) { - String[] parts = string.split(UiConfig.PAIR_SEPARATOR); + String[] parts = string.split(Config.PAIR_SEPARATOR); return new Location(Side.valueOf(parts[0].toUpperCase()), VerticalLocation.valueOf(parts[1].toUpperCase())); } @Override public String toString() { - return this.side.name().toLowerCase() + UiConfig.PAIR_SEPARATOR + this.verticalLocation.name().toLowerCase(); + return this.side.name().toLowerCase() + Config.PAIR_SEPARATOR + this.verticalLocation.name().toLowerCase(); } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java index 8d49ab43c..03c93320c 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java @@ -1,7 +1,7 @@ package org.quiltmc.enigma.gui.docker.component; -import org.quiltmc.enigma.gui.config.LookAndFeel; -import org.quiltmc.enigma.gui.config.UiConfig; +import org.quiltmc.enigma.gui.config.theme.LookAndFeel; +import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.docker.Docker; import javax.swing.JComponent; @@ -121,8 +121,8 @@ public void paint(Graphics g) { // setup text String translatedText = this.textSupplier.get(); - Font font = UiConfig.getDefault2Font(); - if (UiConfig.getLookAndFeel().equals(LookAndFeel.SYSTEM)) { + Font font = Config.getDefault2Font(); + if (Config.getLookAndFeel().equals(LookAndFeel.SYSTEM)) { font = font.deriveFont(Font.BOLD); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerSelector.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerSelector.java index 14c5249c2..f00707bdf 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerSelector.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerSelector.java @@ -1,6 +1,6 @@ package org.quiltmc.enigma.gui.docker.component; -import org.quiltmc.enigma.gui.config.UiConfig; +import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.docker.Docker; import org.quiltmc.enigma.gui.docker.DockerManager; @@ -97,7 +97,7 @@ private boolean dropButton(DockerButton button, MouseEvent event) { if (hoveredPanel != null) { hoveredPanel.add(button); button.setSide(this.side); - UiConfig.setDockerButtonLocation(button.getDocker(), new Docker.Location(this.side, hoveredPanel.equals(this.bottomSelector) ? Docker.VerticalLocation.BOTTOM : Docker.VerticalLocation.TOP)); + Config.setDockerButtonLocation(button.getDocker(), new Docker.Location(this.side, hoveredPanel.equals(this.bottomSelector) ? Docker.VerticalLocation.BOTTOM : Docker.VerticalLocation.TOP)); return true; } @@ -111,7 +111,7 @@ public void paint(Graphics graphics) { if (this.hovered != null) { Rectangle paintedBounds = this.getScreenBoundsFor(this.hovered); - Color color = UiConfig.getDockHighlightColor(); + Color color = Config.getDockHighlightColor(); graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 100)); graphics.fillRect(0, this.hovered.equals(this.bottomSelector) ? paintedBounds.height : 0, paintedBounds.width, paintedBounds.height); this.repaint(); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java index 4eab83dc3..a57e17725 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java @@ -4,10 +4,10 @@ import org.quiltmc.enigma.gui.Gui; import org.quiltmc.enigma.gui.NotificationManager; import org.quiltmc.enigma.gui.config.Decompiler; -import org.quiltmc.enigma.gui.config.LookAndFeel; +import org.quiltmc.enigma.gui.config.theme.LookAndFeel; import org.quiltmc.enigma.gui.config.NetConfig; -import org.quiltmc.enigma.gui.config.Themes; -import org.quiltmc.enigma.gui.config.UiConfig; +import org.quiltmc.enigma.gui.config.theme.Themes; +import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.config.keybind.KeyBinds; import org.quiltmc.enigma.gui.dialog.AboutDialog; import org.quiltmc.enigma.gui.dialog.ChangeDialog; @@ -275,7 +275,7 @@ public void retranslateUi() { private void onOpenJarClicked() { JFileChooser d = this.gui.jarFileChooser; - d.setCurrentDirectory(new File(UiConfig.getLastSelectedDir())); + d.setCurrentDirectory(new File(Config.getLastSelectedDir())); d.setVisible(true); int result = d.showOpenDialog(this.gui.getFrame()); @@ -292,12 +292,12 @@ private void onOpenJarClicked() { this.gui.getController().openJar(path); } - UiConfig.setLastSelectedDir(d.getCurrentDirectory().getAbsolutePath()); + Config.setLastSelectedDir(d.getCurrentDirectory().getAbsolutePath()); } } private void onMaxRecentFilesClicked() { - String input = JOptionPane.showInputDialog(this.gui.getFrame(), I18n.translate("menu.file.dialog.max_recent_projects.set"), UiConfig.getMaxRecentFiles()); + String input = JOptionPane.showInputDialog(this.gui.getFrame(), I18n.translate("menu.file.dialog.max_recent_projects.set"), Config.getMaxRecentFiles()); if (input != null) { try { @@ -306,7 +306,7 @@ private void onMaxRecentFilesClicked() { throw new NumberFormatException(); } - UiConfig.setMaxRecentFiles(max); + Config.setMaxRecentFiles(max); } catch (NumberFormatException e) { JOptionPane.showMessageDialog(this.gui.getFrame(), I18n.translate("prompt.invalid_input"), I18n.translate("prompt.error"), JOptionPane.ERROR_MESSAGE); } @@ -346,15 +346,15 @@ private void onReloadAllClicked() { } private void onExportSourceClicked() { - this.gui.exportSourceFileChooser.setCurrentDirectory(new File(UiConfig.getLastSelectedDir())); + this.gui.exportSourceFileChooser.setCurrentDirectory(new File(Config.getLastSelectedDir())); if (this.gui.exportSourceFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { - UiConfig.setLastSelectedDir(this.gui.exportSourceFileChooser.getCurrentDirectory().toString()); + Config.setLastSelectedDir(this.gui.exportSourceFileChooser.getCurrentDirectory().toString()); this.gui.getController().exportSource(this.gui.exportSourceFileChooser.getSelectedFile().toPath()); } } private void onExportJarClicked() { - this.gui.exportJarFileChooser.setCurrentDirectory(new File(UiConfig.getLastSelectedDir())); + this.gui.exportJarFileChooser.setCurrentDirectory(new File(Config.getLastSelectedDir())); this.gui.exportJarFileChooser.setVisible(true); int result = this.gui.exportJarFileChooser.showSaveDialog(this.gui.getFrame()); @@ -365,13 +365,13 @@ private void onExportJarClicked() { if (this.gui.exportJarFileChooser.getSelectedFile() != null) { Path path = this.gui.exportJarFileChooser.getSelectedFile().toPath(); this.gui.getController().exportJar(path); - UiConfig.setLastSelectedDir(this.gui.exportJarFileChooser.getCurrentDirectory().getAbsolutePath()); + Config.setLastSelectedDir(this.gui.exportJarFileChooser.getCurrentDirectory().getAbsolutePath()); } } private void onCustomScaleClicked() { String answer = (String) JOptionPane.showInputDialog(this.gui.getFrame(), I18n.translate("menu.view.scale.custom.title"), I18n.translate("menu.view.scale.custom.title"), - JOptionPane.QUESTION_MESSAGE, null, null, Float.toString(UiConfig.getScaleFactor() * 100)); + JOptionPane.QUESTION_MESSAGE, null, null, Float.toString(Config.getScaleFactor() * 100)); if (answer == null) { return; @@ -412,7 +412,7 @@ public void onConnectClicked() { this.gui.getController().disconnectIfConnected(null); try { this.gui.getController().createClient(result.username(), result.address().address, result.address().port, result.password()); - if (UiConfig.getServerNotificationLevel() != NotificationManager.ServerNotificationLevel.NONE) { + if (Config.getServerNotificationLevel() != NotificationManager.ServerNotificationLevel.NONE) { this.gui.getNotificationManager().notify(new ParameterizedMessage(Message.CONNECTED_TO_SERVER, result.addressStr())); } @@ -442,7 +442,7 @@ public void onStartServerClicked() { this.gui.getController().disconnectIfConnected(null); try { this.gui.getController().createServer(result.port(), result.password()); - if (UiConfig.getServerNotificationLevel() != NotificationManager.ServerNotificationLevel.NONE) { + if (Config.getServerNotificationLevel() != NotificationManager.ServerNotificationLevel.NONE) { this.gui.getNotificationManager().notify(new ParameterizedMessage(Message.SERVER_STARTED, result.port())); } @@ -460,10 +460,10 @@ private void onGithubClicked() { } private void onOpenMappingsClicked() { - this.gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(UiConfig.getLastSelectedDir())); + this.gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(Config.getLastSelectedDir())); if (this.gui.enigmaMappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { File selectedFile = this.gui.enigmaMappingsFileChooser.getSelectedFile(); - UiConfig.setLastSelectedDir(this.gui.enigmaMappingsFileChooser.getCurrentDirectory().toString()); + Config.setLastSelectedDir(this.gui.enigmaMappingsFileChooser.getCurrentDirectory().toString()); MappingFormat format = MappingFormat.parseFromFile(selectedFile.toPath()); if (format.getReader() != null) { @@ -477,7 +477,7 @@ private void onOpenMappingsClicked() { public void reloadOpenRecentMenu(Gui gui) { this.openRecentMenu.removeAll(); - List> recentFilePairs = UiConfig.getRecentFilePairs(); + List> recentFilePairs = Config.getRecentFilePairs(); // find the longest common prefix among all mappings files // this is to clear the "/home/user/wherever-you-store-your-mappings-projects/" part of the path and only show relevant information @@ -542,13 +542,13 @@ private static void prepareSaveMappingsAsMenu(JMenu saveMappingsAsMenu, JMenuIte item.addActionListener(event -> { // TODO: Use a specific file chooser for it if (gui.enigmaMappingsFileChooser.getCurrentDirectory() == null) { - gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(UiConfig.getLastSelectedDir())); + gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(Config.getLastSelectedDir())); } if (gui.enigmaMappingsFileChooser.showSaveDialog(gui.getFrame()) == JFileChooser.APPROVE_OPTION) { gui.getController().saveMappings(gui.enigmaMappingsFileChooser.getSelectedFile().toPath(), format); saveMappingsItem.setEnabled(true); - UiConfig.setLastSelectedDir(gui.enigmaMappingsFileChooser.getCurrentDirectory().toString()); + Config.setLastSelectedDir(gui.enigmaMappingsFileChooser.getCurrentDirectory().toString()); } }); saveMappingsAsMenu.add(item); @@ -562,15 +562,15 @@ private static void prepareDecompilerMenu(JMenu decompilerMenu, JMenuItem decomp for (Decompiler decompiler : Decompiler.values()) { JRadioButtonMenuItem decompilerButton = new JRadioButtonMenuItem(decompiler.name); decompilerGroup.add(decompilerButton); - if (decompiler.equals(UiConfig.getDecompiler())) { + if (decompiler.equals(Config.getDecompiler())) { decompilerButton.setSelected(true); } decompilerButton.addActionListener(event -> { gui.getController().setDecompiler(decompiler.service); - UiConfig.setDecompiler(decompiler); - UiConfig.save(); + Config.setDecompiler(decompiler); + Config.save(); }); decompilerMenu.add(decompilerButton); } @@ -584,13 +584,13 @@ private static void prepareThemesMenu(JMenu themesMenu, Gui gui) { for (LookAndFeel lookAndFeel : LookAndFeel.values()) { JRadioButtonMenuItem themeButton = new JRadioButtonMenuItem(I18n.translate("menu.view.themes." + lookAndFeel.name().toLowerCase(Locale.ROOT))); themeGroup.add(themeButton); - if (lookAndFeel.equals(UiConfig.getLookAndFeel())) { + if (lookAndFeel.equals(Config.getLookAndFeel())) { themeButton.setSelected(true); } themeButton.addActionListener(e -> { - UiConfig.setLookAndFeel(lookAndFeel); - UiConfig.save(); + Config.setLookAndFeel(lookAndFeel); + Config.save(); Themes.setupTheme(); ChangeDialog.show(gui.getFrame()); }); @@ -603,15 +603,15 @@ private static void prepareLanguagesMenu(JMenu languagesMenu) { for (String lang : I18n.getAvailableLanguages()) { JRadioButtonMenuItem languageButton = new JRadioButtonMenuItem(I18n.getLanguageName(lang)); languageGroup.add(languageButton); - if (lang.equals(UiConfig.getLanguage())) { + if (lang.equals(Config.getLanguage())) { languageButton.setSelected(true); } languageButton.addActionListener(event -> { - UiConfig.setLanguage(lang); + Config.setLanguage(lang); I18n.setLanguage(lang); LanguageUtil.dispatchLanguageChange(); - UiConfig.save(); + Config.save(); }); languagesMenu.add(languageButton); } @@ -631,7 +631,7 @@ private static void prepareScaleMenu(JMenu scaleMenu, Gui gui) { }) .collect(Collectors.toMap(Pair::a, Pair::b)); - JRadioButtonMenuItem currentScaleButton = scaleButtons.get(UiConfig.getScaleFactor()); + JRadioButtonMenuItem currentScaleButton = scaleButtons.get(Config.getScaleFactor()); if (currentScaleButton != null) { currentScaleButton.setSelected(true); } @@ -653,11 +653,11 @@ private static void prepareNotificationsMenu(JMenu notificationsMenu) { JRadioButtonMenuItem notificationsButton = new JRadioButtonMenuItem(level.getText()); notificationsGroup.add(notificationsButton); - if (level.equals(UiConfig.getServerNotificationLevel())) { + if (level.equals(Config.getServerNotificationLevel())) { notificationsButton.setSelected(true); } - notificationsButton.addActionListener(event -> UiConfig.setServerNotificationLevel(level)); + notificationsButton.addActionListener(event -> Config.setServerNotificationLevel(level)); notificationsMenu.add(notificationsButton); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/event/ThemeChangeListener.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/event/ThemeChangeListener.java index 48ac83a28..bc6bbcd4b 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/event/ThemeChangeListener.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/event/ThemeChangeListener.java @@ -1,6 +1,6 @@ package org.quiltmc.enigma.gui.event; -import org.quiltmc.enigma.gui.config.LookAndFeel; +import org.quiltmc.enigma.gui.config.theme.LookAndFeel; import org.quiltmc.enigma.gui.highlight.BoxHighlightPainter; import org.quiltmc.enigma.api.source.TokenType; diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/highlight/SelectionHighlightPainter.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/highlight/SelectionHighlightPainter.java index 32a7c314c..c94c34784 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/highlight/SelectionHighlightPainter.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/highlight/SelectionHighlightPainter.java @@ -1,6 +1,6 @@ package org.quiltmc.enigma.gui.highlight; -import org.quiltmc.enigma.gui.config.UiConfig; +import org.quiltmc.enigma.gui.config.Config; import java.awt.BasicStroke; import java.awt.Graphics; @@ -18,7 +18,7 @@ public void paint(Graphics g, int start, int end, Shape shape, JTextComponent te // draw a thick border Graphics2D g2d = (Graphics2D) g; Rectangle bounds = BoxHighlightPainter.getBounds(text, start, end); - g2d.setColor(UiConfig.getSelectionHighlightColor()); + g2d.setColor(Config.getSelectionHighlightColor()); g2d.setStroke(new BasicStroke(2.0f)); g2d.drawRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/panel/EditorPanel.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/panel/EditorPanel.java index 15827bc36..b875d60c6 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/panel/EditorPanel.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/panel/EditorPanel.java @@ -9,9 +9,9 @@ import org.quiltmc.enigma.gui.EditableType; import org.quiltmc.enigma.gui.Gui; import org.quiltmc.enigma.gui.GuiController; -import org.quiltmc.enigma.gui.config.LookAndFeel; -import org.quiltmc.enigma.gui.config.Themes; -import org.quiltmc.enigma.gui.config.UiConfig; +import org.quiltmc.enigma.gui.config.theme.LookAndFeel; +import org.quiltmc.enigma.gui.config.theme.Themes; +import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.config.keybind.KeyBinds; import org.quiltmc.enigma.gui.element.EditorPopupMenu; import org.quiltmc.enigma.gui.element.NavigatorPanel; @@ -120,9 +120,9 @@ public EditorPanel(Gui gui, NavigatorPanel navigator) { this.editor.setCaret(new BrowserCaret()); this.editor.setFont(ScaleUtil.getFont(this.editor.getFont().getFontName(), Font.PLAIN, this.fontSize)); this.editor.addCaretListener(event -> this.onCaretMove(event.getDot(), this.mouseIsPressed)); - this.editor.setCaretColor(UiConfig.getCaretColor()); + this.editor.setCaretColor(Config.getCaretColor()); this.editor.setContentType("text/enigma-sources"); - this.editor.setBackground(UiConfig.getEditorBackgroundColor()); + this.editor.setBackground(Config.getEditorBackgroundColor()); // set unit increment to height of one line, the amount scrolled per // mouse wheel rotation is then controlled by OS settings @@ -213,7 +213,7 @@ public void keyReleased(KeyEvent event) { this.themeChangeListener = (laf, boxHighlightPainters) -> { if ((this.editorLaf == null || this.editorLaf != laf)) { this.editor.updateUI(); - this.editor.setBackground(UiConfig.getEditorBackgroundColor()); + this.editor.setBackground(Config.getEditorBackgroundColor()); if (this.editorLaf != null) { this.classHandle.invalidateMapped(); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/CallsTreeCellRenderer.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/CallsTreeCellRenderer.java index 62190e9f6..7431c68c6 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/CallsTreeCellRenderer.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/CallsTreeCellRenderer.java @@ -6,7 +6,7 @@ import org.quiltmc.enigma.api.analysis.tree.MethodReferenceTreeNode; import org.quiltmc.enigma.api.analysis.tree.ReferenceTreeNode; import org.quiltmc.enigma.gui.Gui; -import org.quiltmc.enigma.gui.config.UiConfig; +import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.util.GuiUtil; import org.quiltmc.enigma.api.translation.representation.entry.MethodEntry; @@ -26,7 +26,7 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean Component c = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); EntryReference reference = ((ReferenceTreeNode) value).getReference(); - this.setForeground(UiConfig.getTextColor()); + this.setForeground(Config.getTextColor()); // if the node represents the method calling the entry if (reference != null) { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/ImplementationsTreeCellRenderer.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/ImplementationsTreeCellRenderer.java index 5cd6e5ecb..a1a4ba4b4 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/ImplementationsTreeCellRenderer.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/ImplementationsTreeCellRenderer.java @@ -3,7 +3,7 @@ import org.quiltmc.enigma.api.analysis.tree.ClassImplementationsTreeNode; import org.quiltmc.enigma.api.analysis.tree.MethodImplementationsTreeNode; import org.quiltmc.enigma.gui.Gui; -import org.quiltmc.enigma.gui.config.UiConfig; +import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.util.GuiUtil; import javax.swing.JTree; @@ -21,7 +21,7 @@ public ImplementationsTreeCellRenderer(Gui gui) { public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { Component c = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); - this.setForeground(UiConfig.getTextColor()); + this.setForeground(Config.getTextColor()); if (value instanceof ClassImplementationsTreeNode node) { this.setIcon(GuiUtil.getClassIcon(this.gui, node.getClassEntry())); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/InheritanceTreeCellRenderer.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/InheritanceTreeCellRenderer.java index efa6d0d3f..ea79bac4a 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/InheritanceTreeCellRenderer.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/InheritanceTreeCellRenderer.java @@ -3,7 +3,7 @@ import org.quiltmc.enigma.api.analysis.tree.ClassInheritanceTreeNode; import org.quiltmc.enigma.api.analysis.tree.MethodInheritanceTreeNode; import org.quiltmc.enigma.gui.Gui; -import org.quiltmc.enigma.gui.config.UiConfig; +import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.util.GuiUtil; import java.awt.Component; @@ -23,7 +23,7 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean Component ret = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); if (!(value instanceof MethodInheritanceTreeNode node) || node.isImplemented()) { - ret.setForeground(UiConfig.getTextColor()); + ret.setForeground(Config.getTextColor()); ret.setFont(ret.getFont().deriveFont(Font.PLAIN)); if (value instanceof ClassInheritanceTreeNode) { this.setIcon(GuiUtil.getClassIcon(this.gui, ((ClassInheritanceTreeNode) value).getClassEntry())); @@ -31,7 +31,7 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean this.setIcon(GuiUtil.getMethodIcon(((MethodInheritanceTreeNode) value).getMethodEntry())); } } else { - ret.setForeground(UiConfig.getNumberColor()); + ret.setForeground(Config.getNumberColor()); ret.setFont(ret.getFont().deriveFont(Font.ITALIC)); this.setIcon(GuiUtil.CLASS_ICON); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/GuiUtil.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/GuiUtil.java index 6b71d436e..bdf336ec0 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/GuiUtil.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/GuiUtil.java @@ -3,7 +3,7 @@ import com.formdev.flatlaf.extras.FlatSVGIcon; import org.quiltmc.enigma.api.analysis.index.jar.EntryIndex; import org.quiltmc.enigma.gui.Gui; -import org.quiltmc.enigma.gui.config.LookAndFeel; +import org.quiltmc.enigma.gui.config.theme.LookAndFeel; import org.quiltmc.enigma.api.stats.ProjectStatsResult; import org.quiltmc.enigma.api.translation.representation.AccessFlags; import org.quiltmc.enigma.api.translation.representation.entry.ClassEntry; diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java index 948893b37..251cfa189 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java @@ -5,7 +5,7 @@ import com.github.swingdpi.plaf.MetalTweaker; import com.github.swingdpi.plaf.NimbusTweaker; import com.github.swingdpi.plaf.WindowsTweaker; -import org.quiltmc.enigma.gui.config.UiConfig; +import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.syntaxpain.SyntaxpainConfiguration; import java.awt.Dimension; @@ -21,14 +21,14 @@ public class ScaleUtil { private static final List listeners = new ArrayList<>(); public static void setScaleFactor(float scaleFactor) { - float oldScale = UiConfig.getScaleFactor(); + float oldScale = Config.getScaleFactor(); float clamped = Math.min(Math.max(0.25f, scaleFactor), 10.0f); - UiConfig.setScaleFactor(clamped); + Config.setScaleFactor(clamped); rescaleFontInConfig("Default", oldScale); rescaleFontInConfig("Default 2", oldScale); rescaleFontInConfig("Small", oldScale); rescaleFontInConfig("Editor", oldScale); - UiConfig.save(); + Config.save(); listeners.forEach(l -> l.onScaleChanged(clamped, oldScale)); } @@ -53,29 +53,29 @@ public static Font getFont(String fontName, int style, int fontSize) { } public static Font scaleFont(Font font) { - return createTweakerForCurrentLook(UiConfig.getActiveScaleFactor()).modifyFont("", font); + return createTweakerForCurrentLook(Config.getActiveScaleFactor()).modifyFont("", font); } private static void rescaleFontInConfig(String name, float oldScale) { - UiConfig.getFont(name).ifPresent(font -> UiConfig.setFont(name, rescaleFont(font, oldScale))); + Config.getFont(name).ifPresent(font -> Config.setFont(name, rescaleFont(font, oldScale))); } // This does not use the font that's currently active in the UI! private static Font rescaleFont(Font font, float oldScale) { - float newSize = Math.round(font.getSize() / oldScale * UiConfig.getScaleFactor()); + float newSize = Math.round(font.getSize() / oldScale * Config.getScaleFactor()); return font.deriveFont(newSize); } public static float scale(float f) { - return f * UiConfig.getActiveScaleFactor(); + return f * Config.getActiveScaleFactor(); } public static float invert(float f) { - return f / UiConfig.getActiveScaleFactor(); + return f / Config.getActiveScaleFactor(); } public static int scale(int i) { - return (int) (i * UiConfig.getActiveScaleFactor()); + return (int) (i * Config.getActiveScaleFactor()); } public static Border createEmptyBorder(int top, int left, int bottom, int right) { @@ -83,17 +83,17 @@ public static Border createEmptyBorder(int top, int left, int bottom, int right) } public static int invert(int i) { - return (int) (i / UiConfig.getActiveScaleFactor()); + return (int) (i / Config.getActiveScaleFactor()); } public static void applyScaling() { - float scale = UiConfig.getActiveScaleFactor(); + float scale = Config.getActiveScaleFactor(); - if (UiConfig.getActiveLookAndFeel().needsScaling()) { + if (Config.getActiveLookAndFeel().needsScaling()) { UiDefaultsScaler.updateAndApplyGlobalScaling((int) (100 * scale), true); } - Font font = UiConfig.getEditorFont(); + Font font = Config.getEditorFont(); font = font.deriveFont(12 * scale); SyntaxpainConfiguration.setEditorFont(font); } diff --git a/enigma/src/main/resources/lang/de_de.json b/enigma/src/main/resources/lang/de_de.json index 38fc3d4ea..ed5d000a0 100644 --- a/enigma/src/main/resources/lang/de_de.json +++ b/enigma/src/main/resources/lang/de_de.json @@ -18,7 +18,6 @@ "editor.remap_error": "Ein Fehler ist während des Remappens aufgetreten.", "fonts.cat.default": "Standard", - "fonts.cat.default2": "Standard 2", "fonts.cat.small": "Klein", "fonts.cat.editor": "Editor", "fonts.use_custom": "Benutzerdefinierte Schriftarten verwenden", diff --git a/enigma/src/main/resources/lang/en_us.json b/enigma/src/main/resources/lang/en_us.json index 9399f3bcc..f7ef3c497 100644 --- a/enigma/src/main/resources/lang/en_us.json +++ b/enigma/src/main/resources/lang/en_us.json @@ -207,7 +207,6 @@ "javadocs.instruction": "Edit javadocs here.", "fonts.cat.default": "Default", - "fonts.cat.default2": "Default 2", "fonts.cat.small": "Small", "fonts.cat.editor": "Editor", "fonts.use_custom": "Use Custom Fonts", diff --git a/enigma/src/main/resources/lang/fr_fr.json b/enigma/src/main/resources/lang/fr_fr.json index 24b27b00e..689c36c81 100644 --- a/enigma/src/main/resources/lang/fr_fr.json +++ b/enigma/src/main/resources/lang/fr_fr.json @@ -192,7 +192,6 @@ "javadocs.instruction": "Éditer les Javadocs ici.", "fonts.cat.default": "Par défaut", - "fonts.cat.default2": "Par défaut 2", "fonts.cat.small": "Petit", "fonts.cat.editor": "Éditeur", "fonts.use_custom": "Utiliser des polices personnalisées", diff --git a/enigma/src/main/resources/lang/ja_jp.json b/enigma/src/main/resources/lang/ja_jp.json index 3b9dbe6b9..af9f6238c 100644 --- a/enigma/src/main/resources/lang/ja_jp.json +++ b/enigma/src/main/resources/lang/ja_jp.json @@ -145,7 +145,6 @@ "javadocs.instruction": "このJavadocを編集", "fonts.cat.default": "デフォルト", - "fonts.cat.default2": "デフォルト 2", "fonts.cat.small": "スモール", "fonts.cat.editor": "エディタ", "fonts.use_custom": "カスタムフォントを使う", From 11edbbd2e3f0f851a9a2e3b0e1a511f7fbc85fd5 Mon Sep 17 00:00:00 2001 From: ix0rai Date: Wed, 22 Nov 2023 21:59:35 -0600 Subject: [PATCH 05/25] grinding --- .../main/java/org/quiltmc/enigma/gui/Gui.java | 35 +++--- .../org/quiltmc/enigma/gui/GuiController.java | 8 +- .../java/org/quiltmc/enigma/gui/Main.java | 4 +- .../org/quiltmc/enigma/gui/config/Config.java | 58 ++++++++-- .../enigma/gui/config/DockerConfig.java | 67 +++++++++--- .../enigma/gui/config/KeyBindsConfig.java | 23 ++-- .../enigma/gui/config/keybind/KeyBinds.java | 11 +- .../quiltmc/enigma/gui/config/nonsense.java | 67 ------------ .../enigma/gui/config/theme/LookAndFeel.java | 2 +- .../enigma/gui/config/theme/ThemeColors.java | 6 +- .../enigma/gui/config/theme/Themes.java | 103 +++++++++--------- .../gui/dialog/ConnectToServerDialog.java | 8 +- .../enigma/gui/dialog/CreateServerDialog.java | 6 +- .../enigma/gui/dialog/JavadocDialog.java | 2 +- .../org/quiltmc/enigma/gui/docker/Dock.java | 24 ++-- .../org/quiltmc/enigma/gui/docker/Docker.java | 9 +- .../enigma/gui/docker/DockerManager.java | 6 +- .../gui/docker/component/DockerButton.java | 4 +- .../gui/docker/component/DockerSelector.java | 4 +- .../quiltmc/enigma/gui/element/MenuBar.java | 63 +++++------ .../highlight/SelectionHighlightPainter.java | 2 +- .../quiltmc/enigma/gui/panel/EditorPanel.java | 6 +- .../gui/renderer/CallsTreeCellRenderer.java | 2 +- .../ImplementationsTreeCellRenderer.java | 2 +- .../renderer/InheritanceTreeCellRenderer.java | 4 +- .../quiltmc/enigma/gui/util/ScaleUtil.java | 37 +++---- 26 files changed, 266 insertions(+), 297 deletions(-) delete mode 100644 enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/nonsense.java diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java index f5a668c4c..d8187aa58 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java @@ -70,7 +70,6 @@ public class Gui { private final MainWindow mainWindow; private final GuiController controller; - private final Config config; private ConnectionState connectionState; private boolean isJarOpen; @@ -103,8 +102,7 @@ public class Gui { public final JFileChooser exportJarFileChooser; public final SearchDialog searchDialog; - public Gui(EnigmaProfile profile, Set editableTypes, boolean visible, Config config) { - this.config = config; + public Gui(EnigmaProfile profile, Set editableTypes, boolean visible) { this.dockerManager = new DockerManager(this); this.mainWindow = new MainWindow(this, Enigma.NAME); this.centerPanel = new JPanel(new BorderLayout()); @@ -150,8 +148,8 @@ private void setupDockers() { this.dockerManager.registerDocker(new AllClassesDocker(this)); this.dockerManager.registerDocker(new DeobfuscatedClassesDocker(this)); - if (this.config.dockerConfig.dockerLocations.value().isEmpty()) { - this.config.dockerConfig.dockerLocations.value().setValue(DockerConfig.getDefaultLocations(this.dockerManager)); + if (Config.INSTANCE.getDockerConfig().dockerLocations.value().isEmpty()) { + Config.INSTANCE.getDockerConfig().dockerLocations.value().setValue(DockerConfig.getDefaultLocations(this.dockerManager)); } // set default docker sizes @@ -197,7 +195,8 @@ private void setupUi() { this.splitRight.setResizeWeight(1); this.splitLeft.setResizeWeight(0); - if (Config.getHostedDockers(this.dockerManager, Docker.Side.LEFT).isPresent() || Config.getHostedDockers(this.dockerManager, Docker.Side.RIGHT).isPresent()) { + // todo probably doesn't work + if (!Config.INSTANCE.dockerConfig.value().getHostedDockers(Docker.Side.LEFT).isEmpty() || !Config.INSTANCE.dockerConfig.value().getHostedDockers(Docker.Side.RIGHT).isEmpty()) { this.dockerManager.restoreStateFromConfig(); } else { this.dockerManager.setupDefaultConfiguration(); @@ -210,16 +209,12 @@ private void setupUi() { JFrame frame = this.mainWindow.getFrame(); frame.addWindowListener(GuiUtil.onWindowClose(e -> this.close())); - frame.setSize(Config.getWindowSize(Config.MAIN_WINDOW, ScaleUtil.getDimension(1024, 576))); + frame.setSize(Config.get().windowSize.value()); frame.setMinimumSize(ScaleUtil.getDimension(640, 480)); frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - Point windowPos = Config.getWindowPos(Config.MAIN_WINDOW, null); - if (windowPos != null) { - frame.setLocation(windowPos); - } else { - frame.setLocationRelativeTo(null); - } + Point windowPos = Config.get().windowPos.value(); + frame.setLocation(windowPos); this.retranslateUi(); } @@ -521,11 +516,11 @@ public void close() { } private void exit() { - Config.setWindowPos(Config.MAIN_WINDOW, this.mainWindow.getFrame().getLocationOnScreen()); - Config.setWindowSize(Config.MAIN_WINDOW, this.mainWindow.getFrame().getSize()); + Config.get().windowPos.setValue(this.mainWindow.getFrame().getLocationOnScreen(), true); + Config.get().windowSize.setValue(this.mainWindow.getFrame().getSize(), true); this.dockerManager.saveStateToConfig(); - Config.save(); + Config.INSTANCE.save(); this.searchDialog.dispose(); this.mainWindow.getFrame().dispose(); @@ -621,17 +616,17 @@ public void addMessage(ServerMessage message) { // popup notifications switch (message.getType()) { case CHAT -> { - if (Config.getServerNotificationLevel().equals(NotificationManager.ServerNotificationLevel.FULL) && !message.user.equals(NetConfig.getUsername())) { + if (Config.INSTANCE.serverNotificationLevel.value() == NotificationManager.ServerNotificationLevel.FULL && !message.user.equals(Config.INSTANCE.net.value().username.value())) { this.notificationManager.notify(new ParameterizedMessage(Message.MULTIPLAYER_CHAT, message.translate())); } } case CONNECT -> { - if (Config.getServerNotificationLevel() != NotificationManager.ServerNotificationLevel.NONE) { + if (Config.INSTANCE.serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { this.notificationManager.notify(new ParameterizedMessage(Message.MULTIPLAYER_USER_CONNECTED, message.translate())); } } case DISCONNECT -> { - if (Config.getServerNotificationLevel() != NotificationManager.ServerNotificationLevel.NONE) { + if (Config.INSTANCE.serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { this.notificationManager.notify(new ParameterizedMessage(Message.MULTIPLAYER_USER_LEFT, message.translate())); } } @@ -705,7 +700,7 @@ public void reloadKeyBinds() { } public void openMostRecentFiles() { - var pair = Config.getMostRecentFilePair(); + var pair = Config.INSTANCE.getMostRecentFilePair(); if (pair.isPresent()) { this.getNotificationManager().notify(ParameterizedMessage.openedProject(pair.get().a().toString(), pair.get().b().toString())); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java index 15fce76c0..e7bb7f922 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java @@ -125,7 +125,7 @@ public CompletableFuture openJar(final Path jarPath) { return ProgressDialog.runOffThread(this.gui, progress -> { this.project = this.enigma.openJar(jarPath, new ClasspathClassProvider(), progress); this.indexTreeBuilder = new IndexTreeBuilder(this.project.getJarIndex()); - this.chp = new ClassHandleProvider(this.project, Config.getDecompiler().service); + this.chp = new ClassHandleProvider(this.project, Config.INSTANCE.decompiler.value().decompiler.value().service); this.statsGenerator = new StatsGenerator(this.project); SwingUtilities.invokeLater(() -> { @@ -557,7 +557,7 @@ private void applyChange0(ValidationContext vc, EntryChange change, boolean u public void openStatsTree(Set includedTypes) { ProgressDialog.runOffThread(this.gui, progress -> { StatsResult overall = this.getStatsGenerator().getResultNullable().getOverall(); - StatsTree tree = overall.buildTree(Config.getLastTopLevelPackage(), includedTypes); + StatsTree tree = overall.buildTree(Config.INSTANCE.lastTopLevelPackage.value(), includedTypes); String treeJson = GSON.toJson(tree.root); try { @@ -619,7 +619,7 @@ public void createServer(int port, char[] password) throws IOException { this.server.start(); this.client = new EnigmaClient(this, "127.0.0.1", port); this.client.connect(); - this.client.sendPacket(new LoginC2SPacket(this.project.getJarChecksum(), password, NetConfig.getUsername())); + this.client.sendPacket(new LoginC2SPacket(this.project.getJarChecksum(), password, Config.INSTANCE.getNetConfig().username.value())); this.gui.setConnectionState(ConnectionState.HOSTING); } @@ -648,7 +648,7 @@ public synchronized void disconnectIfConnected(String reason) { }); this.gui.setUserList(new ArrayList<>()); - if (Config.getServerNotificationLevel() != NotificationManager.ServerNotificationLevel.NONE) { + if (Config.INSTANCE.serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { this.gui.getNotificationManager().notify(new ParameterizedMessage(Message.LEFT_SERVER)); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java index 29fac472d..b0eca6ad9 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java @@ -96,7 +96,7 @@ public static void main(String[] args) throws IOException { EnigmaProfile parsedProfile = EnigmaProfile.read(options.valueOf(profile)); - I18n.setLanguage(Config.getLanguage()); + I18n.setLanguage(Config.INSTANCE.language.value()); setDefaultSystemProperty("apple.laf.useScreenMenuBar", "true"); setDefaultSystemProperty("awt.useSystemAAFontSettings", "on"); setDefaultSystemProperty("swing.aatext", "true"); @@ -105,7 +105,7 @@ public static void main(String[] args) throws IOException { KeyBinds.loadConfig(); - Gui gui = new Gui(parsedProfile, editables, true, config); + Gui gui = new Gui(parsedProfile, editables, true); GuiController controller = gui.getController(); if (options.has("hide-progress-bars")) { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java index 1fbf1baf4..be51e3a7b 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java @@ -2,6 +2,7 @@ import org.quiltmc.config.api.ReflectiveConfig; import org.quiltmc.config.api.values.TrackedValue; +import org.quiltmc.config.api.values.ValueList; import org.quiltmc.config.api.values.ValueMap; import org.quiltmc.enigma.gui.NotificationManager; import org.quiltmc.enigma.gui.config.theme.LookAndFeel; @@ -14,6 +15,7 @@ import org.quiltmc.syntaxpain.SyntaxpainConfiguration; import java.awt.Dimension; +import java.awt.Point; public final class Config extends ReflectiveConfig { public static final Config INSTANCE = new Config(); @@ -23,16 +25,20 @@ public Config() { } public final TrackedValue language = this.value(I18n.DEFAULT_LANGUAGE); - public final TrackedValue scaleFactor = this.value(1.0); - public final DockerConfig dockerConfig = new DockerConfig(); + public final TrackedValue scaleFactor = this.value(1.0f); public final TrackedValue maxRecentFiles = this.value(10); - public final TrackedValue> recentFiles = this.map("").build(); + public final TrackedValue> recentFiles = this.list(new RecentProject("", "")); public final TrackedValue serverNotificationLevel = this.value(NotificationManager.ServerNotificationLevel.FULL); public final TrackedValue useCustomFonts = this.value(false); public final TrackedValue windowSize = this.value(ScaleUtil.getDimension(1024, 576)); + public final TrackedValue windowPos = this.value(new Point()); public final TrackedValue lastSelectedDir = this.value(""); public final TrackedValue lastTopLevelPackage = this.value(""); public final TrackedValue shouldIncludeSyntheticParameters = this.value(false); + public final TrackedValue keyBinds = this.value(new KeyBindsConfig()); + public final TrackedValue net = this.value(new NetConfig()); + public final TrackedValue decompiler = this.value(new DecompilerConfig()); + public final TrackedValue dockerConfig = this.value(new DockerConfig()); public final TrackedValue lookAndFeel = this.value(LookAndFeel.DEFAULT); // todo laf can't be changed while running @@ -44,16 +50,48 @@ public Config() { public final TrackedValue systemTheme = this.value(new Theme(LookAndFeel.SYSTEM)); public final TrackedValue noneTheme = this.value(new Theme(LookAndFeel.NONE)); - public Theme getCurrentTheme() { - return switch (this.activeLookAndFeel) { - case DEFAULT -> this.defaultTheme.value(); - case DARCULA -> this.darculaTheme.value(); - case METAL -> this.metalTheme.value(); - case SYSTEM -> this.systemTheme.value(); - case NONE -> this.noneTheme.value(); + public static Config get() { + return INSTANCE; + } + + public static DockerConfig getDockerConfig() { + return INSTANCE.dockerConfig.value(); + } + + public static KeyBindsConfig getKeyBindsConfig() { + return INSTANCE.keyBinds.value(); + } + + public static NetConfig getNetConfig() { + return INSTANCE.net.value(); + } + + public static DecompilerConfig getDecompilerConfig() { + return INSTANCE.decompiler.value(); + } + + public static Theme getCurrentTheme() { + return switch (INSTANCE.activeLookAndFeel) { + case DEFAULT -> INSTANCE.defaultTheme.value(); + case DARCULA -> INSTANCE.darculaTheme.value(); + case METAL -> INSTANCE.metalTheme.value(); + case SYSTEM -> INSTANCE.systemTheme.value(); + case NONE -> INSTANCE.noneTheme.value(); }; } + public static ThemeColors getCurrentColors() { + return getCurrentTheme().colors.value(); + } + + public static ThemeFonts getCurrentFonts() { + return getCurrentTheme().fonts.value(); + } + + public record RecentProject(String jarPath, String mappingsPath) { + + } + /** * Updates the backend library Syntaxpain, used for code highlighting and other editor things. */ diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java index cdeae0cb8..f49088b56 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java @@ -16,6 +16,13 @@ import org.quiltmc.enigma.gui.docker.StructureDocker; import org.quiltmc.enigma.util.Pair; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Collectors; + +// todo use ComplexConfigValue for pairs public class DockerConfig extends ReflectiveConfig.Section { public final TrackedValue leftVerticalDividerLocation = this.value(300); public final TrackedValue rightVerticalDividerLocation = this.value(300); @@ -23,40 +30,64 @@ public class DockerConfig extends ReflectiveConfig.Section { public final TrackedValue rightHorizontalDividerLocation = this.value(700); public final TrackedValue savedWithLeftDockerOpen = this.value(true); - public final TrackedValue>> dockerLocations = this.map(new Pair<>("", "")).build(); + public final TrackedValue> dockerLocations = this.map(new Docker.Location(Docker.Side.LEFT, Docker.VerticalLocation.TOP)).build(); + + public Docker.Location getDockerLocation(String id) { + return this.dockerLocations.value().get(id); + } public void putDockerLocation(String id, Docker.Location location) { - putDockerLocation(this.dockerLocations, id, location); + this.dockerLocations.value().put(id, location); } - private static void putDockerLocation(TrackedValue>> locations, String id, Docker.Location location) { - if (location.verticalLocation() == Docker.VerticalLocation.FULL) { - throw new RuntimeException(); + public void putDockerLocation(Docker docker, Docker.Side side, Docker.VerticalLocation verticalLocation) { + this.putDockerLocation(docker.getId(), new Docker.Location(side, verticalLocation)); + } + + public Map getHostedDockers(Docker.Side side) { + return this.dockerLocations.value().entrySet().stream().filter((entry) -> entry.getValue().side() == side).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + } + + public int getVerticalDividerLocation(Docker.Side side) { + return side == Docker.Side.LEFT ? this.leftVerticalDividerLocation.value() : this.rightVerticalDividerLocation.value(); + } + + public void setVerticalDividerLocation(Docker.Side side, int value) { + if (side == Docker.Side.LEFT) { + this.leftVerticalDividerLocation.setValue(value, true); + } else { + this.rightVerticalDividerLocation.setValue(value, true); } + } - locations.value().put(id, new Pair<>(location.side().toString(), location.verticalLocation().toString())); + public int getHorizontalDividerLocation(Docker.Side side) { + return side == Docker.Side.LEFT ? this.leftHorizontalDividerLocation.value() : this.rightHorizontalDividerLocation.value(); } - private static void putDockerLocation(DockerConfig config, Docker docker, Docker.Side side, Docker.VerticalLocation verticalLocation) { - putDockerLocation(config.dockerLocations, docker.getId(), new Docker.Location(side, verticalLocation)); + public void setHorizontalDividerLocation(Docker.Side side, int value) { + if (side == Docker.Side.LEFT) { + this.leftHorizontalDividerLocation.setValue(value, true); + } else { + this.rightHorizontalDividerLocation.setValue(value, true); + } } - public static TrackedValue>> getDefaultLocations(DockerManager manager) { + public static TrackedValue> getDefaultLocations(DockerManager manager) { DockerConfig defaultConfig = new DockerConfig(); // left - putDockerLocation(defaultConfig, manager.getDocker(ObfuscatedClassesDocker.class), Docker.Side.LEFT, Docker.VerticalLocation.TOP); - putDockerLocation(defaultConfig, manager.getDocker(ClassesDocker.class), Docker.Side.LEFT, Docker.VerticalLocation.TOP); - putDockerLocation(defaultConfig, manager.getDocker(DeobfuscatedClassesDocker.class), Docker.Side.LEFT, Docker.VerticalLocation.BOTTOM); + defaultConfig.putDockerLocation(manager.getDocker(ObfuscatedClassesDocker.class), Docker.Side.LEFT, Docker.VerticalLocation.TOP); + defaultConfig.putDockerLocation(manager.getDocker(ClassesDocker.class), Docker.Side.LEFT, Docker.VerticalLocation.TOP); + defaultConfig.putDockerLocation(manager.getDocker(DeobfuscatedClassesDocker.class), Docker.Side.LEFT, Docker.VerticalLocation.BOTTOM); // right - putDockerLocation(defaultConfig, manager.getDocker(StructureDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); - putDockerLocation(defaultConfig, manager.getDocker(InheritanceTreeDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); - putDockerLocation(defaultConfig, manager.getDocker(ImplementationsTreeDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); - putDockerLocation(defaultConfig, manager.getDocker(CallsTreeDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); + defaultConfig.putDockerLocation(manager.getDocker(StructureDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); + defaultConfig.putDockerLocation(manager.getDocker(InheritanceTreeDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); + defaultConfig.putDockerLocation(manager.getDocker(ImplementationsTreeDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); + defaultConfig.putDockerLocation(manager.getDocker(CallsTreeDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); - putDockerLocation(defaultConfig, manager.getDocker(CollabDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.BOTTOM); - putDockerLocation(defaultConfig, manager.getDocker(NotificationsDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.BOTTOM); + defaultConfig.putDockerLocation(manager.getDocker(CollabDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.BOTTOM); + defaultConfig.putDockerLocation(manager.getDocker(NotificationsDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.BOTTOM); return defaultConfig.dockerLocations; } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindsConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindsConfig.java index 5dd312c3e..e8501baaf 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindsConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindsConfig.java @@ -2,27 +2,18 @@ import org.quiltmc.config.api.ReflectiveConfig; import org.quiltmc.config.api.values.TrackedValue; +import org.quiltmc.config.api.values.ValueMap; import org.quiltmc.enigma.gui.config.keybind.KeyBind; public final class KeyBindsConfig extends ReflectiveConfig.Section { + public final TrackedValue> keyCodes = this.map(new String[]{""}).build(); - private KeyBindsConfig() { + public String[] getKeyBindCodes(KeyBind keyBind) { + String[] codes = this.keyCodes.value().get(keyBind.name()); + return codes.length == 0 ? keyBind.serializeCombinations() : codes; } - - private static ConfigSection getSection(KeyBind keyBind) { - return keyBind.category().isEmpty() ? cfg.data() : cfg.data().section(keyBind.category()); - } - - public static String[] getKeyBindCodes(KeyBind keyBind) { - return getSection(keyBind).getArray(keyBind.name()).orElse(keyBind.serializeCombinations()); - } - - public static void setKeyBind(KeyBind keyBind) { - getSection(keyBind).setArray(keyBind.name(), keyBind.serializeCombinations()); - } - - private static class KeyBindConfig extends ReflectiveConfig.Section { - public final TrackedValue + public void setKeyBind(KeyBind keyBind) { + this.keyCodes.value().put(keyBind.name(), keyBind.serializeCombinations()); } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/keybind/KeyBinds.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/keybind/KeyBinds.java index df752cf99..86cac0811 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/keybind/KeyBinds.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/keybind/KeyBinds.java @@ -1,5 +1,6 @@ package org.quiltmc.enigma.gui.config.keybind; +import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.config.KeyBindsConfig; import java.awt.event.InputEvent; @@ -89,27 +90,21 @@ public static Map> getEditableKeyBindsByCategory() { public static void loadConfig() { for (KeyBind keyBind : CONFIGURABLE_KEY_BINDS) { - keyBind.deserializeCombinations(KeyBindsConfig.getKeyBindCodes(keyBind)); + keyBind.deserializeCombinations(Config.INSTANCE.keyBinds.value().getKeyBindCodes(keyBind)); } resetEditableKeyBinds(); } public static void saveConfig() { - boolean modified = false; for (int i = 0; i < CONFIGURABLE_KEY_BINDS.size(); i++) { KeyBind keyBind = CONFIGURABLE_KEY_BINDS.get(i); KeyBind editedKeyBind = editableKeyBinds.get(i); if (!editedKeyBind.equals(keyBind)) { - modified = true; keyBind.setFrom(editedKeyBind); - KeyBindsConfig.setKeyBind(editedKeyBind); + Config.INSTANCE.keyBinds.value().setKeyBind(editedKeyBind); } } - - if (modified) { - KeyBindsConfig.save(); - } } // Reset the key binds to the saved values diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/nonsense.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/nonsense.java deleted file mode 100644 index 314a56a2c..000000000 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/nonsense.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.quiltmc.enigma.gui.config; - -import org.quiltmc.enigma.gui.docker.Dock; -import org.quiltmc.enigma.gui.docker.Docker; -import org.quiltmc.enigma.gui.docker.DockerManager; -import org.tinylog.Logger; - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -public class nonsense { - public static void setHostedDockers(Docker.Side side, Docker[] dockers) { - String[] dockerData = new String[]{"", ""}; - for (int i = 0; i < dockers.length; i++) { - Docker docker = dockers[i]; - - if (docker != null) { - Docker.Location location = Dock.Util.findLocation(docker); - if (location != null) { - dockerData[i] = (docker.getId() + PAIR_SEPARATOR + location.verticalLocation()); - } - } - } - - swing.data().section(HOSTED_DOCKERS).setArray(side.name(), dockerData); - } - - public static Optional> getHostedDockers(DockerManager manager, Docker.Side side) { - Optional hostedDockers = swing.data().section(HOSTED_DOCKERS).getArray(side.name()); - - if (hostedDockers.isEmpty()) { - return Optional.empty(); - } - - Map dockers = new HashMap<>(); - - for (String dockInfo : hostedDockers.get()) { - if (!dockInfo.isBlank()) { - String[] split = dockInfo.split(PAIR_SEPARATOR); - - try { - Docker.VerticalLocation location = Docker.VerticalLocation.valueOf(split[1]); - Docker docker = manager.getDocker(split[0]); - - dockers.put(docker, location); - } catch (Exception e) { - Logger.error("failed to read docker state for {}, ignoring! ({})", dockInfo, e.getMessage()); - } - } - } - - return Optional.of(dockers); - } - - public static Docker.Location getButtonLocation(Docker docker) { - String location = swing.data().section(DOCKER_BUTTON_LOCATIONS).setIfAbsentString(docker.getId(), docker.getPreferredButtonLocation().toString()); - - try { - return Docker.Location.parse(location); - } catch (Exception e) { - Logger.error("invalid docker button location: {}, ignoring!", location); - setDockerButtonLocation(docker, docker.getPreferredButtonLocation()); - return docker.getPreferredButtonLocation(); - } - } -} diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/LookAndFeel.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/LookAndFeel.java index bfd6ace34..4ce60352a 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/LookAndFeel.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/LookAndFeel.java @@ -36,7 +36,7 @@ public boolean needsScaling() { public void setGlobalLAF() { // Configure FlatLaf's UI scale to be our scale factor. // This is also used for the SVG icons, so it applies even when some other LaF is active. - System.setProperty(FlatSystemProperties.UI_SCALE, Float.toString(Config.getActiveScaleFactor())); + System.setProperty(FlatSystemProperties.UI_SCALE, Float.toString(Config.INSTANCE.scaleFactor.value())); try { switch (this) { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/ThemeColors.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/ThemeColors.java index 949219ab7..f1ab92028 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/ThemeColors.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/ThemeColors.java @@ -32,8 +32,10 @@ public class ThemeColors extends ReflectiveConfig.Section { public final TrackedValue comment = this.value(new Color(0xFF339933, true)); public final TrackedValue text = this.value(new Color(0xFF000000, true)); - private final TrackedValue debugToken = this.value(new Color(0xFFD9BEF9, true)); - private final TrackedValue debugTokenOutline = this.value(new Color(0xFFBD93F9, true)); + public final TrackedValue debugToken = this.value(new Color(0xFFD9BEF9, true)); + public final TrackedValue debugTokenOutline = this.value(new Color(0xFFBD93F9, true)); + + public final TrackedValue dockHighlight = this.value(new Color(0xFF0000FF, true)); public void configure(boolean dark) { if (dark) { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java index 5d8cc67c1..ff12b2872 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java @@ -20,75 +20,70 @@ public class Themes { // Calling this after the UI is initialized (e.g. when the user changes // theme settings) is currently not functional. public static void setupTheme() { - LookAndFeel laf = Config.getActiveLookAndFeel(); + LookAndFeel laf = Config.get().lookAndFeel.value(); laf.setGlobalLAF(); - Config.setLookAndFeelDefaults(Config.getLookAndFeel(), LookAndFeel.isDarkLaf()); - Config.snapshotConfig(); + Config.getCurrentColors().configure(LookAndFeel.isDarkLaf()); Themes.setFonts(); UIManager.put("ScrollBar.showButtons", true); JEditorPane.registerEditorKitForContentType("text/enigma-sources", JavaSyntaxKit.class.getName()); Map boxHighlightPainters = getBoxHighlightPainters(); listeners.forEach(l -> l.onThemeChanged(laf, boxHighlightPainters)); ScaleUtil.applyScaling(); - Config.save(); } private static void setFonts() { - if (Config.activeUseCustomFonts()) { - Font small = Config.getSmallFont(); - Font bold = Config.getDefaultFont(); - Font normal = Config.getDefault2Font(); + Font small = Config.getCurrentFonts().small.value(); + Font bold = Config.getCurrentFonts().defaultFont.value(); - UIManager.put("CheckBox.font", bold); - UIManager.put("CheckBoxMenuItem.font", bold); - UIManager.put("CheckBoxMenuItem.acceleratorFont", small); - UIManager.put("ColorChooser.font", normal); - UIManager.put("ComboBox.font", bold); - UIManager.put("DesktopIcon.font", bold); - UIManager.put("EditorPane.font", normal); - UIManager.put("InternalFrame.titleFont", bold); - UIManager.put("FormattedTextField.font", normal); - UIManager.put("Label.font", bold); - UIManager.put("List.font", bold); - UIManager.put("Menu.acceleratorFont", small); - UIManager.put("Menu.font", bold); - UIManager.put("MenuBar.font", bold); - UIManager.put("MenuItem.acceleratorFont", small); - UIManager.put("MenuItem.font", bold); - UIManager.put("OptionPane.font", normal); - UIManager.put("Panel.font", normal); - UIManager.put("PasswordField.font", normal); - UIManager.put("PopupMenu.font", bold); - UIManager.put("ProgressBar.font", bold); - UIManager.put("RadioButton.font", bold); - UIManager.put("RadioButtonMenuItem.acceleratorFont", small); - UIManager.put("RadioButtonMenuItem.font", bold); - UIManager.put("ScrollPane.font", normal); - UIManager.put("Slider.font", bold); - UIManager.put("Spinner.font", bold); - UIManager.put("TabbedPane.font", bold); - UIManager.put("Table.font", normal); - UIManager.put("TableHeader.font", normal); - UIManager.put("TextArea.font", normal); - UIManager.put("TextField.font", normal); - UIManager.put("TextPane.font", normal); - UIManager.put("TitledBorder.font", bold); - UIManager.put("ToggleButton.font", bold); - UIManager.put("ToolBar.font", bold); - UIManager.put("ToolTip.font", normal); - UIManager.put("Tree.font", normal); - UIManager.put("Viewport.font", normal); - UIManager.put("Button.font", bold); - } + UIManager.put("CheckBox.font", bold); + UIManager.put("CheckBoxMenuItem.font", bold); + UIManager.put("CheckBoxMenuItem.acceleratorFont", small); + UIManager.put("ColorChooser.font", bold); // + UIManager.put("ComboBox.font", bold); + UIManager.put("DesktopIcon.font", bold); + UIManager.put("EditorPane.font", bold); // + UIManager.put("InternalFrame.titleFont", bold); + UIManager.put("FormattedTextField.font", bold); // + UIManager.put("Label.font", bold); + UIManager.put("List.font", bold); + UIManager.put("Menu.acceleratorFont", small); + UIManager.put("Menu.font", bold); + UIManager.put("MenuBar.font", bold); + UIManager.put("MenuItem.acceleratorFont", small); + UIManager.put("MenuItem.font", bold); + UIManager.put("OptionPane.font", bold); // + UIManager.put("Panel.font", bold); // + UIManager.put("PasswordField.font", bold); // + UIManager.put("PopupMenu.font", bold); + UIManager.put("ProgressBar.font", bold); + UIManager.put("RadioButton.font", bold); + UIManager.put("RadioButtonMenuItem.acceleratorFont", small); + UIManager.put("RadioButtonMenuItem.font", bold); + UIManager.put("ScrollPane.font", bold); // + UIManager.put("Slider.font", bold); + UIManager.put("Spinner.font", bold); + UIManager.put("TabbedPane.font", bold); + UIManager.put("Table.font", bold); // + UIManager.put("TableHeader.font", bold); // + UIManager.put("TextArea.font", bold); // + UIManager.put("TextField.font", bold); // + UIManager.put("TextPane.font", bold); // + UIManager.put("TitledBorder.font", bold); + UIManager.put("ToggleButton.font", bold); + UIManager.put("ToolBar.font", bold); + UIManager.put("ToolTip.font", bold); // + UIManager.put("Tree.font", bold); // + UIManager.put("Viewport.font", bold); // + UIManager.put("Button.font", bold); } public static Map getBoxHighlightPainters() { return Map.of( - TokenType.OBFUSCATED, BoxHighlightPainter.create(Config.getObfuscatedColor(), Config.getObfuscatedOutlineColor()), - TokenType.JAR_PROPOSED, BoxHighlightPainter.create(Config.getProposedColor(), Config.getProposedOutlineColor()), - TokenType.DYNAMIC_PROPOSED, BoxHighlightPainter.create(Config.getProposedColor(), Config.getProposedOutlineColor()), - TokenType.DEOBFUSCATED, BoxHighlightPainter.create(Config.getDeobfuscatedColor(), Config.getDeobfuscatedOutlineColor()), - TokenType.DEBUG, BoxHighlightPainter.create(Config.getDebugTokenColor(), Config.getDebugTokenOutlineColor()) + TokenType.OBFUSCATED, BoxHighlightPainter.create(Config.getCurrentColors().obfuscated.value(), Config.getCurrentColors().obfuscatedOutline.value()), + TokenType.JAR_PROPOSED, BoxHighlightPainter.create(Config.getCurrentColors().proposed.value(), Config.getCurrentColors().proposedOutline.value()), + TokenType.DYNAMIC_PROPOSED, BoxHighlightPainter.create(Config.getCurrentColors().proposed.value(), Config.getCurrentColors().proposedOutline.value()), + TokenType.DEOBFUSCATED, BoxHighlightPainter.create(Config.getCurrentColors().deobfuscated.value(), Config.getCurrentColors().deobfuscatedOutline.value()), + TokenType.DEBUG, BoxHighlightPainter.create(Config.getCurrentColors().debugToken.value(), Config.getCurrentColors().debugTokenOutline.value()) ); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/ConnectToServerDialog.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/ConnectToServerDialog.java index c84a4cd3f..34fbe65ec 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/ConnectToServerDialog.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/ConnectToServerDialog.java @@ -1,7 +1,7 @@ package org.quiltmc.enigma.gui.dialog; import org.quiltmc.enigma.gui.Gui; -import org.quiltmc.enigma.gui.config.NetConfig; +import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.util.ScaleUtil; import org.quiltmc.enigma.network.EnigmaServer; import org.quiltmc.enigma.network.ServerAddress; @@ -35,9 +35,9 @@ public ConnectToServerDialog(Frame owner, Gui gui) { @Override protected List> createComponents() { - this.usernameField = new JTextField(NetConfig.getUsername()); - this.ipField = new JTextField(NetConfig.getRemoteAddress()); - this.passwordField = new JPasswordField(NetConfig.getPassword()); + this.usernameField = new JTextField(Config.INSTANCE.getNetConfig().username.value()); + this.ipField = new JTextField(Config.INSTANCE.getNetConfig().remoteAddress.value()); + this.passwordField = new JPasswordField(Config.INSTANCE.getNetConfig().password.value()); this.usernameField.addActionListener(event -> this.confirm()); this.ipField.addActionListener(event -> this.confirm()); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/CreateServerDialog.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/CreateServerDialog.java index 5b5645857..7bc5cf492 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/CreateServerDialog.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/CreateServerDialog.java @@ -1,7 +1,7 @@ package org.quiltmc.enigma.gui.dialog; import org.quiltmc.enigma.gui.Gui; -import org.quiltmc.enigma.gui.config.NetConfig; +import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.util.ScaleUtil; import org.quiltmc.enigma.network.EnigmaServer; import org.quiltmc.enigma.util.Pair; @@ -32,8 +32,8 @@ public CreateServerDialog(Frame owner, Gui gui) { @Override protected List> createComponents() { - this.portField = new JTextField(Integer.toString(NetConfig.getServerPort())); - this.passwordField = new JPasswordField(NetConfig.getServerPassword()); + this.portField = new JTextField(Integer.toString(Config.INSTANCE.getNetConfig().serverPort.value())); + this.passwordField = new JPasswordField(Config.INSTANCE.getNetConfig().serverPassword.value()); this.portField.addActionListener(event -> this.confirm()); this.passwordField.addActionListener(event -> this.confirm()); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/JavadocDialog.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/JavadocDialog.java index 46de41a32..420361541 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/JavadocDialog.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/JavadocDialog.java @@ -65,7 +65,7 @@ private JavadocDialog(JFrame parent, GuiController controller, Entry entry, S this.close(); } })); - this.text.setFont(Config.activeUseCustomFonts() ? Config.getEditorFont() : Config.getFallbackEditorFont()); + this.text.setFont(Config.INSTANCE.getCurrentFonts().editor.value()); // buttons panel JPanel buttonsPanel = new JPanel(); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Dock.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Dock.java index 1658cf2c3..53e01f3b9 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Dock.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Dock.java @@ -62,10 +62,10 @@ public Dock(Gui gui, Docker.Side side) { /** * Restores the state of this dock to the version saved in the config file. */ - public void restoreState() { + public void restoreState(DockerManager manager) { // restore docker state - Optional> hostedDockers = Config.getHostedDockers(this.gui.getDockerManager(), this.side); - hostedDockers.ifPresent(m -> m.forEach(this::host)); + Map hostedDockers = Config.getDockerConfig().getHostedDockers(this.side); + hostedDockers.forEach((id, location) -> this.host(manager.getDocker(id), location.verticalLocation())); this.restoreDividerState(true); @@ -85,18 +85,18 @@ public void saveState() { public void restoreDividerState(boolean init) { // restore vertical divider state if (this.isSplit) { - this.splitPane.setDividerLocation(Config.getVerticalDockDividerLocation(this.side)); + this.splitPane.setDividerLocation(Config.getDockerConfig().getVerticalDividerLocation(this.side)); } // restore horizontal divider state JSplitPane parentSplitPane = this.getParentSplitPane(); - int location = Config.getHorizontalDividerLocation(this.side); + int location = Config.getDockerConfig().getHorizontalDividerLocation(this.side); // hack fix: if the right dock is closed while the left dock is open, the divider location is saved as if the left dock is open, // thereby offsetting the divider location by the width of the left dock. which means, if the right dock is reopened while the left dock is closed, // the divider location is too far to the left by the width of the left dock. so here we offset the location to avoid that. - if (init && this.side == Docker.Side.RIGHT && !this.gui.getSplitLeft().getLeftComponent().isVisible() && Config.getSavedWithLeftOpen()) { - location += Config.getHorizontalDividerLocation(Docker.Side.LEFT); + if (init && this.side == Docker.Side.RIGHT && !this.gui.getSplitLeft().getLeftComponent().isVisible() && Config.getDockerConfig().savedWithLeftDockerOpen.value()) { + location += Config.getDockerConfig().getHorizontalDividerLocation(Docker.Side.LEFT); } parentSplitPane.setDividerLocation(location); @@ -106,16 +106,16 @@ public void saveDividerState() { if (this.isVisible()) { // save vertical divider state if (this.isSplit) { - Config.setVerticalDockDividerLocation(this.side, this.splitPane.getDividerLocation()); + Config.getDockerConfig().setVerticalDividerLocation(this.side, this.splitPane.getDividerLocation()); } // save horizontal divider state JSplitPane parentSplitPane = this.getParentSplitPane(); - Config.setHorizontalDividerLocation(this.side, parentSplitPane.getDividerLocation()); + Config.getDockerConfig().setHorizontalDividerLocation(this.side, parentSplitPane.getDividerLocation()); // hack if (this.side == Docker.Side.RIGHT) { - Config.setSavedWithLeftOpen(this.gui.getSplitLeft().getLeftComponent().isVisible()); + Config.getDockerConfig().savedWithLeftDockerOpen.setValue(this.gui.getSplitLeft().getLeftComponent().isVisible(), true); } } } @@ -184,7 +184,7 @@ public void host(Docker docker, Docker.VerticalLocation verticalLocation, boolea parent.remove(button); (verticalLocation == Docker.VerticalLocation.TOP ? selector.getTopSelector() : selector.getBottomSelector()).add(button); button.setSide(this.side); - Config.setDockerButtonLocation(docker, new Docker.Location(this.side, verticalLocation)); + Config.getDockerConfig().putDockerLocation(docker, this.side, verticalLocation); button.getParent().revalidate(); button.getParent().repaint(); @@ -357,7 +357,7 @@ public void paint(Graphics graphics) { if (this.hovered != null) { Rectangle paintedBounds = this.getHighlightBoundsFor(new Point(0, 0), this.hovered); - Color color = Config.getDockHighlightColor(); + Color color = Config.getCurrentColors().dockHighlight.value(); graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 100)); graphics.fillRect(paintedBounds.x, paintedBounds.y, paintedBounds.width, paintedBounds.height); this.repaint(); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java index 066f53395..5321ba343 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java @@ -70,7 +70,7 @@ public DockerButton getButton() { * @return the position of the docker's button in the selector panels. this also represents where the docker will open when its button is clicked cannot use {@link Docker.VerticalLocation#FULL} */ public final Location getButtonLocation() { - return Config.getButtonLocation(this); + return Config.getDockerConfig().getDockerLocation(this.getId()); } public abstract Location getPreferredButtonLocation(); @@ -104,14 +104,9 @@ public int hashCode() { * @param verticalLocation the vertical location of the docker, being full, top or bottom */ public record Location(Side side, VerticalLocation verticalLocation) { - public static Location parse(String string) { - String[] parts = string.split(Config.PAIR_SEPARATOR); - return new Location(Side.valueOf(parts[0].toUpperCase()), VerticalLocation.valueOf(parts[1].toUpperCase())); - } - @Override public String toString() { - return this.side.name().toLowerCase() + Config.PAIR_SEPARATOR + this.verticalLocation.name().toLowerCase(); + return this.side.name().toLowerCase() + ";" + this.verticalLocation.name().toLowerCase(); } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/DockerManager.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/DockerManager.java index a791d6214..1b8279d4b 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/DockerManager.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/DockerManager.java @@ -70,11 +70,11 @@ public void setupDefaultConfiguration() { /** * Restores the state of both docks to the version saved in the config. - * @see Dock#restoreState() + * @see Dock#restoreState(DockerManager) */ public void restoreStateFromConfig() { - this.leftDock.restoreState(); - this.rightDock.restoreState(); + this.leftDock.restoreState(this); + this.rightDock.restoreState(this); } /** diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java index 03c93320c..9de87a22c 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java @@ -121,8 +121,8 @@ public void paint(Graphics g) { // setup text String translatedText = this.textSupplier.get(); - Font font = Config.getDefault2Font(); - if (Config.getLookAndFeel().equals(LookAndFeel.SYSTEM)) { + Font font = Config.getCurrentFonts().defaultFont.value(); + if (Config.get().lookAndFeel.value().equals(LookAndFeel.SYSTEM)) { font = font.deriveFont(Font.BOLD); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerSelector.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerSelector.java index f00707bdf..f7bed9f70 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerSelector.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerSelector.java @@ -97,7 +97,7 @@ private boolean dropButton(DockerButton button, MouseEvent event) { if (hoveredPanel != null) { hoveredPanel.add(button); button.setSide(this.side); - Config.setDockerButtonLocation(button.getDocker(), new Docker.Location(this.side, hoveredPanel.equals(this.bottomSelector) ? Docker.VerticalLocation.BOTTOM : Docker.VerticalLocation.TOP)); + Config.getDockerConfig().putDockerLocation(button.getDocker(), this.side, hoveredPanel.equals(this.bottomSelector) ? Docker.VerticalLocation.BOTTOM : Docker.VerticalLocation.TOP); return true; } @@ -111,7 +111,7 @@ public void paint(Graphics graphics) { if (this.hovered != null) { Rectangle paintedBounds = this.getScreenBoundsFor(this.hovered); - Color color = Config.getDockHighlightColor(); + Color color = Config.getCurrentColors().dockHighlight.value(); graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 100)); graphics.fillRect(0, this.hovered.equals(this.bottomSelector) ? paintedBounds.height : 0, paintedBounds.width, paintedBounds.height); this.repaint(); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java index a57e17725..36608cc7f 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java @@ -275,7 +275,7 @@ public void retranslateUi() { private void onOpenJarClicked() { JFileChooser d = this.gui.jarFileChooser; - d.setCurrentDirectory(new File(Config.getLastSelectedDir())); + d.setCurrentDirectory(new File(Config.INSTANCE.lastSelectedDir.value())); d.setVisible(true); int result = d.showOpenDialog(this.gui.getFrame()); @@ -292,12 +292,12 @@ private void onOpenJarClicked() { this.gui.getController().openJar(path); } - Config.setLastSelectedDir(d.getCurrentDirectory().getAbsolutePath()); + Config.INSTANCE.lastSelectedDir.setValue(d.getCurrentDirectory().getAbsolutePath(), true); } } private void onMaxRecentFilesClicked() { - String input = JOptionPane.showInputDialog(this.gui.getFrame(), I18n.translate("menu.file.dialog.max_recent_projects.set"), Config.getMaxRecentFiles()); + String input = JOptionPane.showInputDialog(this.gui.getFrame(), I18n.translate("menu.file.dialog.max_recent_projects.set"), Config.INSTANCE.maxRecentFiles.value()); if (input != null) { try { @@ -306,7 +306,7 @@ private void onMaxRecentFilesClicked() { throw new NumberFormatException(); } - Config.setMaxRecentFiles(max); + Config.INSTANCE.maxRecentFiles.setValue(max, true); } catch (NumberFormatException e) { JOptionPane.showMessageDialog(this.gui.getFrame(), I18n.translate("prompt.invalid_input"), I18n.translate("prompt.error"), JOptionPane.ERROR_MESSAGE); } @@ -346,15 +346,15 @@ private void onReloadAllClicked() { } private void onExportSourceClicked() { - this.gui.exportSourceFileChooser.setCurrentDirectory(new File(Config.getLastSelectedDir())); + this.gui.exportSourceFileChooser.setCurrentDirectory(new File(Config.INSTANCE.lastSelectedDir.value())); if (this.gui.exportSourceFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { - Config.setLastSelectedDir(this.gui.exportSourceFileChooser.getCurrentDirectory().toString()); + Config.INSTANCE.lastSelectedDir.setValue(this.gui.exportSourceFileChooser.getCurrentDirectory().toString(), true); this.gui.getController().exportSource(this.gui.exportSourceFileChooser.getSelectedFile().toPath()); } } private void onExportJarClicked() { - this.gui.exportJarFileChooser.setCurrentDirectory(new File(Config.getLastSelectedDir())); + this.gui.exportJarFileChooser.setCurrentDirectory(new File(Config.INSTANCE.lastSelectedDir.value())); this.gui.exportJarFileChooser.setVisible(true); int result = this.gui.exportJarFileChooser.showSaveDialog(this.gui.getFrame()); @@ -365,13 +365,13 @@ private void onExportJarClicked() { if (this.gui.exportJarFileChooser.getSelectedFile() != null) { Path path = this.gui.exportJarFileChooser.getSelectedFile().toPath(); this.gui.getController().exportJar(path); - Config.setLastSelectedDir(this.gui.exportJarFileChooser.getCurrentDirectory().getAbsolutePath()); + Config.INSTANCE.lastSelectedDir.setValue(this.gui.exportJarFileChooser.getCurrentDirectory().getAbsolutePath(), true); } } private void onCustomScaleClicked() { String answer = (String) JOptionPane.showInputDialog(this.gui.getFrame(), I18n.translate("menu.view.scale.custom.title"), I18n.translate("menu.view.scale.custom.title"), - JOptionPane.QUESTION_MESSAGE, null, null, Float.toString(Config.getScaleFactor() * 100)); + JOptionPane.QUESTION_MESSAGE, null, null, Double.toString(Config.INSTANCE.scaleFactor.value() * 100)); if (answer == null) { return; @@ -412,14 +412,13 @@ public void onConnectClicked() { this.gui.getController().disconnectIfConnected(null); try { this.gui.getController().createClient(result.username(), result.address().address, result.address().port, result.password()); - if (Config.getServerNotificationLevel() != NotificationManager.ServerNotificationLevel.NONE) { + if (Config.INSTANCE.serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { this.gui.getNotificationManager().notify(new ParameterizedMessage(Message.CONNECTED_TO_SERVER, result.addressStr())); } - NetConfig.setUsername(result.username()); - NetConfig.setRemoteAddress(result.addressStr()); - NetConfig.setPassword(String.valueOf(result.password())); - NetConfig.save(); + Config.INSTANCE.getNetConfig().username.setValue(result.username(), true); + Config.INSTANCE.getNetConfig().remoteAddress.setValue(result.addressStr(), true); + Config.INSTANCE.getNetConfig().password.setValue(String.valueOf(result.password()), true); } catch (IOException e) { JOptionPane.showMessageDialog(this.gui.getFrame(), e.toString(), I18n.translate("menu.collab.connect.error"), JOptionPane.ERROR_MESSAGE); this.gui.getController().disconnectIfConnected(null); @@ -442,13 +441,12 @@ public void onStartServerClicked() { this.gui.getController().disconnectIfConnected(null); try { this.gui.getController().createServer(result.port(), result.password()); - if (Config.getServerNotificationLevel() != NotificationManager.ServerNotificationLevel.NONE) { + if (Config.INSTANCE.serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { this.gui.getNotificationManager().notify(new ParameterizedMessage(Message.SERVER_STARTED, result.port())); } - NetConfig.setServerPort(result.port()); - NetConfig.setServerPassword(String.valueOf(result.password())); - NetConfig.save(); + Config.INSTANCE.getNetConfig().serverPort.setValue(result.port(), true); + Config.INSTANCE.getNetConfig().serverPassword.setValue(String.valueOf(result.password()), true); } catch (IOException e) { JOptionPane.showMessageDialog(this.gui.getFrame(), e.toString(), I18n.translate("menu.collab.server.start.error"), JOptionPane.ERROR_MESSAGE); this.gui.getController().disconnectIfConnected(null); @@ -460,10 +458,10 @@ private void onGithubClicked() { } private void onOpenMappingsClicked() { - this.gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(Config.getLastSelectedDir())); + this.gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(Config.INSTANCE.lastSelectedDir.value())); if (this.gui.enigmaMappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { File selectedFile = this.gui.enigmaMappingsFileChooser.getSelectedFile(); - Config.setLastSelectedDir(this.gui.enigmaMappingsFileChooser.getCurrentDirectory().toString()); + Config.INSTANCE.lastSelectedDir.setValue(this.gui.enigmaMappingsFileChooser.getCurrentDirectory().toString(), true); MappingFormat format = MappingFormat.parseFromFile(selectedFile.toPath()); if (format.getReader() != null) { @@ -542,13 +540,13 @@ private static void prepareSaveMappingsAsMenu(JMenu saveMappingsAsMenu, JMenuIte item.addActionListener(event -> { // TODO: Use a specific file chooser for it if (gui.enigmaMappingsFileChooser.getCurrentDirectory() == null) { - gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(Config.getLastSelectedDir())); + gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(Config.INSTANCE.lastSelectedDir.value())); } if (gui.enigmaMappingsFileChooser.showSaveDialog(gui.getFrame()) == JFileChooser.APPROVE_OPTION) { gui.getController().saveMappings(gui.enigmaMappingsFileChooser.getSelectedFile().toPath(), format); saveMappingsItem.setEnabled(true); - Config.setLastSelectedDir(gui.enigmaMappingsFileChooser.getCurrentDirectory().toString()); + Config.get().lastSelectedDir.setValue(gui.enigmaMappingsFileChooser.getCurrentDirectory().toString(), true); } }); saveMappingsAsMenu.add(item); @@ -562,15 +560,14 @@ private static void prepareDecompilerMenu(JMenu decompilerMenu, JMenuItem decomp for (Decompiler decompiler : Decompiler.values()) { JRadioButtonMenuItem decompilerButton = new JRadioButtonMenuItem(decompiler.name); decompilerGroup.add(decompilerButton); - if (decompiler.equals(Config.getDecompiler())) { + if (decompiler.equals(Config.getDecompilerConfig().decompiler.value())) { decompilerButton.setSelected(true); } decompilerButton.addActionListener(event -> { gui.getController().setDecompiler(decompiler.service); - Config.setDecompiler(decompiler); - Config.save(); + Config.getDecompilerConfig().decompiler.setValue(decompiler, true); }); decompilerMenu.add(decompilerButton); } @@ -584,13 +581,12 @@ private static void prepareThemesMenu(JMenu themesMenu, Gui gui) { for (LookAndFeel lookAndFeel : LookAndFeel.values()) { JRadioButtonMenuItem themeButton = new JRadioButtonMenuItem(I18n.translate("menu.view.themes." + lookAndFeel.name().toLowerCase(Locale.ROOT))); themeGroup.add(themeButton); - if (lookAndFeel.equals(Config.getLookAndFeel())) { + if (lookAndFeel.equals(Config.get().lookAndFeel.value())) { themeButton.setSelected(true); } themeButton.addActionListener(e -> { - Config.setLookAndFeel(lookAndFeel); - Config.save(); + Config.get().lookAndFeel.setValue(lookAndFeel, true); Themes.setupTheme(); ChangeDialog.show(gui.getFrame()); }); @@ -603,15 +599,14 @@ private static void prepareLanguagesMenu(JMenu languagesMenu) { for (String lang : I18n.getAvailableLanguages()) { JRadioButtonMenuItem languageButton = new JRadioButtonMenuItem(I18n.getLanguageName(lang)); languageGroup.add(languageButton); - if (lang.equals(Config.getLanguage())) { + if (lang.equals(Config.get().language.value())) { languageButton.setSelected(true); } languageButton.addActionListener(event -> { - Config.setLanguage(lang); + Config.get().language.setValue(lang, true); I18n.setLanguage(lang); LanguageUtil.dispatchLanguageChange(); - Config.save(); }); languagesMenu.add(languageButton); } @@ -631,7 +626,7 @@ private static void prepareScaleMenu(JMenu scaleMenu, Gui gui) { }) .collect(Collectors.toMap(Pair::a, Pair::b)); - JRadioButtonMenuItem currentScaleButton = scaleButtons.get(Config.getScaleFactor()); + JRadioButtonMenuItem currentScaleButton = scaleButtons.get(Config.get().scaleFactor.value()); if (currentScaleButton != null) { currentScaleButton.setSelected(true); } @@ -653,11 +648,11 @@ private static void prepareNotificationsMenu(JMenu notificationsMenu) { JRadioButtonMenuItem notificationsButton = new JRadioButtonMenuItem(level.getText()); notificationsGroup.add(notificationsButton); - if (level.equals(Config.getServerNotificationLevel())) { + if (level.equals(Config.get().serverNotificationLevel.value())) { notificationsButton.setSelected(true); } - notificationsButton.addActionListener(event -> Config.setServerNotificationLevel(level)); + notificationsButton.addActionListener(event -> Config.get().serverNotificationLevel.setValue(level, true)); notificationsMenu.add(notificationsButton); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/highlight/SelectionHighlightPainter.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/highlight/SelectionHighlightPainter.java index c94c34784..b5c9103a0 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/highlight/SelectionHighlightPainter.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/highlight/SelectionHighlightPainter.java @@ -18,7 +18,7 @@ public void paint(Graphics g, int start, int end, Shape shape, JTextComponent te // draw a thick border Graphics2D g2d = (Graphics2D) g; Rectangle bounds = BoxHighlightPainter.getBounds(text, start, end); - g2d.setColor(Config.getSelectionHighlightColor()); + g2d.setColor(Config.getCurrentColors().selectionHighlight.value()); g2d.setStroke(new BasicStroke(2.0f)); g2d.drawRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/panel/EditorPanel.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/panel/EditorPanel.java index b875d60c6..0f7f12ea5 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/panel/EditorPanel.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/panel/EditorPanel.java @@ -120,9 +120,9 @@ public EditorPanel(Gui gui, NavigatorPanel navigator) { this.editor.setCaret(new BrowserCaret()); this.editor.setFont(ScaleUtil.getFont(this.editor.getFont().getFontName(), Font.PLAIN, this.fontSize)); this.editor.addCaretListener(event -> this.onCaretMove(event.getDot(), this.mouseIsPressed)); - this.editor.setCaretColor(Config.getCaretColor()); + this.editor.setCaretColor(Config.INSTANCE.getCurrentColors().caret.value()); this.editor.setContentType("text/enigma-sources"); - this.editor.setBackground(Config.getEditorBackgroundColor()); + this.editor.setBackground(Config.INSTANCE.getCurrentColors().editorBackground.value()); // set unit increment to height of one line, the amount scrolled per // mouse wheel rotation is then controlled by OS settings @@ -213,7 +213,7 @@ public void keyReleased(KeyEvent event) { this.themeChangeListener = (laf, boxHighlightPainters) -> { if ((this.editorLaf == null || this.editorLaf != laf)) { this.editor.updateUI(); - this.editor.setBackground(Config.getEditorBackgroundColor()); + this.editor.setBackground(Config.INSTANCE.getCurrentColors().editorBackground.value()); if (this.editorLaf != null) { this.classHandle.invalidateMapped(); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/CallsTreeCellRenderer.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/CallsTreeCellRenderer.java index 7431c68c6..5c2e40ece 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/CallsTreeCellRenderer.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/CallsTreeCellRenderer.java @@ -26,7 +26,7 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean Component c = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); EntryReference reference = ((ReferenceTreeNode) value).getReference(); - this.setForeground(Config.getTextColor()); + this.setForeground(Config.INSTANCE.getCurrentColors().text.value()); // if the node represents the method calling the entry if (reference != null) { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/ImplementationsTreeCellRenderer.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/ImplementationsTreeCellRenderer.java index a1a4ba4b4..223b69595 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/ImplementationsTreeCellRenderer.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/ImplementationsTreeCellRenderer.java @@ -21,7 +21,7 @@ public ImplementationsTreeCellRenderer(Gui gui) { public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { Component c = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); - this.setForeground(Config.getTextColor()); + this.setForeground(Config.getCurrentColors().text.value()); if (value instanceof ClassImplementationsTreeNode node) { this.setIcon(GuiUtil.getClassIcon(this.gui, node.getClassEntry())); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/InheritanceTreeCellRenderer.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/InheritanceTreeCellRenderer.java index ea79bac4a..e48d08c2d 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/InheritanceTreeCellRenderer.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/InheritanceTreeCellRenderer.java @@ -23,7 +23,7 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean Component ret = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); if (!(value instanceof MethodInheritanceTreeNode node) || node.isImplemented()) { - ret.setForeground(Config.getTextColor()); + ret.setForeground(Config.getCurrentColors().text.value()); ret.setFont(ret.getFont().deriveFont(Font.PLAIN)); if (value instanceof ClassInheritanceTreeNode) { this.setIcon(GuiUtil.getClassIcon(this.gui, ((ClassInheritanceTreeNode) value).getClassEntry())); @@ -31,7 +31,7 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean this.setIcon(GuiUtil.getMethodIcon(((MethodInheritanceTreeNode) value).getMethodEntry())); } } else { - ret.setForeground(Config.getNumberColor()); + ret.setForeground(Config.getCurrentColors().number.value()); ret.setFont(ret.getFont().deriveFont(Font.ITALIC)); this.setIcon(GuiUtil.CLASS_ICON); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java index 251cfa189..b0104ea0f 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java @@ -5,6 +5,7 @@ import com.github.swingdpi.plaf.MetalTweaker; import com.github.swingdpi.plaf.NimbusTweaker; import com.github.swingdpi.plaf.WindowsTweaker; +import org.quiltmc.config.api.values.TrackedValue; import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.syntaxpain.SyntaxpainConfiguration; @@ -21,14 +22,12 @@ public class ScaleUtil { private static final List listeners = new ArrayList<>(); public static void setScaleFactor(float scaleFactor) { - float oldScale = Config.getScaleFactor(); + float oldScale = Config.INSTANCE.scaleFactor.value(); float clamped = Math.min(Math.max(0.25f, scaleFactor), 10.0f); - Config.setScaleFactor(clamped); - rescaleFontInConfig("Default", oldScale); - rescaleFontInConfig("Default 2", oldScale); - rescaleFontInConfig("Small", oldScale); - rescaleFontInConfig("Editor", oldScale); - Config.save(); + Config.INSTANCE.scaleFactor.setValue(clamped, true); + rescaleFontInConfig(Config.INSTANCE.getCurrentFonts().defaultFont, oldScale); + rescaleFontInConfig(Config.INSTANCE.getCurrentFonts().small, oldScale); + rescaleFontInConfig(Config.INSTANCE.getCurrentFonts().editor, oldScale); listeners.forEach(l -> l.onScaleChanged(clamped, oldScale)); } @@ -53,29 +52,29 @@ public static Font getFont(String fontName, int style, int fontSize) { } public static Font scaleFont(Font font) { - return createTweakerForCurrentLook(Config.getActiveScaleFactor()).modifyFont("", font); + return createTweakerForCurrentLook(Config.INSTANCE.scaleFactor.value()).modifyFont("", font); } - private static void rescaleFontInConfig(String name, float oldScale) { - Config.getFont(name).ifPresent(font -> Config.setFont(name, rescaleFont(font, oldScale))); + private static void rescaleFontInConfig(TrackedValue font, float oldScale) { + font.setValue(rescaleFont(font.value(), oldScale), true); } // This does not use the font that's currently active in the UI! private static Font rescaleFont(Font font, float oldScale) { - float newSize = Math.round(font.getSize() / oldScale * Config.getScaleFactor()); + float newSize = Math.round(font.getSize() / oldScale * Config.INSTANCE.scaleFactor.value()); return font.deriveFont(newSize); } public static float scale(float f) { - return f * Config.getActiveScaleFactor(); + return f * Config.INSTANCE.scaleFactor.value(); } public static float invert(float f) { - return f / Config.getActiveScaleFactor(); + return f / Config.INSTANCE.scaleFactor.value(); } public static int scale(int i) { - return (int) (i * Config.getActiveScaleFactor()); + return (int) (i * Config.INSTANCE.scaleFactor.value()); } public static Border createEmptyBorder(int top, int left, int bottom, int right) { @@ -83,18 +82,18 @@ public static Border createEmptyBorder(int top, int left, int bottom, int right) } public static int invert(int i) { - return (int) (i / Config.getActiveScaleFactor()); + return (int) (i / Config.INSTANCE.scaleFactor.value()); } public static void applyScaling() { - float scale = Config.getActiveScaleFactor(); + double scale = Config.INSTANCE.scaleFactor.value(); - if (Config.getActiveLookAndFeel().needsScaling()) { + if (Config.INSTANCE.activeLookAndFeel.needsScaling()) { UiDefaultsScaler.updateAndApplyGlobalScaling((int) (100 * scale), true); } - Font font = Config.getEditorFont(); - font = font.deriveFont(12 * scale); + Font font = Config.INSTANCE.getCurrentFonts().editor.value(); + font = font.deriveFont((float) (12 * scale)); SyntaxpainConfiguration.setEditorFont(font); } From 27f5c62f6edb529fbbf88021bb8352097188cc34 Mon Sep 17 00:00:00 2001 From: ix0rai Date: Sun, 26 Nov 2023 15:39:16 -0600 Subject: [PATCH 06/25] progress --- .../main/java/org/quiltmc/enigma/gui/Gui.java | 18 ++++---- .../org/quiltmc/enigma/gui/GuiController.java | 5 +-- .../java/org/quiltmc/enigma/gui/Main.java | 8 ++-- .../org/quiltmc/enigma/gui/config/Config.java | 45 ++++++++++++------- .../enigma/gui/config/DockerConfig.java | 37 +++++++-------- .../enigma/gui/config/keybind/KeyBinds.java | 3 +- .../enigma/gui/config/theme/Themes.java | 16 +++---- .../gui/dialog/ConnectToServerDialog.java | 6 +-- .../enigma/gui/dialog/CreateServerDialog.java | 4 +- .../quiltmc/enigma/gui/dialog/FontDialog.java | 19 ++++---- .../enigma/gui/dialog/JavadocDialog.java | 2 +- .../org/quiltmc/enigma/gui/docker/Dock.java | 29 +++++------- .../org/quiltmc/enigma/gui/docker/Docker.java | 2 +- .../enigma/gui/docker/DockerManager.java | 9 ---- .../gui/docker/component/DockerButton.java | 2 +- .../gui/docker/component/DockerSelector.java | 4 +- .../quiltmc/enigma/gui/element/MenuBar.java | 33 +++++++------- .../highlight/SelectionHighlightPainter.java | 2 +- .../quiltmc/enigma/gui/panel/EditorPanel.java | 6 +-- .../gui/renderer/CallsTreeCellRenderer.java | 2 +- .../ImplementationsTreeCellRenderer.java | 2 +- .../renderer/InheritanceTreeCellRenderer.java | 4 +- .../quiltmc/enigma/gui/util/ScaleUtil.java | 8 ++-- 23 files changed, 127 insertions(+), 139 deletions(-) diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java index d8187aa58..ed5cfd4f5 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java @@ -6,7 +6,6 @@ import org.quiltmc.enigma.api.translation.mapping.EntryMapping; import org.quiltmc.enigma.api.translation.mapping.EntryRemapper; import org.quiltmc.enigma.gui.config.DockerConfig; -import org.quiltmc.enigma.gui.config.NetConfig; import org.quiltmc.enigma.gui.config.theme.Themes; import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.dialog.JavadocDialog; @@ -148,8 +147,8 @@ private void setupDockers() { this.dockerManager.registerDocker(new AllClassesDocker(this)); this.dockerManager.registerDocker(new DeobfuscatedClassesDocker(this)); - if (Config.INSTANCE.getDockerConfig().dockerLocations.value().isEmpty()) { - Config.INSTANCE.getDockerConfig().dockerLocations.value().setValue(DockerConfig.getDefaultLocations(this.dockerManager)); + if (Config.dockers().dockerLocations.value().isEmpty()) { + Config.dockers().dockerLocations.value().setValue(DockerConfig.getDefaultLocations(this.dockerManager)); } // set default docker sizes @@ -196,7 +195,7 @@ private void setupUi() { this.splitLeft.setResizeWeight(0); // todo probably doesn't work - if (!Config.INSTANCE.dockerConfig.value().getHostedDockers(Docker.Side.LEFT).isEmpty() || !Config.INSTANCE.dockerConfig.value().getHostedDockers(Docker.Side.RIGHT).isEmpty()) { + if (!Config.dockers().getLocations(Docker.Side.LEFT).isEmpty() || !Config.dockers().getLocations(Docker.Side.RIGHT).isEmpty()) { this.dockerManager.restoreStateFromConfig(); } else { this.dockerManager.setupDefaultConfiguration(); @@ -519,8 +518,7 @@ private void exit() { Config.get().windowPos.setValue(this.mainWindow.getFrame().getLocationOnScreen(), true); Config.get().windowSize.setValue(this.mainWindow.getFrame().getSize(), true); - this.dockerManager.saveStateToConfig(); - Config.INSTANCE.save(); + Config.get().save(); this.searchDialog.dispose(); this.mainWindow.getFrame().dispose(); @@ -700,11 +698,11 @@ public void reloadKeyBinds() { } public void openMostRecentFiles() { - var pair = Config.INSTANCE.getMostRecentFilePair(); + Config.RecentProject project = Config.getMostRecentProject(); - if (pair.isPresent()) { - this.getNotificationManager().notify(ParameterizedMessage.openedProject(pair.get().a().toString(), pair.get().b().toString())); - this.controller.openJar(pair.get().a()).whenComplete((v, t) -> this.controller.openMappings(pair.get().b())); + if (project != null) { + this.getNotificationManager().notify(ParameterizedMessage.openedProject(project.jarPath(), project.mappingsPath())); + this.controller.openJar(project.getJarPath()).whenComplete((v, t) -> this.controller.openMappings(project.getMappingsPath())); } } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java index e7bb7f922..214f8df11 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java @@ -22,7 +22,6 @@ import org.quiltmc.enigma.api.class_handle.ClassHandle; import org.quiltmc.enigma.api.class_handle.ClassHandleProvider; import org.quiltmc.enigma.api.class_provider.ClasspathClassProvider; -import org.quiltmc.enigma.gui.config.NetConfig; import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.dialog.ProgressDialog; import org.quiltmc.enigma.gui.docker.CollabDocker; @@ -153,7 +152,7 @@ public CompletableFuture openMappings(MappingFormat format, Path path) { } this.gui.setMappingsFile(path); - Config.addRecentFilePair(this.project.getJarPath(), path); + Config.insertRecentProject(this.project.getJarPath().toString(), path.toString()); this.gui.getMenuBar().reloadOpenRecentMenu(this.gui); return ProgressDialog.runOffThread(this.gui, progress -> { @@ -619,7 +618,7 @@ public void createServer(int port, char[] password) throws IOException { this.server.start(); this.client = new EnigmaClient(this, "127.0.0.1", port); this.client.connect(); - this.client.sendPacket(new LoginC2SPacket(this.project.getJarChecksum(), password, Config.INSTANCE.getNetConfig().username.value())); + this.client.sendPacket(new LoginC2SPacket(this.project.getJarChecksum(), password, Config.INSTANCE.net().username.value())); this.gui.setConnectionState(ConnectionState.HOSTING); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java index b0eca6ad9..1811b9af3 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java @@ -131,10 +131,10 @@ public static void main(String[] args) throws IOException { gui.getNotificationManager().notify(ParameterizedMessage.openedProject(jarPath.toString(), mappingsPath.toString())); } else { // search for mappings that are associated with the jar - for (var pair : Config.getRecentFilePairs()) { - if (pair.a().equals(jarPath)) { - gui.getNotificationManager().notify(ParameterizedMessage.openedProject(pair.a().toString(), pair.b().toString())); - gui.getController().openMappings(pair.b()); + for (Config.RecentProject recentProject : Config.INSTANCE.recentProjects.value()) { + if (recentProject.getJarPath().equals(jarPath)) { + gui.getNotificationManager().notify(ParameterizedMessage.openedProject(recentProject.jarPath(), recentProject.mappingsPath())); + gui.getController().openMappings(recentProject.getMappingsPath()); break; } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java index be51e3a7b..f154a6fd9 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java @@ -3,7 +3,6 @@ import org.quiltmc.config.api.ReflectiveConfig; import org.quiltmc.config.api.values.TrackedValue; import org.quiltmc.config.api.values.ValueList; -import org.quiltmc.config.api.values.ValueMap; import org.quiltmc.enigma.gui.NotificationManager; import org.quiltmc.enigma.gui.config.theme.LookAndFeel; import org.quiltmc.enigma.gui.config.theme.Theme; @@ -16,18 +15,20 @@ import java.awt.Dimension; import java.awt.Point; +import java.nio.file.Path; +import java.nio.file.Paths; public final class Config extends ReflectiveConfig { public static final Config INSTANCE = new Config(); public Config() { - this.updateSyntaxpain(); + updateSyntaxpain(); } public final TrackedValue language = this.value(I18n.DEFAULT_LANGUAGE); public final TrackedValue scaleFactor = this.value(1.0f); public final TrackedValue maxRecentFiles = this.value(10); - public final TrackedValue> recentFiles = this.list(new RecentProject("", "")); + public final TrackedValue> recentProjects = this.list(new RecentProject("", "")); public final TrackedValue serverNotificationLevel = this.value(NotificationManager.ServerNotificationLevel.FULL); public final TrackedValue useCustomFonts = this.value(false); public final TrackedValue windowSize = this.value(ScaleUtil.getDimension(1024, 576)); @@ -54,23 +55,23 @@ public static Config get() { return INSTANCE; } - public static DockerConfig getDockerConfig() { + public static DockerConfig dockers() { return INSTANCE.dockerConfig.value(); } - public static KeyBindsConfig getKeyBindsConfig() { + public static KeyBindsConfig keyBinds() { return INSTANCE.keyBinds.value(); } - public static NetConfig getNetConfig() { + public static NetConfig net() { return INSTANCE.net.value(); } - public static DecompilerConfig getDecompilerConfig() { + public static DecompilerConfig decompiler() { return INSTANCE.decompiler.value(); } - public static Theme getCurrentTheme() { + public static Theme currentTheme() { return switch (INSTANCE.activeLookAndFeel) { case DEFAULT -> INSTANCE.defaultTheme.value(); case DARCULA -> INSTANCE.darculaTheme.value(); @@ -80,24 +81,38 @@ public static Theme getCurrentTheme() { }; } - public static ThemeColors getCurrentColors() { - return getCurrentTheme().colors.value(); + public static ThemeColors currentColors() { + return currentTheme().colors.value(); } - public static ThemeFonts getCurrentFonts() { - return getCurrentTheme().fonts.value(); + public static ThemeFonts currentFonts() { + return currentTheme().fonts.value(); + } + + public static void insertRecentProject(String jarPath, String mappingsPath) { + INSTANCE.recentProjects.value().add(0, new RecentProject(jarPath, mappingsPath)); + } + + public static RecentProject getMostRecentProject() { + return INSTANCE.recentProjects.value().get(0); } public record RecentProject(String jarPath, String mappingsPath) { + public Path getJarPath() { + return Paths.get(this.jarPath); + } + public Path getMappingsPath() { + return Paths.get(this.mappingsPath); + } } /** * Updates the backend library Syntaxpain, used for code highlighting and other editor things. */ - private void updateSyntaxpain() { - ThemeFonts fonts = this.getCurrentTheme().fonts.value(); - ThemeColors colors = this.getCurrentTheme().colors.value(); + private static void updateSyntaxpain() { + ThemeFonts fonts = currentFonts(); + ThemeColors colors = currentColors(); SyntaxpainConfiguration.setEditorFont(fonts.editor.value()); SyntaxpainConfiguration.setQuickFindDialogFactory(EnigmaQuickFindDialog::new); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java index f49088b56..b185d3585 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java @@ -14,15 +14,10 @@ import org.quiltmc.enigma.gui.docker.NotificationsDocker; import org.quiltmc.enigma.gui.docker.ObfuscatedClassesDocker; import org.quiltmc.enigma.gui.docker.StructureDocker; -import org.quiltmc.enigma.util.Pair; -import java.util.HashMap; import java.util.Map; -import java.util.Optional; -import java.util.function.Function; import java.util.stream.Collectors; -// todo use ComplexConfigValue for pairs public class DockerConfig extends ReflectiveConfig.Section { public final TrackedValue leftVerticalDividerLocation = this.value(300); public final TrackedValue rightVerticalDividerLocation = this.value(300); @@ -32,19 +27,19 @@ public class DockerConfig extends ReflectiveConfig.Section { public final TrackedValue> dockerLocations = this.map(new Docker.Location(Docker.Side.LEFT, Docker.VerticalLocation.TOP)).build(); - public Docker.Location getDockerLocation(String id) { - return this.dockerLocations.value().get(id); + public void putLocation(String id, Docker.Location location) { + this.dockerLocations.value().put(id, location); } - public void putDockerLocation(String id, Docker.Location location) { - this.dockerLocations.value().put(id, location); + public void putLocation(Docker docker, Docker.Side side, Docker.VerticalLocation verticalLocation) { + this.putLocation(docker.getId(), new Docker.Location(side, verticalLocation)); } - public void putDockerLocation(Docker docker, Docker.Side side, Docker.VerticalLocation verticalLocation) { - this.putDockerLocation(docker.getId(), new Docker.Location(side, verticalLocation)); + public Docker.Location getLocation(String id) { + return this.dockerLocations.value().get(id); } - public Map getHostedDockers(Docker.Side side) { + public Map getLocations(Docker.Side side) { return this.dockerLocations.value().entrySet().stream().filter((entry) -> entry.getValue().side() == side).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } @@ -76,18 +71,18 @@ public static TrackedValue> getDefaultLocations(Docker DockerConfig defaultConfig = new DockerConfig(); // left - defaultConfig.putDockerLocation(manager.getDocker(ObfuscatedClassesDocker.class), Docker.Side.LEFT, Docker.VerticalLocation.TOP); - defaultConfig.putDockerLocation(manager.getDocker(ClassesDocker.class), Docker.Side.LEFT, Docker.VerticalLocation.TOP); - defaultConfig.putDockerLocation(manager.getDocker(DeobfuscatedClassesDocker.class), Docker.Side.LEFT, Docker.VerticalLocation.BOTTOM); + defaultConfig.putLocation(manager.getDocker(ObfuscatedClassesDocker.class), Docker.Side.LEFT, Docker.VerticalLocation.TOP); + defaultConfig.putLocation(manager.getDocker(ClassesDocker.class), Docker.Side.LEFT, Docker.VerticalLocation.TOP); + defaultConfig.putLocation(manager.getDocker(DeobfuscatedClassesDocker.class), Docker.Side.LEFT, Docker.VerticalLocation.BOTTOM); // right - defaultConfig.putDockerLocation(manager.getDocker(StructureDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); - defaultConfig.putDockerLocation(manager.getDocker(InheritanceTreeDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); - defaultConfig.putDockerLocation(manager.getDocker(ImplementationsTreeDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); - defaultConfig.putDockerLocation(manager.getDocker(CallsTreeDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); + defaultConfig.putLocation(manager.getDocker(StructureDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); + defaultConfig.putLocation(manager.getDocker(InheritanceTreeDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); + defaultConfig.putLocation(manager.getDocker(ImplementationsTreeDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); + defaultConfig.putLocation(manager.getDocker(CallsTreeDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); - defaultConfig.putDockerLocation(manager.getDocker(CollabDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.BOTTOM); - defaultConfig.putDockerLocation(manager.getDocker(NotificationsDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.BOTTOM); + defaultConfig.putLocation(manager.getDocker(CollabDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.BOTTOM); + defaultConfig.putLocation(manager.getDocker(NotificationsDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.BOTTOM); return defaultConfig.dockerLocations; } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/keybind/KeyBinds.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/keybind/KeyBinds.java index 86cac0811..8b8e27eff 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/keybind/KeyBinds.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/keybind/KeyBinds.java @@ -1,7 +1,6 @@ package org.quiltmc.enigma.gui.config.keybind; import org.quiltmc.enigma.gui.config.Config; -import org.quiltmc.enigma.gui.config.KeyBindsConfig; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; @@ -90,7 +89,7 @@ public static Map> getEditableKeyBindsByCategory() { public static void loadConfig() { for (KeyBind keyBind : CONFIGURABLE_KEY_BINDS) { - keyBind.deserializeCombinations(Config.INSTANCE.keyBinds.value().getKeyBindCodes(keyBind)); + keyBind.deserializeCombinations(Config.keyBinds().getKeyBindCodes(keyBind)); } resetEditableKeyBinds(); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java index ff12b2872..ba8965ad0 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java @@ -22,7 +22,7 @@ public class Themes { public static void setupTheme() { LookAndFeel laf = Config.get().lookAndFeel.value(); laf.setGlobalLAF(); - Config.getCurrentColors().configure(LookAndFeel.isDarkLaf()); + Config.currentColors().configure(LookAndFeel.isDarkLaf()); Themes.setFonts(); UIManager.put("ScrollBar.showButtons", true); JEditorPane.registerEditorKitForContentType("text/enigma-sources", JavaSyntaxKit.class.getName()); @@ -32,8 +32,8 @@ public static void setupTheme() { } private static void setFonts() { - Font small = Config.getCurrentFonts().small.value(); - Font bold = Config.getCurrentFonts().defaultFont.value(); + Font small = Config.currentFonts().small.value(); + Font bold = Config.currentFonts().defaultFont.value(); UIManager.put("CheckBox.font", bold); UIManager.put("CheckBoxMenuItem.font", bold); @@ -79,11 +79,11 @@ private static void setFonts() { public static Map getBoxHighlightPainters() { return Map.of( - TokenType.OBFUSCATED, BoxHighlightPainter.create(Config.getCurrentColors().obfuscated.value(), Config.getCurrentColors().obfuscatedOutline.value()), - TokenType.JAR_PROPOSED, BoxHighlightPainter.create(Config.getCurrentColors().proposed.value(), Config.getCurrentColors().proposedOutline.value()), - TokenType.DYNAMIC_PROPOSED, BoxHighlightPainter.create(Config.getCurrentColors().proposed.value(), Config.getCurrentColors().proposedOutline.value()), - TokenType.DEOBFUSCATED, BoxHighlightPainter.create(Config.getCurrentColors().deobfuscated.value(), Config.getCurrentColors().deobfuscatedOutline.value()), - TokenType.DEBUG, BoxHighlightPainter.create(Config.getCurrentColors().debugToken.value(), Config.getCurrentColors().debugTokenOutline.value()) + TokenType.OBFUSCATED, BoxHighlightPainter.create(Config.currentColors().obfuscated.value(), Config.currentColors().obfuscatedOutline.value()), + TokenType.JAR_PROPOSED, BoxHighlightPainter.create(Config.currentColors().proposed.value(), Config.currentColors().proposedOutline.value()), + TokenType.DYNAMIC_PROPOSED, BoxHighlightPainter.create(Config.currentColors().proposed.value(), Config.currentColors().proposedOutline.value()), + TokenType.DEOBFUSCATED, BoxHighlightPainter.create(Config.currentColors().deobfuscated.value(), Config.currentColors().deobfuscatedOutline.value()), + TokenType.DEBUG, BoxHighlightPainter.create(Config.currentColors().debugToken.value(), Config.currentColors().debugTokenOutline.value()) ); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/ConnectToServerDialog.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/ConnectToServerDialog.java index 34fbe65ec..5300fd021 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/ConnectToServerDialog.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/ConnectToServerDialog.java @@ -35,9 +35,9 @@ public ConnectToServerDialog(Frame owner, Gui gui) { @Override protected List> createComponents() { - this.usernameField = new JTextField(Config.INSTANCE.getNetConfig().username.value()); - this.ipField = new JTextField(Config.INSTANCE.getNetConfig().remoteAddress.value()); - this.passwordField = new JPasswordField(Config.INSTANCE.getNetConfig().password.value()); + this.usernameField = new JTextField(Config.INSTANCE.net().username.value()); + this.ipField = new JTextField(Config.INSTANCE.net().remoteAddress.value()); + this.passwordField = new JPasswordField(Config.INSTANCE.net().password.value()); this.usernameField.addActionListener(event -> this.confirm()); this.ipField.addActionListener(event -> this.confirm()); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/CreateServerDialog.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/CreateServerDialog.java index 7bc5cf492..fa95b7db7 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/CreateServerDialog.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/CreateServerDialog.java @@ -32,8 +32,8 @@ public CreateServerDialog(Frame owner, Gui gui) { @Override protected List> createComponents() { - this.portField = new JTextField(Integer.toString(Config.INSTANCE.getNetConfig().serverPort.value())); - this.passwordField = new JPasswordField(Config.INSTANCE.getNetConfig().serverPassword.value()); + this.portField = new JTextField(Integer.toString(Config.INSTANCE.net().serverPort.value())); + this.passwordField = new JPasswordField(Config.INSTANCE.net().serverPassword.value()); this.portField.addActionListener(event -> this.confirm()); this.passwordField.addActionListener(event -> this.confirm()); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java index e06ab286c..afadaf6ef 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java @@ -1,5 +1,6 @@ package org.quiltmc.enigma.gui.dialog; +import org.quiltmc.config.api.values.TrackedValue; import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.util.GridBagConstraintsBuilder; import org.quiltmc.enigma.gui.util.ScaleUtil; @@ -19,10 +20,10 @@ import javax.swing.JList; public class FontDialog extends JDialog { - private static final List FONTS = List.of( - Config.INSTANCE.getCurrentTheme().fonts.value().defaultFont.value(), - Config.INSTANCE.getCurrentTheme().fonts.value().small.value(), - Config.INSTANCE.getCurrentTheme().fonts.value().editor.value() + private static final List> FONTS = List.of( + Config.currentFonts().defaultFont, + Config.currentFonts().small, + Config.currentFonts().editor ); private static final List CATEGORY_TEXTS = List.of( @@ -36,6 +37,7 @@ public class FontDialog extends JDialog { private final JCheckBox customCheckBox = new JCheckBox(I18n.translate("fonts.use_custom")); private final JButton okButton = new JButton(I18n.translate("prompt.ok")); private final JButton cancelButton = new JButton(I18n.translate("prompt.cancel")); + private final Font[] fontValues = new Font[]{FONTS.get(0).value(), FONTS.get(1).value(), FONTS.get(2).value()}; public FontDialog(Frame owner) { super(owner, "Fonts", true); @@ -76,14 +78,14 @@ private void categoryChanged() { this.updateUiState(); int selectedIndex = this.entries.getSelectedIndex(); if (selectedIndex != -1) { - this.chooser.setSelectedFont(this.fonts[selectedIndex]); + this.chooser.setSelectedFont(this.fontValues[selectedIndex]); } } private void selectedFontChanged() { int selectedIndex = this.entries.getSelectedIndex(); if (selectedIndex != -1) { - this.fonts[selectedIndex] = this.chooser.getSelectedFont(); + this.fontValues[selectedIndex] = this.chooser.getSelectedFont(); } } @@ -94,11 +96,10 @@ private void updateUiState() { private void apply() { for (int i = 0; i < FONTS.size(); i++) { - Config.setFont(FONTS.get(i), this.fonts[i]); + FONTS.get(i).setValue(this.fontValues[i], true); } - Config.setUseCustomFonts(this.customCheckBox.isSelected()); - Config.save(); + Config.get().useCustomFonts.setValue(this.customCheckBox.isSelected(), true); ChangeDialog.show(this); this.dispose(); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/JavadocDialog.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/JavadocDialog.java index 420361541..78586aeb8 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/JavadocDialog.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/JavadocDialog.java @@ -65,7 +65,7 @@ private JavadocDialog(JFrame parent, GuiController controller, Entry entry, S this.close(); } })); - this.text.setFont(Config.INSTANCE.getCurrentFonts().editor.value()); + this.text.setFont(Config.INSTANCE.currentFonts().editor.value()); // buttons panel JPanel buttonsPanel = new JPanel(); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Dock.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Dock.java index 53e01f3b9..7ab53c936 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Dock.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Dock.java @@ -19,7 +19,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Optional; /** * Handles the docking of {@link Docker}s. @@ -64,7 +63,7 @@ public Dock(Gui gui, Docker.Side side) { */ public void restoreState(DockerManager manager) { // restore docker state - Map hostedDockers = Config.getDockerConfig().getHostedDockers(this.side); + Map hostedDockers = Config.dockers().getLocations(this.side); hostedDockers.forEach((id, location) -> this.host(manager.getDocker(id), location.verticalLocation())); this.restoreDividerState(true); @@ -74,29 +73,21 @@ public void restoreState(DockerManager manager) { } } - /** - * Saves the state of this dock to the config file. - */ - public void saveState() { - Config.setHostedDockers(this.side, this.getDockers()); - this.saveDividerState(); - } - public void restoreDividerState(boolean init) { // restore vertical divider state if (this.isSplit) { - this.splitPane.setDividerLocation(Config.getDockerConfig().getVerticalDividerLocation(this.side)); + this.splitPane.setDividerLocation(Config.dockers().getVerticalDividerLocation(this.side)); } // restore horizontal divider state JSplitPane parentSplitPane = this.getParentSplitPane(); - int location = Config.getDockerConfig().getHorizontalDividerLocation(this.side); + int location = Config.dockers().getHorizontalDividerLocation(this.side); // hack fix: if the right dock is closed while the left dock is open, the divider location is saved as if the left dock is open, // thereby offsetting the divider location by the width of the left dock. which means, if the right dock is reopened while the left dock is closed, // the divider location is too far to the left by the width of the left dock. so here we offset the location to avoid that. - if (init && this.side == Docker.Side.RIGHT && !this.gui.getSplitLeft().getLeftComponent().isVisible() && Config.getDockerConfig().savedWithLeftDockerOpen.value()) { - location += Config.getDockerConfig().getHorizontalDividerLocation(Docker.Side.LEFT); + if (init && this.side == Docker.Side.RIGHT && !this.gui.getSplitLeft().getLeftComponent().isVisible() && Config.dockers().savedWithLeftDockerOpen.value()) { + location += Config.dockers().getHorizontalDividerLocation(Docker.Side.LEFT); } parentSplitPane.setDividerLocation(location); @@ -106,16 +97,16 @@ public void saveDividerState() { if (this.isVisible()) { // save vertical divider state if (this.isSplit) { - Config.getDockerConfig().setVerticalDividerLocation(this.side, this.splitPane.getDividerLocation()); + Config.dockers().setVerticalDividerLocation(this.side, this.splitPane.getDividerLocation()); } // save horizontal divider state JSplitPane parentSplitPane = this.getParentSplitPane(); - Config.getDockerConfig().setHorizontalDividerLocation(this.side, parentSplitPane.getDividerLocation()); + Config.dockers().setHorizontalDividerLocation(this.side, parentSplitPane.getDividerLocation()); // hack if (this.side == Docker.Side.RIGHT) { - Config.getDockerConfig().savedWithLeftDockerOpen.setValue(this.gui.getSplitLeft().getLeftComponent().isVisible(), true); + Config.dockers().savedWithLeftDockerOpen.setValue(this.gui.getSplitLeft().getLeftComponent().isVisible(), true); } } } @@ -184,7 +175,7 @@ public void host(Docker docker, Docker.VerticalLocation verticalLocation, boolea parent.remove(button); (verticalLocation == Docker.VerticalLocation.TOP ? selector.getTopSelector() : selector.getBottomSelector()).add(button); button.setSide(this.side); - Config.getDockerConfig().putDockerLocation(docker, this.side, verticalLocation); + Config.dockers().putLocation(docker, this.side, verticalLocation); button.getParent().revalidate(); button.getParent().repaint(); @@ -357,7 +348,7 @@ public void paint(Graphics graphics) { if (this.hovered != null) { Rectangle paintedBounds = this.getHighlightBoundsFor(new Point(0, 0), this.hovered); - Color color = Config.getCurrentColors().dockHighlight.value(); + Color color = Config.currentColors().dockHighlight.value(); graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 100)); graphics.fillRect(paintedBounds.x, paintedBounds.y, paintedBounds.width, paintedBounds.height); this.repaint(); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java index 5321ba343..5a7fb21f7 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java @@ -70,7 +70,7 @@ public DockerButton getButton() { * @return the position of the docker's button in the selector panels. this also represents where the docker will open when its button is clicked cannot use {@link Docker.VerticalLocation#FULL} */ public final Location getButtonLocation() { - return Config.getDockerConfig().getDockerLocation(this.getId()); + return Config.dockers().getLocation(this.getId()); } public abstract Location getPreferredButtonLocation(); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/DockerManager.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/DockerManager.java index 1b8279d4b..d1ebc3c77 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/DockerManager.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/DockerManager.java @@ -77,15 +77,6 @@ public void restoreStateFromConfig() { this.rightDock.restoreState(this); } - /** - * Saves the state of both docks to the config file. - * @see Dock#saveState() - */ - public void saveStateToConfig() { - this.leftDock.saveState(); - this.rightDock.saveState(); - } - /** * Registers a new docker to be available in the GUI. * @param docker the docker to be registered diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java index 9de87a22c..e6899e458 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java @@ -121,7 +121,7 @@ public void paint(Graphics g) { // setup text String translatedText = this.textSupplier.get(); - Font font = Config.getCurrentFonts().defaultFont.value(); + Font font = Config.currentFonts().defaultFont.value(); if (Config.get().lookAndFeel.value().equals(LookAndFeel.SYSTEM)) { font = font.deriveFont(Font.BOLD); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerSelector.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerSelector.java index f7bed9f70..31c19b80a 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerSelector.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerSelector.java @@ -97,7 +97,7 @@ private boolean dropButton(DockerButton button, MouseEvent event) { if (hoveredPanel != null) { hoveredPanel.add(button); button.setSide(this.side); - Config.getDockerConfig().putDockerLocation(button.getDocker(), this.side, hoveredPanel.equals(this.bottomSelector) ? Docker.VerticalLocation.BOTTOM : Docker.VerticalLocation.TOP); + Config.dockers().putLocation(button.getDocker(), this.side, hoveredPanel.equals(this.bottomSelector) ? Docker.VerticalLocation.BOTTOM : Docker.VerticalLocation.TOP); return true; } @@ -111,7 +111,7 @@ public void paint(Graphics graphics) { if (this.hovered != null) { Rectangle paintedBounds = this.getScreenBoundsFor(this.hovered); - Color color = Config.getCurrentColors().dockHighlight.value(); + Color color = Config.currentColors().dockHighlight.value(); graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 100)); graphics.fillRect(0, this.hovered.equals(this.bottomSelector) ? paintedBounds.height : 0, paintedBounds.width, paintedBounds.height); this.repaint(); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java index 36608cc7f..86d5bc21d 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java @@ -5,7 +5,6 @@ import org.quiltmc.enigma.gui.NotificationManager; import org.quiltmc.enigma.gui.config.Decompiler; import org.quiltmc.enigma.gui.config.theme.LookAndFeel; -import org.quiltmc.enigma.gui.config.NetConfig; import org.quiltmc.enigma.gui.config.theme.Themes; import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.config.keybind.KeyBinds; @@ -412,13 +411,13 @@ public void onConnectClicked() { this.gui.getController().disconnectIfConnected(null); try { this.gui.getController().createClient(result.username(), result.address().address, result.address().port, result.password()); - if (Config.INSTANCE.serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { + if (Config.get().serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { this.gui.getNotificationManager().notify(new ParameterizedMessage(Message.CONNECTED_TO_SERVER, result.addressStr())); } - Config.INSTANCE.getNetConfig().username.setValue(result.username(), true); - Config.INSTANCE.getNetConfig().remoteAddress.setValue(result.addressStr(), true); - Config.INSTANCE.getNetConfig().password.setValue(String.valueOf(result.password()), true); + Config.net().username.setValue(result.username(), true); + Config.net().remoteAddress.setValue(result.addressStr(), true); + Config.net().password.setValue(String.valueOf(result.password()), true); } catch (IOException e) { JOptionPane.showMessageDialog(this.gui.getFrame(), e.toString(), I18n.translate("menu.collab.connect.error"), JOptionPane.ERROR_MESSAGE); this.gui.getController().disconnectIfConnected(null); @@ -445,8 +444,8 @@ public void onStartServerClicked() { this.gui.getNotificationManager().notify(new ParameterizedMessage(Message.SERVER_STARTED, result.port())); } - Config.INSTANCE.getNetConfig().serverPort.setValue(result.port(), true); - Config.INSTANCE.getNetConfig().serverPassword.setValue(String.valueOf(result.password()), true); + Config.net().serverPort.setValue(result.port(), true); + Config.net().serverPassword.setValue(String.valueOf(result.password()), true); } catch (IOException e) { JOptionPane.showMessageDialog(this.gui.getFrame(), e.toString(), I18n.translate("menu.collab.server.start.error"), JOptionPane.ERROR_MESSAGE); this.gui.getController().disconnectIfConnected(null); @@ -475,14 +474,14 @@ private void onOpenMappingsClicked() { public void reloadOpenRecentMenu(Gui gui) { this.openRecentMenu.removeAll(); - List> recentFilePairs = Config.getRecentFilePairs(); + List recentFilePairs = Config.get().recentProjects.value(); // find the longest common prefix among all mappings files // this is to clear the "/home/user/wherever-you-store-your-mappings-projects/" part of the path and only show relevant information Path prefix = null; if (recentFilePairs.size() > 1) { - List recentFiles = recentFilePairs.stream().map(Pair::b).sorted().toList(); + List recentFiles = recentFilePairs.stream().map(Config.RecentProject::getMappingsPath).sorted().toList(); prefix = recentFiles.get(0); for (int i = 1; i < recentFiles.size(); i++) { @@ -494,23 +493,23 @@ public void reloadOpenRecentMenu(Gui gui) { } } - for (Pair recent : recentFilePairs) { - if (!Files.exists(recent.a()) || !Files.exists(recent.b())) { + for (Config.RecentProject recent : recentFilePairs) { + if (!Files.exists(recent.getJarPath()) || !Files.exists(recent.getMappingsPath())) { continue; } - String jarName = recent.a().getFileName().toString(); + String jarName = recent.getJarPath().getFileName().toString(); // if there's no common prefix, just show the last directory in the tree String mappingsName; if (prefix != null) { - mappingsName = prefix.relativize(recent.b()).toString(); + mappingsName = prefix.relativize(recent.getMappingsPath()).toString(); } else { - mappingsName = recent.b().getFileName().toString(); + mappingsName = recent.getMappingsPath().getFileName().toString(); } JMenuItem item = new JMenuItem(jarName + " -> " + mappingsName); - item.addActionListener(event -> gui.getController().openJar(recent.a()).whenComplete((v, t) -> gui.getController().openMappings(recent.b()))); + item.addActionListener(event -> gui.getController().openJar(recent.getJarPath()).whenComplete((v, t) -> gui.getController().openMappings(recent.getMappingsPath()))); this.openRecentMenu.add(item); } } @@ -560,14 +559,14 @@ private static void prepareDecompilerMenu(JMenu decompilerMenu, JMenuItem decomp for (Decompiler decompiler : Decompiler.values()) { JRadioButtonMenuItem decompilerButton = new JRadioButtonMenuItem(decompiler.name); decompilerGroup.add(decompilerButton); - if (decompiler.equals(Config.getDecompilerConfig().decompiler.value())) { + if (decompiler.equals(Config.decompiler().decompiler.value())) { decompilerButton.setSelected(true); } decompilerButton.addActionListener(event -> { gui.getController().setDecompiler(decompiler.service); - Config.getDecompilerConfig().decompiler.setValue(decompiler, true); + Config.decompiler().decompiler.setValue(decompiler, true); }); decompilerMenu.add(decompilerButton); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/highlight/SelectionHighlightPainter.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/highlight/SelectionHighlightPainter.java index b5c9103a0..985f294a2 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/highlight/SelectionHighlightPainter.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/highlight/SelectionHighlightPainter.java @@ -18,7 +18,7 @@ public void paint(Graphics g, int start, int end, Shape shape, JTextComponent te // draw a thick border Graphics2D g2d = (Graphics2D) g; Rectangle bounds = BoxHighlightPainter.getBounds(text, start, end); - g2d.setColor(Config.getCurrentColors().selectionHighlight.value()); + g2d.setColor(Config.currentColors().selectionHighlight.value()); g2d.setStroke(new BasicStroke(2.0f)); g2d.drawRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/panel/EditorPanel.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/panel/EditorPanel.java index 0f7f12ea5..8acaa3533 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/panel/EditorPanel.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/panel/EditorPanel.java @@ -120,9 +120,9 @@ public EditorPanel(Gui gui, NavigatorPanel navigator) { this.editor.setCaret(new BrowserCaret()); this.editor.setFont(ScaleUtil.getFont(this.editor.getFont().getFontName(), Font.PLAIN, this.fontSize)); this.editor.addCaretListener(event -> this.onCaretMove(event.getDot(), this.mouseIsPressed)); - this.editor.setCaretColor(Config.INSTANCE.getCurrentColors().caret.value()); + this.editor.setCaretColor(Config.INSTANCE.currentColors().caret.value()); this.editor.setContentType("text/enigma-sources"); - this.editor.setBackground(Config.INSTANCE.getCurrentColors().editorBackground.value()); + this.editor.setBackground(Config.INSTANCE.currentColors().editorBackground.value()); // set unit increment to height of one line, the amount scrolled per // mouse wheel rotation is then controlled by OS settings @@ -213,7 +213,7 @@ public void keyReleased(KeyEvent event) { this.themeChangeListener = (laf, boxHighlightPainters) -> { if ((this.editorLaf == null || this.editorLaf != laf)) { this.editor.updateUI(); - this.editor.setBackground(Config.INSTANCE.getCurrentColors().editorBackground.value()); + this.editor.setBackground(Config.INSTANCE.currentColors().editorBackground.value()); if (this.editorLaf != null) { this.classHandle.invalidateMapped(); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/CallsTreeCellRenderer.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/CallsTreeCellRenderer.java index 5c2e40ece..613eef46f 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/CallsTreeCellRenderer.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/CallsTreeCellRenderer.java @@ -26,7 +26,7 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean Component c = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); EntryReference reference = ((ReferenceTreeNode) value).getReference(); - this.setForeground(Config.INSTANCE.getCurrentColors().text.value()); + this.setForeground(Config.INSTANCE.currentColors().text.value()); // if the node represents the method calling the entry if (reference != null) { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/ImplementationsTreeCellRenderer.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/ImplementationsTreeCellRenderer.java index 223b69595..50c69e09d 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/ImplementationsTreeCellRenderer.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/ImplementationsTreeCellRenderer.java @@ -21,7 +21,7 @@ public ImplementationsTreeCellRenderer(Gui gui) { public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { Component c = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); - this.setForeground(Config.getCurrentColors().text.value()); + this.setForeground(Config.currentColors().text.value()); if (value instanceof ClassImplementationsTreeNode node) { this.setIcon(GuiUtil.getClassIcon(this.gui, node.getClassEntry())); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/InheritanceTreeCellRenderer.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/InheritanceTreeCellRenderer.java index e48d08c2d..a57e2d90e 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/InheritanceTreeCellRenderer.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/InheritanceTreeCellRenderer.java @@ -23,7 +23,7 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean Component ret = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); if (!(value instanceof MethodInheritanceTreeNode node) || node.isImplemented()) { - ret.setForeground(Config.getCurrentColors().text.value()); + ret.setForeground(Config.currentColors().text.value()); ret.setFont(ret.getFont().deriveFont(Font.PLAIN)); if (value instanceof ClassInheritanceTreeNode) { this.setIcon(GuiUtil.getClassIcon(this.gui, ((ClassInheritanceTreeNode) value).getClassEntry())); @@ -31,7 +31,7 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean this.setIcon(GuiUtil.getMethodIcon(((MethodInheritanceTreeNode) value).getMethodEntry())); } } else { - ret.setForeground(Config.getCurrentColors().number.value()); + ret.setForeground(Config.currentColors().number.value()); ret.setFont(ret.getFont().deriveFont(Font.ITALIC)); this.setIcon(GuiUtil.CLASS_ICON); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java index b0104ea0f..f8e51262a 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java @@ -25,9 +25,9 @@ public static void setScaleFactor(float scaleFactor) { float oldScale = Config.INSTANCE.scaleFactor.value(); float clamped = Math.min(Math.max(0.25f, scaleFactor), 10.0f); Config.INSTANCE.scaleFactor.setValue(clamped, true); - rescaleFontInConfig(Config.INSTANCE.getCurrentFonts().defaultFont, oldScale); - rescaleFontInConfig(Config.INSTANCE.getCurrentFonts().small, oldScale); - rescaleFontInConfig(Config.INSTANCE.getCurrentFonts().editor, oldScale); + rescaleFontInConfig(Config.INSTANCE.currentFonts().defaultFont, oldScale); + rescaleFontInConfig(Config.INSTANCE.currentFonts().small, oldScale); + rescaleFontInConfig(Config.INSTANCE.currentFonts().editor, oldScale); listeners.forEach(l -> l.onScaleChanged(clamped, oldScale)); } @@ -92,7 +92,7 @@ public static void applyScaling() { UiDefaultsScaler.updateAndApplyGlobalScaling((int) (100 * scale), true); } - Font font = Config.INSTANCE.getCurrentFonts().editor.value(); + Font font = Config.INSTANCE.currentFonts().editor.value(); font = font.deriveFont((float) (12 * scale)); SyntaxpainConfiguration.setEditorFont(font); } From d60a4e0ffcbb2c3018ff7aa880383d88b951c3e7 Mon Sep 17 00:00:00 2001 From: ix0rai Date: Sun, 26 Nov 2023 16:35:03 -0600 Subject: [PATCH 07/25] progress 2! --- enigma-swing/build.gradle | 1 + .../main/java/org/quiltmc/enigma/gui/Gui.java | 6 +- .../org/quiltmc/enigma/gui/GuiController.java | 8 +- .../java/org/quiltmc/enigma/gui/Main.java | 4 +- .../org/quiltmc/enigma/gui/config/Config.java | 30 +++- .../enigma/gui/config/ConfigPaths.java | 39 +++++ .../gui/config/NightConfigSerializer.java | 147 ++++++++++++++++++ .../enigma/gui/config/keybind/KeyBinds.java | 4 +- .../enigma/gui/config/theme/LookAndFeel.java | 2 +- .../gui/dialog/ConnectToServerDialog.java | 6 +- .../enigma/gui/dialog/CreateServerDialog.java | 4 +- .../quiltmc/enigma/gui/dialog/FontDialog.java | 14 +- .../enigma/gui/dialog/JavadocDialog.java | 2 +- .../enigma/gui/dialog/StatsDialog.java | 14 +- .../quiltmc/enigma/gui/element/MenuBar.java | 26 ++-- .../quiltmc/enigma/gui/panel/EditorPanel.java | 6 +- .../gui/renderer/CallsTreeCellRenderer.java | 2 +- .../quiltmc/enigma/gui/util/ScaleUtil.java | 28 ++-- gradle/libs.versions.toml | 4 + 19 files changed, 282 insertions(+), 65 deletions(-) create mode 100644 enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/ConfigPaths.java create mode 100644 enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NightConfigSerializer.java diff --git a/enigma-swing/build.gradle b/enigma-swing/build.gradle index 62f4a2441..a976c0b5a 100644 --- a/enigma-swing/build.gradle +++ b/enigma-swing/build.gradle @@ -16,6 +16,7 @@ dependencies { implementation libs.quilt.config implementation libs.swing.dpi implementation libs.fontchooser + implementation libs.bundles.night.config testImplementation(testFixtures(project(':enigma'))) } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java index ed5cfd4f5..455236eea 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java @@ -614,17 +614,17 @@ public void addMessage(ServerMessage message) { // popup notifications switch (message.getType()) { case CHAT -> { - if (Config.INSTANCE.serverNotificationLevel.value() == NotificationManager.ServerNotificationLevel.FULL && !message.user.equals(Config.INSTANCE.net.value().username.value())) { + if (Config.get().serverNotificationLevel.value() == NotificationManager.ServerNotificationLevel.FULL && !message.user.equals(Config.get().net.value().username.value())) { this.notificationManager.notify(new ParameterizedMessage(Message.MULTIPLAYER_CHAT, message.translate())); } } case CONNECT -> { - if (Config.INSTANCE.serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { + if (Config.get().serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { this.notificationManager.notify(new ParameterizedMessage(Message.MULTIPLAYER_USER_CONNECTED, message.translate())); } } case DISCONNECT -> { - if (Config.INSTANCE.serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { + if (Config.get().serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { this.notificationManager.notify(new ParameterizedMessage(Message.MULTIPLAYER_USER_LEFT, message.translate())); } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java index 214f8df11..a36bfcb9d 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java @@ -124,7 +124,7 @@ public CompletableFuture openJar(final Path jarPath) { return ProgressDialog.runOffThread(this.gui, progress -> { this.project = this.enigma.openJar(jarPath, new ClasspathClassProvider(), progress); this.indexTreeBuilder = new IndexTreeBuilder(this.project.getJarIndex()); - this.chp = new ClassHandleProvider(this.project, Config.INSTANCE.decompiler.value().decompiler.value().service); + this.chp = new ClassHandleProvider(this.project, Config.decompiler().decompiler.value().service); this.statsGenerator = new StatsGenerator(this.project); SwingUtilities.invokeLater(() -> { @@ -556,7 +556,7 @@ private void applyChange0(ValidationContext vc, EntryChange change, boolean u public void openStatsTree(Set includedTypes) { ProgressDialog.runOffThread(this.gui, progress -> { StatsResult overall = this.getStatsGenerator().getResultNullable().getOverall(); - StatsTree tree = overall.buildTree(Config.INSTANCE.lastTopLevelPackage.value(), includedTypes); + StatsTree tree = overall.buildTree(Config.get().lastTopLevelPackage.value(), includedTypes); String treeJson = GSON.toJson(tree.root); try { @@ -618,7 +618,7 @@ public void createServer(int port, char[] password) throws IOException { this.server.start(); this.client = new EnigmaClient(this, "127.0.0.1", port); this.client.connect(); - this.client.sendPacket(new LoginC2SPacket(this.project.getJarChecksum(), password, Config.INSTANCE.net().username.value())); + this.client.sendPacket(new LoginC2SPacket(this.project.getJarChecksum(), password, Config.net().username.value())); this.gui.setConnectionState(ConnectionState.HOSTING); } @@ -647,7 +647,7 @@ public synchronized void disconnectIfConnected(String reason) { }); this.gui.setUserList(new ArrayList<>()); - if (Config.INSTANCE.serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { + if (Config.get().serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { this.gui.getNotificationManager().notify(new ParameterizedMessage(Message.LEFT_SERVER)); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java index 1811b9af3..0a95bf7ce 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java @@ -96,7 +96,7 @@ public static void main(String[] args) throws IOException { EnigmaProfile parsedProfile = EnigmaProfile.read(options.valueOf(profile)); - I18n.setLanguage(Config.INSTANCE.language.value()); + I18n.setLanguage(Config.get().language.value()); setDefaultSystemProperty("apple.laf.useScreenMenuBar", "true"); setDefaultSystemProperty("awt.useSystemAAFontSettings", "on"); setDefaultSystemProperty("swing.aatext", "true"); @@ -131,7 +131,7 @@ public static void main(String[] args) throws IOException { gui.getNotificationManager().notify(ParameterizedMessage.openedProject(jarPath.toString(), mappingsPath.toString())); } else { // search for mappings that are associated with the jar - for (Config.RecentProject recentProject : Config.INSTANCE.recentProjects.value()) { + for (Config.RecentProject recentProject : Config.get().recentProjects.value()) { if (recentProject.getJarPath().equals(jarPath)) { gui.getNotificationManager().notify(ParameterizedMessage.openedProject(recentProject.jarPath(), recentProject.mappingsPath())); gui.getController().openMappings(recentProject.getMappingsPath()); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java index f154a6fd9..ff060bf30 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java @@ -1,8 +1,15 @@ package org.quiltmc.enigma.gui.config; +import com.electronwill.nightconfig.toml.TomlParser; +import com.electronwill.nightconfig.toml.TomlWriter; import org.quiltmc.config.api.ReflectiveConfig; +import org.quiltmc.config.api.values.ComplexConfigValue; +import org.quiltmc.config.api.values.ConfigSerializableObject; import org.quiltmc.config.api.values.TrackedValue; import org.quiltmc.config.api.values.ValueList; +import org.quiltmc.config.api.values.ValueMap; +import org.quiltmc.config.implementor_api.ConfigEnvironment; +import org.quiltmc.config.implementor_api.ConfigFactory; import org.quiltmc.enigma.gui.NotificationManager; import org.quiltmc.enigma.gui.config.theme.LookAndFeel; import org.quiltmc.enigma.gui.config.theme.Theme; @@ -19,7 +26,8 @@ import java.nio.file.Paths; public final class Config extends ReflectiveConfig { - public static final Config INSTANCE = new Config(); + private static final ConfigEnvironment ENVIRONMENT = new ConfigEnvironment(ConfigPaths.getConfigPathRoot(), "toml", new NightConfigSerializer<>("toml", new TomlParser(), new TomlWriter())); + private static final Config INSTANCE = ConfigFactory.create(ENVIRONMENT, "enigma", "main", Config.class); public Config() { updateSyntaxpain(); @@ -97,7 +105,7 @@ public static RecentProject getMostRecentProject() { return INSTANCE.recentProjects.value().get(0); } - public record RecentProject(String jarPath, String mappingsPath) { + public record RecentProject(String jarPath, String mappingsPath) implements ConfigSerializableObject> { public Path getJarPath() { return Paths.get(this.jarPath); } @@ -105,6 +113,24 @@ public Path getJarPath() { public Path getMappingsPath() { return Paths.get(this.mappingsPath); } + + @Override + public RecentProject convertFrom(ValueMap representation) { + return new RecentProject(representation.get("jarPath"), representation.get("mappingsPath")); + } + + @Override + public ValueMap getRepresentation() { + return ValueMap.builder("") + .put("jarPath", this.jarPath) + .put("mappingsPath", this.mappingsPath) + .build(); + } + + @Override + public ComplexConfigValue copy() { + return this; + } } /** diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/ConfigPaths.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/ConfigPaths.java new file mode 100644 index 000000000..22c12919f --- /dev/null +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/ConfigPaths.java @@ -0,0 +1,39 @@ +package org.quiltmc.enigma.gui.config; + +import org.quiltmc.enigma.util.Os; + +import java.nio.file.Path; +import java.nio.file.Paths; + +public class ConfigPaths { + public static Path getConfigPathRoot() { + switch (Os.getOs()) { + case LINUX -> { + String configHome = System.getenv("XDG_CONFIG_HOME"); + if (configHome == null) { + return getUserHomeUnix().resolve(".config"); + } + + return Paths.get(configHome); + } + case MAC -> { + return getUserHomeUnix().resolve("Library").resolve("Application Support"); + } + case WINDOWS -> { + return Paths.get(System.getenv("LOCALAPPDATA")); + } + default -> { + return Paths.get(System.getProperty("user.dir")); + } + } + } + + private static Path getUserHomeUnix() { + String userHome = System.getenv("HOME"); + if (userHome == null) { + userHome = System.getProperty("user.dir"); + } + + return Paths.get(userHome); + } +} diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NightConfigSerializer.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NightConfigSerializer.java new file mode 100644 index 000000000..fd3b31e57 --- /dev/null +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NightConfigSerializer.java @@ -0,0 +1,147 @@ +package org.quiltmc.enigma.gui.config; + +import com.electronwill.nightconfig.core.CommentedConfig; +import com.electronwill.nightconfig.core.InMemoryCommentedFormat; +import com.electronwill.nightconfig.core.UnmodifiableCommentedConfig; +import com.electronwill.nightconfig.core.io.ConfigParser; +import com.electronwill.nightconfig.core.io.ConfigWriter; +import org.quiltmc.config.api.Config; +import org.quiltmc.config.api.Constraint; +import org.quiltmc.config.api.MarshallingUtils; +import org.quiltmc.config.api.Serializer; +import org.quiltmc.config.api.annotations.Comment; +import org.quiltmc.config.api.values.CompoundConfigValue; +import org.quiltmc.config.api.values.ConfigSerializableObject; +import org.quiltmc.config.api.values.TrackedValue; +import org.quiltmc.config.api.values.ValueList; +import org.quiltmc.config.api.values.ValueMap; +import org.quiltmc.config.api.values.ValueTreeNode; + +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public final class NightConfigSerializer implements Serializer { + private final String fileExtension; + private final ConfigParser parser; + private final ConfigWriter writer; + + public NightConfigSerializer(String fileExtension, ConfigParser parser, ConfigWriter writer) { + this.fileExtension = fileExtension; + this.parser = parser; + this.writer = writer; + } + + @Override + public String getFileExtension() { + return this.fileExtension; + } + + @Override + public void serialize(Config config, OutputStream to) { + this.writer.write(write(createCommentedConfig(), config.nodes()), to); + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + @Override + public void deserialize(Config config, InputStream from) { + CommentedConfig read = this.parser.parse(from); + + for (TrackedValue trackedValue : config.values()) { + if (read.contains(trackedValue.key().toString())) { + ((TrackedValue) trackedValue).setValue(MarshallingUtils.coerce(read.get(trackedValue.key().toString()), trackedValue.getDefaultValue(), (CommentedConfig c, MarshallingUtils.MapEntryConsumer entryConsumer) -> + c.entrySet().forEach(e -> entryConsumer.put(e.getKey(), e.getValue()))), false); + } + } + } + + private static List convertList(List list) { + List result = new ArrayList<>(list.size()); + + for (Object value : list) { + result.add(convertAny(value)); + } + + return result; + } + + private static UnmodifiableCommentedConfig convertMap(ValueMap map) { + CommentedConfig result = createCommentedConfig(); + + for (Map.Entry entry : map.entrySet()) { + result.add(entry.getKey(), convertAny(entry.getValue())); + } + + return result; + } + + private static Object convertAny(Object value) { + if (value instanceof ValueMap) { + return convertMap((ValueMap) value); + } else if (value instanceof ValueList) { + return convertList((ValueList) value); + } else if (value instanceof ConfigSerializableObject) { + return convertAny(((ConfigSerializableObject) value).getRepresentation()); + } else { + return value; + } + } + + private static CommentedConfig write(CommentedConfig config, Iterable nodes) { + for (ValueTreeNode node : nodes) { + List comments = new ArrayList<>(); + + if (node.hasMetadata(Comment.TYPE)) { + for (String string : node.metadata(Comment.TYPE)) { + comments.add(string); + } + } + + if (node instanceof TrackedValue trackedValue) { + Object defaultValue = trackedValue.getDefaultValue(); + + if (defaultValue.getClass().isEnum()) { + StringBuilder options = new StringBuilder("options: "); + Object[] enumConstants = defaultValue.getClass().getEnumConstants(); + + for (int i = 0, enumConstantsLength = enumConstants.length; i < enumConstantsLength; i++) { + Object o = enumConstants[i]; + + options.append(o); + + if (i < enumConstantsLength - 1) { + options.append(", "); + } + } + + comments.add(options.toString()); + } + + for (Constraint constraint : trackedValue.constraints()) { + comments.add(constraint.getRepresentation()); + } + + if (!(defaultValue instanceof CompoundConfigValue)) { + comments.add("default: " + defaultValue); + } + + config.add(trackedValue.key().toString(), convertAny(trackedValue.getRealValue())); + } else { + write(config, ((ValueTreeNode.Section) node)); + } + + if (!comments.isEmpty()) { + config.setComment(node.key().toString(), " " + String.join("\n ", comments)); + } + } + + return config; + } + + private static CommentedConfig createCommentedConfig() { + return InMemoryCommentedFormat.defaultInstance().createConfig(LinkedHashMap::new); + } +} diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/keybind/KeyBinds.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/keybind/KeyBinds.java index 8b8e27eff..47765fcf9 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/keybind/KeyBinds.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/keybind/KeyBinds.java @@ -101,7 +101,7 @@ public static void saveConfig() { KeyBind editedKeyBind = editableKeyBinds.get(i); if (!editedKeyBind.equals(keyBind)) { keyBind.setFrom(editedKeyBind); - Config.INSTANCE.keyBinds.value().setKeyBind(editedKeyBind); + Config.keyBinds().setKeyBind(editedKeyBind); } } } @@ -114,7 +114,7 @@ public static void resetEditableKeyBinds() { public static void resetToDefault(KeyBind keyBind) { // Ensure the key bind is editable - if (!editableKeyBinds.contains(keyBind)) { + if (!getEditableKeyBinds().contains(keyBind)) { return; } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/LookAndFeel.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/LookAndFeel.java index 4ce60352a..76ce8fff1 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/LookAndFeel.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/LookAndFeel.java @@ -36,7 +36,7 @@ public boolean needsScaling() { public void setGlobalLAF() { // Configure FlatLaf's UI scale to be our scale factor. // This is also used for the SVG icons, so it applies even when some other LaF is active. - System.setProperty(FlatSystemProperties.UI_SCALE, Float.toString(Config.INSTANCE.scaleFactor.value())); + System.setProperty(FlatSystemProperties.UI_SCALE, Float.toString(Config.get().scaleFactor.value())); try { switch (this) { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/ConnectToServerDialog.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/ConnectToServerDialog.java index 5300fd021..257982d43 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/ConnectToServerDialog.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/ConnectToServerDialog.java @@ -35,9 +35,9 @@ public ConnectToServerDialog(Frame owner, Gui gui) { @Override protected List> createComponents() { - this.usernameField = new JTextField(Config.INSTANCE.net().username.value()); - this.ipField = new JTextField(Config.INSTANCE.net().remoteAddress.value()); - this.passwordField = new JPasswordField(Config.INSTANCE.net().password.value()); + this.usernameField = new JTextField(Config.net().username.value()); + this.ipField = new JTextField(Config.net().remoteAddress.value()); + this.passwordField = new JPasswordField(Config.net().password.value()); this.usernameField.addActionListener(event -> this.confirm()); this.ipField.addActionListener(event -> this.confirm()); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/CreateServerDialog.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/CreateServerDialog.java index fa95b7db7..ffd9f2441 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/CreateServerDialog.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/CreateServerDialog.java @@ -32,8 +32,8 @@ public CreateServerDialog(Frame owner, Gui gui) { @Override protected List> createComponents() { - this.portField = new JTextField(Integer.toString(Config.INSTANCE.net().serverPort.value())); - this.passwordField = new JPasswordField(Config.INSTANCE.net().serverPassword.value()); + this.portField = new JTextField(Integer.toString(Config.net().serverPort.value())); + this.passwordField = new JPasswordField(Config.net().serverPassword.value()); this.portField.addActionListener(event -> this.confirm()); this.passwordField.addActionListener(event -> this.confirm()); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java index afadaf6ef..b8b283a64 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java @@ -35,22 +35,22 @@ public class FontDialog extends JDialog { private final JList entries = new JList<>(CATEGORY_TEXTS.stream().map(I18n::translate).toArray(String[]::new)); private final FontChooser chooser = new FontChooser(Font.decode(Font.DIALOG)); private final JCheckBox customCheckBox = new JCheckBox(I18n.translate("fonts.use_custom")); - private final JButton okButton = new JButton(I18n.translate("prompt.ok")); - private final JButton cancelButton = new JButton(I18n.translate("prompt.cancel")); private final Font[] fontValues = new Font[]{FONTS.get(0).value(), FONTS.get(1).value(), FONTS.get(2).value()}; public FontDialog(Frame owner) { super(owner, "Fonts", true); - this.customCheckBox.setSelected(Config.INSTANCE.useCustomFonts.value()); + this.customCheckBox.setSelected(Config.get().useCustomFonts.value()); this.entries.setPreferredSize(ScaleUtil.getDimension(100, 0)); this.entries.addListSelectionListener(e -> this.categoryChanged()); this.chooser.addChangeListener(e -> this.selectedFontChanged()); this.customCheckBox.addActionListener(e -> this.customFontsClicked()); - this.okButton.addActionListener(e -> this.apply()); - this.cancelButton.addActionListener(e -> this.cancel()); + JButton okButton = new JButton(I18n.translate("prompt.ok")); + okButton.addActionListener(e -> this.apply()); + JButton cancelButton = new JButton(I18n.translate("prompt.cancel")); + cancelButton.addActionListener(e -> this.cancel()); Container contentPane = this.getContentPane(); contentPane.setLayout(new GridBagLayout()); @@ -61,8 +61,8 @@ public FontDialog(Frame owner) { contentPane.add(this.entries, cb.pos(0, 0).weight(0.0, 1.0).fill(GridBagConstraints.BOTH).build()); contentPane.add(this.chooser, cb.pos(1, 0).weight(1.0, 1.0).fill(GridBagConstraints.BOTH).size(2, 1).build()); contentPane.add(this.customCheckBox, cb.pos(0, 1).anchor(GridBagConstraints.WEST).size(2, 1).build()); - contentPane.add(this.okButton, cb.pos(1, 1).anchor(GridBagConstraints.EAST).weight(1.0, 0.0).build()); - contentPane.add(this.cancelButton, cb.pos(2, 1).anchor(GridBagConstraints.EAST).weight(0.0, 0.0).build()); + contentPane.add(okButton, cb.pos(1, 1).anchor(GridBagConstraints.EAST).weight(1.0, 0.0).build()); + contentPane.add(cancelButton, cb.pos(2, 1).anchor(GridBagConstraints.EAST).weight(0.0, 0.0).build()); this.updateUiState(); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/JavadocDialog.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/JavadocDialog.java index 78586aeb8..595f2e376 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/JavadocDialog.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/JavadocDialog.java @@ -65,7 +65,7 @@ private JavadocDialog(JFrame parent, GuiController controller, Entry entry, S this.close(); } })); - this.text.setFont(Config.INSTANCE.currentFonts().editor.value()); + this.text.setFont(Config.currentFonts().editor.value()); // buttons panel JPanel buttonsPanel = new JPanel(); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/StatsDialog.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/StatsDialog.java index 19ac0cab4..6e61ee25e 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/StatsDialog.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/StatsDialog.java @@ -65,12 +65,12 @@ public static void show(Gui gui, ProjectStatsResult result, String packageName) contentPane.add(topLevelPackageOption, cb1.pos(0, result.getOverall().getTypes().size() + 1).build()); JTextField topLevelPackage = new JTextField(); - topLevelPackage.setText(Config.INSTANCE.lastTopLevelPackage.value()); + topLevelPackage.setText(Config.get().lastTopLevelPackage.value()); contentPane.add(topLevelPackage, cb1.pos(0, result.getOverall().getTypes().size() + 2).fill(GridBagConstraints.HORIZONTAL).build()); // show synthetic members option JCheckBox syntheticParametersOption = new JCheckBox(I18n.translate("menu.file.stats.synthetic_parameters")); - syntheticParametersOption.setSelected(Config.INSTANCE.shouldIncludeSyntheticParameters.value()); + syntheticParametersOption.setSelected(Config.get().shouldIncludeSyntheticParameters.value()); contentPane.add(syntheticParametersOption, cb1.pos(0, result.getOverall().getTypes().size() + 4).build()); // show filter button @@ -78,10 +78,10 @@ public static void show(Gui gui, ProjectStatsResult result, String packageName) filterButton.addActionListener(action -> { dialog.dispose(); ProgressDialog.runOffThread(gui, listener -> { - Config.INSTANCE.lastTopLevelPackage.setValue(topLevelPackage.getText(), true); + Config.get().lastTopLevelPackage.setValue(topLevelPackage.getText(), true); - ProjectStatsResult projectResult = gui.getController().getStatsGenerator().getResult(syntheticParametersOption.isSelected()).filter(Config.INSTANCE.lastTopLevelPackage.value()); - SwingUtilities.invokeLater(() -> show(gui, projectResult, Config.INSTANCE.lastTopLevelPackage.value())); + ProjectStatsResult projectResult = gui.getController().getStatsGenerator().getResult(syntheticParametersOption.isSelected()).filter(Config.get().lastTopLevelPackage.value()); + SwingUtilities.invokeLater(() -> show(gui, projectResult, Config.get().lastTopLevelPackage.value())); }); }); contentPane.add(filterButton, cb1.pos(0, result.getOverall().getTypes().size() + 3).anchor(GridBagConstraints.EAST).build()); @@ -92,8 +92,8 @@ public static void show(Gui gui, ProjectStatsResult result, String packageName) button.addActionListener(action -> { dialog.dispose(); - Config.INSTANCE.lastTopLevelPackage.setValue(topLevelPackage.getText(), true); - Config.INSTANCE.shouldIncludeSyntheticParameters.setValue(syntheticParametersOption.isSelected(), true); + Config.get().lastTopLevelPackage.setValue(topLevelPackage.getText(), true); + Config.get().shouldIncludeSyntheticParameters.setValue(syntheticParametersOption.isSelected(), true); generateStats(gui, checkboxes); }); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java index 86d5bc21d..713f0f856 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java @@ -274,7 +274,7 @@ public void retranslateUi() { private void onOpenJarClicked() { JFileChooser d = this.gui.jarFileChooser; - d.setCurrentDirectory(new File(Config.INSTANCE.lastSelectedDir.value())); + d.setCurrentDirectory(new File(Config.get().lastSelectedDir.value())); d.setVisible(true); int result = d.showOpenDialog(this.gui.getFrame()); @@ -291,12 +291,12 @@ private void onOpenJarClicked() { this.gui.getController().openJar(path); } - Config.INSTANCE.lastSelectedDir.setValue(d.getCurrentDirectory().getAbsolutePath(), true); + Config.get().lastSelectedDir.setValue(d.getCurrentDirectory().getAbsolutePath(), true); } } private void onMaxRecentFilesClicked() { - String input = JOptionPane.showInputDialog(this.gui.getFrame(), I18n.translate("menu.file.dialog.max_recent_projects.set"), Config.INSTANCE.maxRecentFiles.value()); + String input = JOptionPane.showInputDialog(this.gui.getFrame(), I18n.translate("menu.file.dialog.max_recent_projects.set"), Config.get().maxRecentFiles.value()); if (input != null) { try { @@ -305,7 +305,7 @@ private void onMaxRecentFilesClicked() { throw new NumberFormatException(); } - Config.INSTANCE.maxRecentFiles.setValue(max, true); + Config.get().maxRecentFiles.setValue(max, true); } catch (NumberFormatException e) { JOptionPane.showMessageDialog(this.gui.getFrame(), I18n.translate("prompt.invalid_input"), I18n.translate("prompt.error"), JOptionPane.ERROR_MESSAGE); } @@ -345,15 +345,15 @@ private void onReloadAllClicked() { } private void onExportSourceClicked() { - this.gui.exportSourceFileChooser.setCurrentDirectory(new File(Config.INSTANCE.lastSelectedDir.value())); + this.gui.exportSourceFileChooser.setCurrentDirectory(new File(Config.get().lastSelectedDir.value())); if (this.gui.exportSourceFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { - Config.INSTANCE.lastSelectedDir.setValue(this.gui.exportSourceFileChooser.getCurrentDirectory().toString(), true); + Config.get().lastSelectedDir.setValue(this.gui.exportSourceFileChooser.getCurrentDirectory().toString(), true); this.gui.getController().exportSource(this.gui.exportSourceFileChooser.getSelectedFile().toPath()); } } private void onExportJarClicked() { - this.gui.exportJarFileChooser.setCurrentDirectory(new File(Config.INSTANCE.lastSelectedDir.value())); + this.gui.exportJarFileChooser.setCurrentDirectory(new File(Config.get().lastSelectedDir.value())); this.gui.exportJarFileChooser.setVisible(true); int result = this.gui.exportJarFileChooser.showSaveDialog(this.gui.getFrame()); @@ -364,13 +364,13 @@ private void onExportJarClicked() { if (this.gui.exportJarFileChooser.getSelectedFile() != null) { Path path = this.gui.exportJarFileChooser.getSelectedFile().toPath(); this.gui.getController().exportJar(path); - Config.INSTANCE.lastSelectedDir.setValue(this.gui.exportJarFileChooser.getCurrentDirectory().getAbsolutePath(), true); + Config.get().lastSelectedDir.setValue(this.gui.exportJarFileChooser.getCurrentDirectory().getAbsolutePath(), true); } } private void onCustomScaleClicked() { String answer = (String) JOptionPane.showInputDialog(this.gui.getFrame(), I18n.translate("menu.view.scale.custom.title"), I18n.translate("menu.view.scale.custom.title"), - JOptionPane.QUESTION_MESSAGE, null, null, Double.toString(Config.INSTANCE.scaleFactor.value() * 100)); + JOptionPane.QUESTION_MESSAGE, null, null, Double.toString(Config.get().scaleFactor.value() * 100)); if (answer == null) { return; @@ -440,7 +440,7 @@ public void onStartServerClicked() { this.gui.getController().disconnectIfConnected(null); try { this.gui.getController().createServer(result.port(), result.password()); - if (Config.INSTANCE.serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { + if (Config.get().serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { this.gui.getNotificationManager().notify(new ParameterizedMessage(Message.SERVER_STARTED, result.port())); } @@ -457,10 +457,10 @@ private void onGithubClicked() { } private void onOpenMappingsClicked() { - this.gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(Config.INSTANCE.lastSelectedDir.value())); + this.gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(Config.get().lastSelectedDir.value())); if (this.gui.enigmaMappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { File selectedFile = this.gui.enigmaMappingsFileChooser.getSelectedFile(); - Config.INSTANCE.lastSelectedDir.setValue(this.gui.enigmaMappingsFileChooser.getCurrentDirectory().toString(), true); + Config.get().lastSelectedDir.setValue(this.gui.enigmaMappingsFileChooser.getCurrentDirectory().toString(), true); MappingFormat format = MappingFormat.parseFromFile(selectedFile.toPath()); if (format.getReader() != null) { @@ -539,7 +539,7 @@ private static void prepareSaveMappingsAsMenu(JMenu saveMappingsAsMenu, JMenuIte item.addActionListener(event -> { // TODO: Use a specific file chooser for it if (gui.enigmaMappingsFileChooser.getCurrentDirectory() == null) { - gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(Config.INSTANCE.lastSelectedDir.value())); + gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(Config.get().lastSelectedDir.value())); } if (gui.enigmaMappingsFileChooser.showSaveDialog(gui.getFrame()) == JFileChooser.APPROVE_OPTION) { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/panel/EditorPanel.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/panel/EditorPanel.java index 8acaa3533..2a061ad4d 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/panel/EditorPanel.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/panel/EditorPanel.java @@ -120,9 +120,9 @@ public EditorPanel(Gui gui, NavigatorPanel navigator) { this.editor.setCaret(new BrowserCaret()); this.editor.setFont(ScaleUtil.getFont(this.editor.getFont().getFontName(), Font.PLAIN, this.fontSize)); this.editor.addCaretListener(event -> this.onCaretMove(event.getDot(), this.mouseIsPressed)); - this.editor.setCaretColor(Config.INSTANCE.currentColors().caret.value()); + this.editor.setCaretColor(Config.currentColors().caret.value()); this.editor.setContentType("text/enigma-sources"); - this.editor.setBackground(Config.INSTANCE.currentColors().editorBackground.value()); + this.editor.setBackground(Config.currentColors().editorBackground.value()); // set unit increment to height of one line, the amount scrolled per // mouse wheel rotation is then controlled by OS settings @@ -213,7 +213,7 @@ public void keyReleased(KeyEvent event) { this.themeChangeListener = (laf, boxHighlightPainters) -> { if ((this.editorLaf == null || this.editorLaf != laf)) { this.editor.updateUI(); - this.editor.setBackground(Config.INSTANCE.currentColors().editorBackground.value()); + this.editor.setBackground(Config.currentColors().editorBackground.value()); if (this.editorLaf != null) { this.classHandle.invalidateMapped(); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/CallsTreeCellRenderer.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/CallsTreeCellRenderer.java index 613eef46f..e91eef0ae 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/CallsTreeCellRenderer.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/renderer/CallsTreeCellRenderer.java @@ -26,7 +26,7 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean Component c = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); EntryReference reference = ((ReferenceTreeNode) value).getReference(); - this.setForeground(Config.INSTANCE.currentColors().text.value()); + this.setForeground(Config.currentColors().text.value()); // if the node represents the method calling the entry if (reference != null) { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java index f8e51262a..9916e2e9d 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java @@ -22,12 +22,12 @@ public class ScaleUtil { private static final List listeners = new ArrayList<>(); public static void setScaleFactor(float scaleFactor) { - float oldScale = Config.INSTANCE.scaleFactor.value(); + float oldScale = Config.get().scaleFactor.value(); float clamped = Math.min(Math.max(0.25f, scaleFactor), 10.0f); - Config.INSTANCE.scaleFactor.setValue(clamped, true); - rescaleFontInConfig(Config.INSTANCE.currentFonts().defaultFont, oldScale); - rescaleFontInConfig(Config.INSTANCE.currentFonts().small, oldScale); - rescaleFontInConfig(Config.INSTANCE.currentFonts().editor, oldScale); + Config.get().scaleFactor.setValue(clamped, true); + rescaleFontInConfig(Config.currentFonts().defaultFont, oldScale); + rescaleFontInConfig(Config.currentFonts().small, oldScale); + rescaleFontInConfig(Config.currentFonts().editor, oldScale); listeners.forEach(l -> l.onScaleChanged(clamped, oldScale)); } @@ -52,7 +52,7 @@ public static Font getFont(String fontName, int style, int fontSize) { } public static Font scaleFont(Font font) { - return createTweakerForCurrentLook(Config.INSTANCE.scaleFactor.value()).modifyFont("", font); + return createTweakerForCurrentLook(Config.get().scaleFactor.value()).modifyFont("", font); } private static void rescaleFontInConfig(TrackedValue font, float oldScale) { @@ -61,20 +61,20 @@ private static void rescaleFontInConfig(TrackedValue font, float oldScale) // This does not use the font that's currently active in the UI! private static Font rescaleFont(Font font, float oldScale) { - float newSize = Math.round(font.getSize() / oldScale * Config.INSTANCE.scaleFactor.value()); + float newSize = Math.round(font.getSize() / oldScale * Config.get().scaleFactor.value()); return font.deriveFont(newSize); } public static float scale(float f) { - return f * Config.INSTANCE.scaleFactor.value(); + return f * Config.get().scaleFactor.value(); } public static float invert(float f) { - return f / Config.INSTANCE.scaleFactor.value(); + return f / Config.get().scaleFactor.value(); } public static int scale(int i) { - return (int) (i * Config.INSTANCE.scaleFactor.value()); + return (int) (i * Config.get().scaleFactor.value()); } public static Border createEmptyBorder(int top, int left, int bottom, int right) { @@ -82,17 +82,17 @@ public static Border createEmptyBorder(int top, int left, int bottom, int right) } public static int invert(int i) { - return (int) (i / Config.INSTANCE.scaleFactor.value()); + return (int) (i / Config.get().scaleFactor.value()); } public static void applyScaling() { - double scale = Config.INSTANCE.scaleFactor.value(); + double scale = Config.get().scaleFactor.value(); - if (Config.INSTANCE.activeLookAndFeel.needsScaling()) { + if (Config.get().activeLookAndFeel.needsScaling()) { UiDefaultsScaler.updateAndApplyGlobalScaling((int) (100 * scale), true); } - Font font = Config.INSTANCE.currentFonts().editor.value(); + Font font = Config.currentFonts().editor.value(); font = font.deriveFont((float) (12 * scale)); SyntaxpainConfiguration.setEditorFont(font); } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index db0207666..2fe641235 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -11,6 +11,7 @@ swing_dpi = "0.10" fontchooser = "2.5.2" tinylog = "2.6.2" quilt_config = "1.1.0-beta.3" +night_config = "3.6.5" vineflower = "1.10.0-20230713.053900-2" cfr = "0.2.1" @@ -34,6 +35,8 @@ tinylog_api = { module = "org.tinylog:tinylog-api", version.ref = "tinylog" } tinylog_impl = { module = "org.tinylog:tinylog-impl", version.ref = "tinylog" } quilt_config = { module = "org.quiltmc:quilt-config", version.ref = "quilt_config" } +night_config_core = { module = "com.electronwill.night-config:core", version.ref = "night_config" } +night_config_toml = { module = "com.electronwill.night-config:toml", version.ref = "night_config" } jopt = { module = "net.sf.jopt-simple:jopt-simple", version.ref = "jopt" } flatlaf = { module = "com.formdev:flatlaf", version.ref = "flatlaf" } @@ -55,6 +58,7 @@ jimfs = { module = "com.google.jimfs:jimfs", version.ref = "jimfs" } [bundles] asm = ["asm", "asm_commons", "asm_tree", "asm_util"] tinylog = ["tinylog_api", "tinylog_impl"] +night_config = ["night_config_core", "night_config_toml"] [plugins] shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" } From 1f62201cb9084f5ce653779cf1307f2dd8a2c3e3 Mon Sep 17 00:00:00 2001 From: ix0rai Date: Sun, 26 Nov 2023 17:00:13 -0600 Subject: [PATCH 08/25] fix checkstyle --- .../main/java/org/quiltmc/enigma/gui/config/Decompiler.java | 1 - .../org/quiltmc/enigma/gui/config/DecompilerConfig.java | 6 ++---- .../quiltmc/enigma/gui/config/NightConfigSerializer.java | 2 +- .../src/test/java/org/quiltmc/enigma/TestPackageRename.java | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Decompiler.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Decompiler.java index 978b8989c..690b93648 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Decompiler.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Decompiler.java @@ -5,7 +5,6 @@ import org.quiltmc.enigma.api.source.DecompilerService; import org.quiltmc.enigma.api.source.Decompilers; -import java.util.Map; import java.util.function.BiConsumer; import javax.swing.JDialog; diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java index 0a813b7df..09b903eaa 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java @@ -18,8 +18,7 @@ private static class VineflowerSection extends ReflectiveConfig.Section { } public static void updateVineflowerValues(Map options) { - VineflowerSection section = // statically get it - null; + VineflowerSection section = getVineflowerSection(); for (Map.Entry entry : options.entrySet()) { if (entry.getValue() instanceof String s) { @@ -33,8 +32,7 @@ public static void updateVineflowerValues(Map options) { } public static VineflowerSection getVineflowerSection() { - // todo - return null; + return Config.decompiler().vineflowerSection.value(); } public static void bootstrap() { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NightConfigSerializer.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NightConfigSerializer.java index fd3b31e57..4553a5c68 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NightConfigSerializer.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NightConfigSerializer.java @@ -53,7 +53,7 @@ public void deserialize(Config config, InputStream from) { for (TrackedValue trackedValue : config.values()) { if (read.contains(trackedValue.key().toString())) { ((TrackedValue) trackedValue).setValue(MarshallingUtils.coerce(read.get(trackedValue.key().toString()), trackedValue.getDefaultValue(), (CommentedConfig c, MarshallingUtils.MapEntryConsumer entryConsumer) -> - c.entrySet().forEach(e -> entryConsumer.put(e.getKey(), e.getValue()))), false); + c.entrySet().forEach(e -> entryConsumer.put(e.getKey(), e.getValue()))), false); } } } diff --git a/enigma-swing/src/test/java/org/quiltmc/enigma/TestPackageRename.java b/enigma-swing/src/test/java/org/quiltmc/enigma/TestPackageRename.java index 0471f563d..c7805db3b 100644 --- a/enigma-swing/src/test/java/org/quiltmc/enigma/TestPackageRename.java +++ b/enigma-swing/src/test/java/org/quiltmc/enigma/TestPackageRename.java @@ -118,7 +118,7 @@ private static void renamePackage(String packageName, String newName, PackageRen private static ClassSelectorPopupMenu setupMenu() throws InterruptedException { Set editables = EnumSet.allOf(EditableType.class); editables.addAll(List.of(EditableType.values())); - Gui gui = new Gui(EnigmaProfile.EMPTY, editables, false, config); + Gui gui = new Gui(EnigmaProfile.EMPTY, editables, false); gui.setShowsProgressBars(false); CountDownLatch latch = new CountDownLatch(1); From 4fbc9104ac3a29a4dc3f4064feb2797cf4a971cd Mon Sep 17 00:00:00 2001 From: ix0rai Date: Mon, 27 Nov 2023 21:32:11 -0600 Subject: [PATCH 09/25] progress --- .../main/java/org/quiltmc/enigma/gui/Gui.java | 8 ++-- .../org/quiltmc/enigma/gui/config/Config.java | 45 ++++++++++++++++--- .../enigma/gui/config/KeyBindsConfig.java | 4 +- .../enigma/gui/config/keybind/KeyBinds.java | 4 +- 4 files changed, 48 insertions(+), 13 deletions(-) diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java index 455236eea..ba38f7da5 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java @@ -208,11 +208,11 @@ private void setupUi() { JFrame frame = this.mainWindow.getFrame(); frame.addWindowListener(GuiUtil.onWindowClose(e -> this.close())); - frame.setSize(Config.get().windowSize.value()); + frame.setSize(Config.get().windowSize.value().toDimension()); frame.setMinimumSize(ScaleUtil.getDimension(640, 480)); frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - Point windowPos = Config.get().windowPos.value(); + Point windowPos = Config.get().windowPos.value().toPoint(); frame.setLocation(windowPos); this.retranslateUi(); @@ -515,8 +515,8 @@ public void close() { } private void exit() { - Config.get().windowPos.setValue(this.mainWindow.getFrame().getLocationOnScreen(), true); - Config.get().windowSize.setValue(this.mainWindow.getFrame().getSize(), true); + Config.get().windowPos.setValue(Config.Vec2i.fromPoint(this.mainWindow.getFrame().getLocationOnScreen()), true); + Config.get().windowSize.setValue(Config.Vec2i.fromDimension(this.mainWindow.getFrame().getSize()), true); Config.get().save(); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java index ff060bf30..2c1efc039 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java @@ -16,7 +16,6 @@ import org.quiltmc.enigma.gui.config.theme.ThemeColors; import org.quiltmc.enigma.gui.config.theme.ThemeFonts; import org.quiltmc.enigma.gui.dialog.EnigmaQuickFindDialog; -import org.quiltmc.enigma.gui.util.ScaleUtil; import org.quiltmc.enigma.util.I18n; import org.quiltmc.syntaxpain.SyntaxpainConfiguration; @@ -30,7 +29,7 @@ public final class Config extends ReflectiveConfig { private static final Config INSTANCE = ConfigFactory.create(ENVIRONMENT, "enigma", "main", Config.class); public Config() { - updateSyntaxpain(); + //updateSyntaxpain(); } public final TrackedValue language = this.value(I18n.DEFAULT_LANGUAGE); @@ -39,8 +38,8 @@ public Config() { public final TrackedValue> recentProjects = this.list(new RecentProject("", "")); public final TrackedValue serverNotificationLevel = this.value(NotificationManager.ServerNotificationLevel.FULL); public final TrackedValue useCustomFonts = this.value(false); - public final TrackedValue windowSize = this.value(ScaleUtil.getDimension(1024, 576)); - public final TrackedValue windowPos = this.value(new Point()); + public final TrackedValue windowSize = this.value(new Vec2i(1024, 576)); + public final TrackedValue windowPos = this.value(new Vec2i(0, 0)); public final TrackedValue lastSelectedDir = this.value(""); public final TrackedValue lastTopLevelPackage = this.value(""); public final TrackedValue shouldIncludeSyntheticParameters = this.value(false); @@ -51,7 +50,7 @@ public Config() { public final TrackedValue lookAndFeel = this.value(LookAndFeel.DEFAULT); // todo laf can't be changed while running - public final LookAndFeel activeLookAndFeel = this.lookAndFeel.value(); + public final transient LookAndFeel activeLookAndFeel = this.lookAndFeel.value(); public final TrackedValue defaultTheme = this.value(new Theme(LookAndFeel.DEFAULT)); public final TrackedValue darculaTheme = this.value(new Theme(LookAndFeel.DEFAULT)); @@ -133,6 +132,42 @@ public ComplexConfigValue copy() { } } + public record Vec2i(int x, int y) implements ConfigSerializableObject> { + public Dimension toDimension() { + return new Dimension(this.x, this.y); + } + + public static Vec2i fromDimension(Dimension dimension) { + return new Vec2i(dimension.width, dimension.height); + } + + public Point toPoint() { + return new Point(this.x, this.y); + } + + public static Vec2i fromPoint(Point point) { + return new Vec2i(point.x, point.y); + } + + @Override + public Vec2i convertFrom(ValueMap representation) { + return new Vec2i(representation.get("x"), representation.get("y")); + } + + @Override + public ValueMap getRepresentation() { + return ValueMap.builder(0) + .put("x", this.x) + .put("y", this.y) + .build(); + } + + @Override + public ComplexConfigValue copy() { + return this; + } + } + /** * Updates the backend library Syntaxpain, used for code highlighting and other editor things. */ diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindsConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindsConfig.java index e8501baaf..bb792a901 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindsConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindsConfig.java @@ -8,12 +8,12 @@ public final class KeyBindsConfig extends ReflectiveConfig.Section { public final TrackedValue> keyCodes = this.map(new String[]{""}).build(); - public String[] getKeyBindCodes(KeyBind keyBind) { + public String[] getKeyCodes(KeyBind keyBind) { String[] codes = this.keyCodes.value().get(keyBind.name()); return codes.length == 0 ? keyBind.serializeCombinations() : codes; } - public void setKeyBind(KeyBind keyBind) { + public void setBind(KeyBind keyBind) { this.keyCodes.value().put(keyBind.name(), keyBind.serializeCombinations()); } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/keybind/KeyBinds.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/keybind/KeyBinds.java index 47765fcf9..295b7b009 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/keybind/KeyBinds.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/keybind/KeyBinds.java @@ -89,7 +89,7 @@ public static Map> getEditableKeyBindsByCategory() { public static void loadConfig() { for (KeyBind keyBind : CONFIGURABLE_KEY_BINDS) { - keyBind.deserializeCombinations(Config.keyBinds().getKeyBindCodes(keyBind)); + keyBind.deserializeCombinations(Config.keyBinds().getKeyCodes(keyBind)); } resetEditableKeyBinds(); @@ -101,7 +101,7 @@ public static void saveConfig() { KeyBind editedKeyBind = editableKeyBinds.get(i); if (!editedKeyBind.equals(keyBind)) { keyBind.setFrom(editedKeyBind); - Config.keyBinds().setKeyBind(editedKeyBind); + Config.keyBinds().setBind(editedKeyBind); } } } From 7580bd5fcc6da67953e60843cef863902601818e Mon Sep 17 00:00:00 2001 From: ix0rai Date: Wed, 29 Nov 2023 21:43:41 -0600 Subject: [PATCH 10/25] qconf 1.1.0 --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2fe641235..0d54cda1f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,7 +10,7 @@ syntaxpain = "0.1.1" swing_dpi = "0.10" fontchooser = "2.5.2" tinylog = "2.6.2" -quilt_config = "1.1.0-beta.3" +quilt_config = "1.1.0" night_config = "3.6.5" vineflower = "1.10.0-20230713.053900-2" From e0006a5ac93810cef3a1e1c51a96ada3a72557e7 Mon Sep 17 00:00:00 2001 From: ix0rai Date: Fri, 1 Dec 2023 23:12:40 -0600 Subject: [PATCH 11/25] nearly working --- .../main/java/org/quiltmc/enigma/gui/Gui.java | 2 +- .../org/quiltmc/enigma/gui/config/Config.java | 60 +++--- .../enigma/gui/config/DecompilerConfig.java | 36 ++-- .../enigma/gui/config/DockerConfig.java | 4 +- .../enigma/gui/config/KeyBindsConfig.java | 11 +- .../quiltmc/enigma/gui/config/NetConfig.java | 2 +- .../enigma/gui/config/theme/LookAndFeel.java | 19 +- .../enigma/gui/config/theme/Theme.java | 180 +++++++++++++++++- .../enigma/gui/config/theme/ThemeColors.java | 110 ----------- .../enigma/gui/config/theme/ThemeFonts.java | 13 -- .../org/quiltmc/enigma/gui/docker/Docker.java | 24 ++- 11 files changed, 269 insertions(+), 192 deletions(-) delete mode 100644 enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/ThemeColors.java delete mode 100644 enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/ThemeFonts.java diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java index ba38f7da5..6baacba53 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java @@ -614,7 +614,7 @@ public void addMessage(ServerMessage message) { // popup notifications switch (message.getType()) { case CHAT -> { - if (Config.get().serverNotificationLevel.value() == NotificationManager.ServerNotificationLevel.FULL && !message.user.equals(Config.get().net.value().username.value())) { + if (Config.get().serverNotificationLevel.value() == NotificationManager.ServerNotificationLevel.FULL && !message.user.equals(Config.net().username.value())) { this.notificationManager.notify(new ParameterizedMessage(Message.MULTIPLAYER_CHAT, message.translate())); } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java index 2c1efc039..e84695e8c 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java @@ -13,8 +13,6 @@ import org.quiltmc.enigma.gui.NotificationManager; import org.quiltmc.enigma.gui.config.theme.LookAndFeel; import org.quiltmc.enigma.gui.config.theme.Theme; -import org.quiltmc.enigma.gui.config.theme.ThemeColors; -import org.quiltmc.enigma.gui.config.theme.ThemeFonts; import org.quiltmc.enigma.gui.dialog.EnigmaQuickFindDialog; import org.quiltmc.enigma.util.I18n; import org.quiltmc.syntaxpain.SyntaxpainConfiguration; @@ -26,7 +24,11 @@ public final class Config extends ReflectiveConfig { private static final ConfigEnvironment ENVIRONMENT = new ConfigEnvironment(ConfigPaths.getConfigPathRoot(), "toml", new NightConfigSerializer<>("toml", new TomlParser(), new TomlWriter())); - private static final Config INSTANCE = ConfigFactory.create(ENVIRONMENT, "enigma", "main", Config.class); + private static final Config MAIN = ConfigFactory.create(ENVIRONMENT, "enigma", "main", Config.class); + private static final KeyBindsConfig KEYBINDS = ConfigFactory.create(ENVIRONMENT, "enigma", "keybinds", KeyBindsConfig.class); + private static final NetConfig NET = ConfigFactory.create(ENVIRONMENT, "enigma", "net", NetConfig.class); + private static final DockerConfig DOCKER = ConfigFactory.create(ENVIRONMENT, "enigma", "docker", DockerConfig.class); + private static final DecompilerConfig DECOMPILER = ConfigFactory.create(ENVIRONMENT, "enigma", "decompiler", DecompilerConfig.class); public Config() { //updateSyntaxpain(); @@ -43,65 +45,61 @@ public Config() { public final TrackedValue lastSelectedDir = this.value(""); public final TrackedValue lastTopLevelPackage = this.value(""); public final TrackedValue shouldIncludeSyntheticParameters = this.value(false); - public final TrackedValue keyBinds = this.value(new KeyBindsConfig()); - public final TrackedValue net = this.value(new NetConfig()); - public final TrackedValue decompiler = this.value(new DecompilerConfig()); - public final TrackedValue dockerConfig = this.value(new DockerConfig()); public final TrackedValue lookAndFeel = this.value(LookAndFeel.DEFAULT); // todo laf can't be changed while running public final transient LookAndFeel activeLookAndFeel = this.lookAndFeel.value(); - public final TrackedValue defaultTheme = this.value(new Theme(LookAndFeel.DEFAULT)); - public final TrackedValue darculaTheme = this.value(new Theme(LookAndFeel.DEFAULT)); - public final TrackedValue metalTheme = this.value(new Theme(LookAndFeel.METAL)); - public final TrackedValue systemTheme = this.value(new Theme(LookAndFeel.SYSTEM)); - public final TrackedValue noneTheme = this.value(new Theme(LookAndFeel.NONE)); + public final Theme defaultTheme = new Theme(LookAndFeel.DEFAULT); + public final Theme darculaTheme = new Theme(LookAndFeel.DARCULA); + public final Theme metalTheme = new Theme(LookAndFeel.METAL); + public final Theme systemTheme = new Theme(LookAndFeel.SYSTEM); + public final Theme noneTheme = new Theme(LookAndFeel.NONE); public static Config get() { - return INSTANCE; + return MAIN; } public static DockerConfig dockers() { - return INSTANCE.dockerConfig.value(); + return DOCKER; } public static KeyBindsConfig keyBinds() { - return INSTANCE.keyBinds.value(); + return KEYBINDS; } public static NetConfig net() { - return INSTANCE.net.value(); + return NET; } public static DecompilerConfig decompiler() { - return INSTANCE.decompiler.value(); + return DECOMPILER; } public static Theme currentTheme() { - return switch (INSTANCE.activeLookAndFeel) { - case DEFAULT -> INSTANCE.defaultTheme.value(); - case DARCULA -> INSTANCE.darculaTheme.value(); - case METAL -> INSTANCE.metalTheme.value(); - case SYSTEM -> INSTANCE.systemTheme.value(); - case NONE -> INSTANCE.noneTheme.value(); + return switch (MAIN.activeLookAndFeel) { + case DEFAULT -> MAIN.defaultTheme; + case DARCULA -> MAIN.darculaTheme; + case METAL -> MAIN.metalTheme; + case SYSTEM -> MAIN.systemTheme; + case NONE -> MAIN.noneTheme; }; } - public static ThemeColors currentColors() { - return currentTheme().colors.value(); + public static Theme.Colors currentColors() { + return currentTheme().colors; } - public static ThemeFonts currentFonts() { - return currentTheme().fonts.value(); + public static Theme.Fonts currentFonts() { + return currentTheme().fonts; } public static void insertRecentProject(String jarPath, String mappingsPath) { - INSTANCE.recentProjects.value().add(0, new RecentProject(jarPath, mappingsPath)); + MAIN.recentProjects.value().add(0, new RecentProject(jarPath, mappingsPath)); } public static RecentProject getMostRecentProject() { - return INSTANCE.recentProjects.value().get(0); + return MAIN.recentProjects.value().get(0); } public record RecentProject(String jarPath, String mappingsPath) implements ConfigSerializableObject> { @@ -172,8 +170,8 @@ public ComplexConfigValue copy() { * Updates the backend library Syntaxpain, used for code highlighting and other editor things. */ private static void updateSyntaxpain() { - ThemeFonts fonts = currentFonts(); - ThemeColors colors = currentColors(); + Theme.Fonts fonts = currentFonts(); + Theme.Colors colors = currentColors(); SyntaxpainConfiguration.setEditorFont(fonts.editor.value()); SyntaxpainConfiguration.setQuickFindDialogFactory(EnigmaQuickFindDialog::new); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java index 09b903eaa..948d2e8ec 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java @@ -7,41 +7,31 @@ import java.util.Map; -public class DecompilerConfig extends ReflectiveConfig.Section { - public final TrackedValue decompiler = this.value(Decompiler.VINEFLOWER); - public final TrackedValue vineflowerSection = this.value(new VineflowerSection()); - - private static class VineflowerSection extends ReflectiveConfig.Section { - public final TrackedValue> stringValues = this.map("").build(); - public final TrackedValue> intValues = this.map(0).build(); - public final TrackedValue> booleanValues = this.map(true).build(); +public class DecompilerConfig extends ReflectiveConfig { + public DecompilerConfig() { + VineflowerPreferences.OPTIONS.putAll(this.stringValues.value()); + VineflowerPreferences.OPTIONS.putAll(this.intValues.value()); + VineflowerPreferences.OPTIONS.putAll(this.booleanValues.value()); } - public static void updateVineflowerValues(Map options) { - VineflowerSection section = getVineflowerSection(); + public final TrackedValue decompiler = this.value(Decompiler.VINEFLOWER); + public final TrackedValue> stringValues = this.map("").build(); + public final TrackedValue> intValues = this.map(0).build(); + public final TrackedValue> booleanValues = this.map(true).build(); + public static void updateVineflowerValues(Map options) { for (Map.Entry entry : options.entrySet()) { if (entry.getValue() instanceof String s) { - section.stringValues.value().put(entry.getKey(), s); + Config.decompiler().stringValues.value().put(entry.getKey(), s); } else if (entry.getValue() instanceof Integer i) { - section.intValues.value().put(entry.getKey(), i); + Config.decompiler().intValues.value().put(entry.getKey(), i); } else if (entry.getValue() instanceof Boolean b) { - section.booleanValues.value().put(entry.getKey(), b); + Config.decompiler().booleanValues.value().put(entry.getKey(), b); } } } - public static VineflowerSection getVineflowerSection() { - return Config.decompiler().vineflowerSection.value(); - } - public static void bootstrap() { // Just run the static initialization } - - static { - VineflowerPreferences.OPTIONS.putAll(getVineflowerSection().stringValues.value()); - VineflowerPreferences.OPTIONS.putAll(getVineflowerSection().intValues.value()); - VineflowerPreferences.OPTIONS.putAll(getVineflowerSection().booleanValues.value()); - } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java index b185d3585..f344244da 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java @@ -15,10 +15,11 @@ import org.quiltmc.enigma.gui.docker.ObfuscatedClassesDocker; import org.quiltmc.enigma.gui.docker.StructureDocker; +import javax.annotation.Nullable; import java.util.Map; import java.util.stream.Collectors; -public class DockerConfig extends ReflectiveConfig.Section { +public class DockerConfig extends ReflectiveConfig { public final TrackedValue leftVerticalDividerLocation = this.value(300); public final TrackedValue rightVerticalDividerLocation = this.value(300); public final TrackedValue leftHorizontalDividerLocation = this.value(300); @@ -35,6 +36,7 @@ public void putLocation(Docker docker, Docker.Side side, Docker.VerticalLocation this.putLocation(docker.getId(), new Docker.Location(side, verticalLocation)); } + @Nullable public Docker.Location getLocation(String id) { return this.dockerLocations.value().get(id); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindsConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindsConfig.java index bb792a901..94a1798bf 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindsConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindsConfig.java @@ -2,18 +2,19 @@ import org.quiltmc.config.api.ReflectiveConfig; import org.quiltmc.config.api.values.TrackedValue; +import org.quiltmc.config.api.values.ValueList; import org.quiltmc.config.api.values.ValueMap; import org.quiltmc.enigma.gui.config.keybind.KeyBind; -public final class KeyBindsConfig extends ReflectiveConfig.Section { - public final TrackedValue> keyCodes = this.map(new String[]{""}).build(); +public final class KeyBindsConfig extends ReflectiveConfig { + public final TrackedValue>> keyCodes = this.map(ValueList.create("")).build(); public String[] getKeyCodes(KeyBind keyBind) { - String[] codes = this.keyCodes.value().get(keyBind.name()); - return codes.length == 0 ? keyBind.serializeCombinations() : codes; + ValueList codes = this.keyCodes.value().get(keyBind.name()); + return (codes == null || codes.size() == 0) ? keyBind.serializeCombinations() : codes.toArray(String[]::new); } public void setBind(KeyBind keyBind) { - this.keyCodes.value().put(keyBind.name(), keyBind.serializeCombinations()); + this.keyCodes.value().put(keyBind.name(), ValueList.create("", keyBind.serializeCombinations())); } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NetConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NetConfig.java index 17fd4cfa2..8b37eb287 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NetConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NetConfig.java @@ -4,7 +4,7 @@ import org.quiltmc.config.api.values.TrackedValue; import org.quiltmc.enigma.network.EnigmaServer; -public final class NetConfig extends ReflectiveConfig.Section { +public final class NetConfig extends ReflectiveConfig { public final TrackedValue username = this.value(System.getProperty("user.name", "user")); public final TrackedValue password = this.value(""); public final TrackedValue remoteAddress = this.value(""); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/LookAndFeel.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/LookAndFeel.java index 76ce8fff1..7c14b1a9c 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/LookAndFeel.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/LookAndFeel.java @@ -3,6 +3,8 @@ import com.formdev.flatlaf.FlatDarkLaf; import com.formdev.flatlaf.FlatLightLaf; import com.formdev.flatlaf.FlatSystemProperties; +import org.quiltmc.config.api.values.ComplexConfigValue; +import org.quiltmc.config.api.values.ConfigSerializableObject; import org.quiltmc.enigma.gui.config.Config; import java.awt.Color; @@ -12,7 +14,7 @@ import javax.swing.UIManager; import javax.swing.plaf.metal.MetalLookAndFeel; -public enum LookAndFeel { +public enum LookAndFeel implements ConfigSerializableObject { DEFAULT(false), DARCULA(false), METAL(true), @@ -66,4 +68,19 @@ public static boolean isDarkLaf() { int b = (int) (0.3 * c.getRed() + 0.59 * c.getGreen() + 0.11 * c.getBlue()); return b < 85; } + + @Override + public ConfigSerializableObject convertFrom(Integer representation) { + return values()[representation]; + } + + @Override + public Integer getRepresentation() { + return this.ordinal(); + } + + @Override + public ComplexConfigValue copy() { + return this; + } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java index 8450c3a80..1600c9d15 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java @@ -1,14 +1,188 @@ package org.quiltmc.enigma.gui.config.theme; import org.quiltmc.config.api.ReflectiveConfig; +import org.quiltmc.config.api.values.ComplexConfigValue; +import org.quiltmc.config.api.values.ConfigSerializableObject; import org.quiltmc.config.api.values.TrackedValue; +import org.quiltmc.config.api.values.ValueMap; +import org.quiltmc.enigma.gui.util.ScaleUtil; + +import java.awt.Color; +import java.awt.Font; public class Theme extends ReflectiveConfig.Section { - public final LookAndFeel lookAndFeel; + public final transient LookAndFeel lookAndFeel; public Theme(LookAndFeel lookAndFeel) { this.lookAndFeel = lookAndFeel; } - public final TrackedValue colors = this.value(new ThemeColors()); - public final TrackedValue fonts = this.value(new ThemeFonts()); + public final Colors colors = new Colors(); + public final Fonts fonts = new Fonts(); + + public static class Fonts extends ReflectiveConfig.Section { + public final TrackedValue defaultFont = this.value(new SerializableFont(Font.decode(Font.DIALOG).deriveFont(Font.BOLD))); + public final TrackedValue small = this.value(new SerializableFont(Font.decode(Font.DIALOG))); + public final TrackedValue editor = this.value(new SerializableFont(Font.decode(Font.MONOSPACED))); + + private static class SerializableFont extends Font implements ConfigSerializableObject> { + public SerializableFont(Font font) { + this(font.getName(), font.getStyle(), font.getSize()); + } + + public SerializableFont(String name, int style, int size) { + super(name, style, size); + } + + @Override + public ConfigSerializableObject> convertFrom(ValueMap representation) { + return new SerializableFont( + representation.get("name"), + Integer.parseInt(representation.get("style")), + Integer.parseInt(representation.get("size")) + ); + } + + @Override + public ValueMap getRepresentation() { + return ValueMap.builder("") + .put("name", this.name) + .put("style", String.valueOf(this.style)) + .put("size", String.valueOf(this.size)) + .build(); + } + + @Override + public ComplexConfigValue copy() { + return new SerializableFont(this.name, this.style, this.size); + } + } + } + + public static class Colors extends ReflectiveConfig.Section { + public final TrackedValue lineNumbersForeground = this.value(new SerializableColor(0xFF333300)); + public final TrackedValue lineNumbersBackground = this.value(new SerializableColor(0xFFEEEEFF)); + public final TrackedValue lineNumbersSelected = this.value(new SerializableColor(0xFFCCCCEE)); + + public final TrackedValue obfuscated = this.value(new SerializableColor(0xFFFFDCDC)); + public final TrackedValue obfuscatedOutline = this.value(new SerializableColor(0xFFA05050)); + + public final TrackedValue proposed = this.value(new SerializableColor(0xFF000000)); + public final TrackedValue proposedOutline = this.value(new SerializableColor(0xBF000000)); + + public final TrackedValue deobfuscated = this.value(new SerializableColor(0xFFDCFFDC)); + public final TrackedValue deobfuscatedOutline = this.value(new SerializableColor(0xFF50A050)); + + public final TrackedValue editorBackground = this.value(new SerializableColor(0xFF50A050)); + public final TrackedValue highlight = this.value(new SerializableColor(0xFF50A050)); + public final TrackedValue caret = this.value(new SerializableColor(0xFF50A050)); + public final TrackedValue selectionHighlight = this.value(new SerializableColor(0xFF50A050)); + public final TrackedValue string = this.value(new SerializableColor(0xFFCC6600)); + public final TrackedValue number = this.value(new SerializableColor(0xFF999933)); + public final TrackedValue operator = this.value(new SerializableColor(0xFF000000)); + public final TrackedValue delimiter = this.value(new SerializableColor(0xFF000000)); + public final TrackedValue type = this.value(new SerializableColor(0xFF000000)); + public final TrackedValue identifier = this.value(new SerializableColor(0xFF000000)); + public final TrackedValue comment = this.value(new SerializableColor(0xFF339933)); + public final TrackedValue text = this.value(new SerializableColor(0xFF000000)); + + public final TrackedValue debugToken = this.value(new SerializableColor(0xFFD9BEF9)); + public final TrackedValue debugTokenOutline = this.value(new SerializableColor(0xFFBD93F9)); + + public final TrackedValue dockHighlight = this.value(new SerializableColor(0xFF0000FF)); + + private static class SerializableColor extends Color implements ConfigSerializableObject { + private final int rgba; + + public SerializableColor(int rgba) { + super(rgba, true); + this.rgba = rgba; + } + + @Override + public ConfigSerializableObject convertFrom(Integer representation) { + return new SerializableColor(representation); + } + + @Override + public Integer getRepresentation() { + return this.rgba; + } + + @Override + public ComplexConfigValue copy() { + return new SerializableColor(this.rgba); + } + } + + public void configure(boolean dark) { + if (dark) { + setIfAbsent(this.lineNumbersForeground, new SerializableColor(0xFFA4A4A3)); + setIfAbsent(this.lineNumbersBackground, new SerializableColor(0xFF313335)); + setIfAbsent(this.lineNumbersSelected, new SerializableColor(0xFF606366)); + + setIfAbsent(this.obfuscated, new SerializableColor(0x4DFF5555)); + setIfAbsent(this.obfuscatedOutline, new SerializableColor(0x80FF5555)); + + setIfAbsent(this.proposed, new SerializableColor(0x4D606366)); + setIfAbsent(this.proposedOutline, new SerializableColor(0x80606366)); + + setIfAbsent(this.deobfuscated, new SerializableColor(0x4D50FA7B)); + setIfAbsent(this.deobfuscatedOutline, new SerializableColor(0x50FA7B)); + + setIfAbsent(this.editorBackground, new SerializableColor(0xFF282A36)); + setIfAbsent(this.highlight, new SerializableColor(0xFFFF79C6)); + setIfAbsent(this.caret, new SerializableColor(0xFFF8F8F2)); + setIfAbsent(this.selectionHighlight, new SerializableColor(0xFFF8F8F2)); + setIfAbsent(this.string, new SerializableColor(0xFFF1FA8C)); + setIfAbsent(this.number, new SerializableColor(0xFFBD93F9)); + setIfAbsent(this.operator, new SerializableColor(0xFFF8F8F2)); + setIfAbsent(this.delimiter, new SerializableColor(0xFFF8F8F2)); + setIfAbsent(this.type, new SerializableColor(0xFFF8F8F2)); + setIfAbsent(this.identifier, new SerializableColor(0xFFF8F8F2)); + setIfAbsent(this.comment, new SerializableColor(0xFF339933)); + setIfAbsent(this.text, new SerializableColor(0xFFF8F8F2)); + + setIfAbsent(this.debugToken, new SerializableColor(0x804B1370)); + setIfAbsent(this.debugTokenOutline, new SerializableColor(0x80701367)); + } else { + resetIfAbsent(this.lineNumbersForeground); + resetIfAbsent(this.lineNumbersBackground); + resetIfAbsent(this.lineNumbersSelected); + + resetIfAbsent(this.obfuscated); + resetIfAbsent(this.obfuscatedOutline); + + resetIfAbsent(this.proposed); + resetIfAbsent(this.proposedOutline); + + resetIfAbsent(this.deobfuscated); + resetIfAbsent(this.deobfuscatedOutline); + + resetIfAbsent(this.editorBackground); + resetIfAbsent(this.highlight); + resetIfAbsent(this.caret); + resetIfAbsent(this.selectionHighlight); + resetIfAbsent(this.string); + resetIfAbsent(this.number); + resetIfAbsent(this.operator); + resetIfAbsent(this.delimiter); + resetIfAbsent(this.type); + resetIfAbsent(this.identifier); + resetIfAbsent(this.text); + + resetIfAbsent(this.debugToken); + resetIfAbsent(this.debugTokenOutline); + } + } + + private static void resetIfAbsent(TrackedValue value) { + setIfAbsent(value, value.getDefaultValue()); + } + + private static void setIfAbsent(TrackedValue value, T newValue) { + if (value.getDefaultValue().equals(value.value())) { + value.setValue(newValue, true); + } + } + } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/ThemeColors.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/ThemeColors.java deleted file mode 100644 index f1ab92028..000000000 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/ThemeColors.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.quiltmc.enigma.gui.config.theme; - -import org.quiltmc.config.api.ReflectiveConfig; -import org.quiltmc.config.api.values.TrackedValue; - -import java.awt.Color; - -public class ThemeColors extends ReflectiveConfig.Section { - public final TrackedValue lineNumbersForeground = this.value(new Color(0xFF333300, true)); - public final TrackedValue lineNumbersBackground = this.value(new Color(0xFFEEEEFF, true)); - public final TrackedValue lineNumbersSelected = this.value(new Color(0xFFCCCCEE, true)); - - public final TrackedValue obfuscated = this.value(new Color(0xFFFFDCDC, true)); - public final TrackedValue obfuscatedOutline = this.value(new Color(0xFFA05050, true)); - - public final TrackedValue proposed = this.value(new Color(0xFF000000, true)); - public final TrackedValue proposedOutline = this.value(new Color(0xBF000000, true)); - - public final TrackedValue deobfuscated = this.value(new Color(0xFFDCFFDC, true)); - public final TrackedValue deobfuscatedOutline = this.value(new Color(0xFF50A050, true)); - - public final TrackedValue editorBackground = this.value(new Color(0xFF50A050, true)); - public final TrackedValue highlight = this.value(new Color(0xFF50A050, true)); - public final TrackedValue caret = this.value(new Color(0xFF50A050, true)); - public final TrackedValue selectionHighlight = this.value(new Color(0xFF50A050, true)); - public final TrackedValue string = this.value(new Color(0xFFCC6600, true)); - public final TrackedValue number = this.value(new Color(0xFF999933, true)); - public final TrackedValue operator = this.value(new Color(0xFF000000, true)); - public final TrackedValue delimiter = this.value(new Color(0xFF000000, true)); - public final TrackedValue type = this.value(new Color(0xFF000000, true)); - public final TrackedValue identifier = this.value(new Color(0xFF000000, true)); - public final TrackedValue comment = this.value(new Color(0xFF339933, true)); - public final TrackedValue text = this.value(new Color(0xFF000000, true)); - - public final TrackedValue debugToken = this.value(new Color(0xFFD9BEF9, true)); - public final TrackedValue debugTokenOutline = this.value(new Color(0xFFBD93F9, true)); - - public final TrackedValue dockHighlight = this.value(new Color(0xFF0000FF, true)); - - public void configure(boolean dark) { - if (dark) { - setIfAbsent(this.lineNumbersForeground, new Color(0xFFA4A4A3, true)); - setIfAbsent(this.lineNumbersBackground, new Color(0xFF313335, true)); - setIfAbsent(this.lineNumbersSelected, new Color(0xFF606366, true)); - - setIfAbsent(this.obfuscated, new Color(0x4DFF5555, true)); - setIfAbsent(this.obfuscatedOutline, new Color(0x80FF5555, true)); - - setIfAbsent(this.proposed, new Color(0x4D606366, true)); - setIfAbsent(this.proposedOutline, new Color(0x80606366, true)); - - setIfAbsent(this.deobfuscated, new Color(0x4D50FA7B, true)); - setIfAbsent(this.deobfuscatedOutline, new Color(0x50FA7B, true)); - - setIfAbsent(this.editorBackground, new Color(0xFF282A36, true)); - setIfAbsent(this.highlight, new Color(0xFFFF79C6, true)); - setIfAbsent(this.caret, new Color(0xFFF8F8F2, true)); - setIfAbsent(this.selectionHighlight, new Color(0xFFF8F8F2)); - setIfAbsent(this.string, new Color(0xFFF1FA8C, true)); - setIfAbsent(this.number, new Color(0xFFBD93F9, true)); - setIfAbsent(this.operator, new Color(0xFFF8F8F2, true)); - setIfAbsent(this.delimiter, new Color(0xFFF8F8F2, true)); - setIfAbsent(this.type, new Color(0xFFF8F8F2, true)); - setIfAbsent(this.identifier, new Color(0xFFF8F8F2, true)); - setIfAbsent(this.comment, new Color(0xFF339933, true)); - setIfAbsent(this.text, new Color(0xFFF8F8F2, true)); - - setIfAbsent(this.debugToken, new Color(0x804B1370, true)); - setIfAbsent(this.debugTokenOutline, new Color(0x80701367, true)); - } else { - resetIfAbsent(this.lineNumbersForeground); - resetIfAbsent(this.lineNumbersBackground); - resetIfAbsent(this.lineNumbersSelected); - - resetIfAbsent(this.obfuscated); - resetIfAbsent(this.obfuscatedOutline); - - resetIfAbsent(this.proposed); - resetIfAbsent(this.proposedOutline); - - resetIfAbsent(this.deobfuscated); - resetIfAbsent(this.deobfuscatedOutline); - - resetIfAbsent(this.editorBackground); - resetIfAbsent(this.highlight); - resetIfAbsent(this.caret); - resetIfAbsent(this.selectionHighlight); - resetIfAbsent(this.string); - resetIfAbsent(this.number); - resetIfAbsent(this.operator); - resetIfAbsent(this.delimiter); - resetIfAbsent(this.type); - resetIfAbsent(this.identifier); - resetIfAbsent(this.text); - - resetIfAbsent(this.debugToken); - resetIfAbsent(this.debugTokenOutline); - } - } - - private static void resetIfAbsent(TrackedValue value) { - setIfAbsent(value, value.getDefaultValue()); - } - - private static void setIfAbsent(TrackedValue value, T newValue) { - if (value.getDefaultValue().equals(value.value())) { - value.setValue(newValue, true); - } - } -} diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/ThemeFonts.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/ThemeFonts.java deleted file mode 100644 index 27538634c..000000000 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/ThemeFonts.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.quiltmc.enigma.gui.config.theme; - -import org.quiltmc.config.api.ReflectiveConfig; -import org.quiltmc.config.api.values.TrackedValue; -import org.quiltmc.enigma.gui.util.ScaleUtil; - -import java.awt.Font; - -public class ThemeFonts extends ReflectiveConfig.Section { - public final TrackedValue defaultFont = this.value(Font.decode(Font.DIALOG).deriveFont(Font.BOLD)); - public final TrackedValue small = this.value(ScaleUtil.scaleFont(Font.decode(Font.DIALOG))); - public final TrackedValue editor = this.value(Font.decode(Font.MONOSPACED)); -} diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java index 5a7fb21f7..6140d7495 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java @@ -1,5 +1,7 @@ package org.quiltmc.enigma.gui.docker; +import org.quiltmc.config.api.values.ComplexConfigValue; +import org.quiltmc.config.api.values.ConfigSerializableObject; import org.quiltmc.enigma.gui.Gui; import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.docker.component.DockerButton; @@ -70,7 +72,8 @@ public DockerButton getButton() { * @return the position of the docker's button in the selector panels. this also represents where the docker will open when its button is clicked cannot use {@link Docker.VerticalLocation#FULL} */ public final Location getButtonLocation() { - return Config.dockers().getLocation(this.getId()); + Location savedLocation = Config.dockers().getLocation(this.getId()); + return savedLocation == null ? this.getPreferredButtonLocation() : savedLocation; } public abstract Location getPreferredButtonLocation(); @@ -103,10 +106,25 @@ public int hashCode() { * @param side the side of the screen, either right or left * @param verticalLocation the vertical location of the docker, being full, top or bottom */ - public record Location(Side side, VerticalLocation verticalLocation) { + public record Location(Side side, VerticalLocation verticalLocation) implements ConfigSerializableObject { @Override public String toString() { - return this.side.name().toLowerCase() + ";" + this.verticalLocation.name().toLowerCase(); + return this.side.name() + ";" + this.verticalLocation.name(); + } + + @Override + public ConfigSerializableObject convertFrom(String representation) { + return new Location(Side.valueOf(representation.split(";")[0]), VerticalLocation.valueOf(representation.split(";")[0])); + } + + @Override + public String getRepresentation() { + return this.toString(); + } + + @Override + public ComplexConfigValue copy() { + return this; } } From ffc84d99b0c72370c05d02635548543467fe97dd Mon Sep 17 00:00:00 2001 From: ix0rai Date: Sun, 3 Dec 2023 17:02:53 -0600 Subject: [PATCH 12/25] [mad scientist voice] it boots! --- .../main/java/org/quiltmc/enigma/gui/Gui.java | 4 ++- .../enigma/gui/config/DockerConfig.java | 30 +++++++++++-------- .../org/quiltmc/enigma/gui/docker/Docker.java | 2 +- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java index 6baacba53..89e8bb7f6 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java @@ -148,7 +148,9 @@ private void setupDockers() { this.dockerManager.registerDocker(new DeobfuscatedClassesDocker(this)); if (Config.dockers().dockerLocations.value().isEmpty()) { - Config.dockers().dockerLocations.value().setValue(DockerConfig.getDefaultLocations(this.dockerManager)); + for (var entry : DockerConfig.getDefaultLocations(this.dockerManager).entrySet()) { + Config.dockers().putLocation(entry.getKey(), entry.getValue()); + } } // set default docker sizes diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java index f344244da..ac1067549 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java @@ -3,6 +3,7 @@ import org.quiltmc.config.api.ReflectiveConfig; import org.quiltmc.config.api.values.TrackedValue; import org.quiltmc.config.api.values.ValueMap; +import org.quiltmc.enigma.gui.docker.AllClassesDocker; import org.quiltmc.enigma.gui.docker.CallsTreeDocker; import org.quiltmc.enigma.gui.docker.ClassesDocker; import org.quiltmc.enigma.gui.docker.CollabDocker; @@ -16,6 +17,7 @@ import org.quiltmc.enigma.gui.docker.StructureDocker; import javax.annotation.Nullable; +import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; @@ -28,6 +30,10 @@ public class DockerConfig extends ReflectiveConfig { public final TrackedValue> dockerLocations = this.map(new Docker.Location(Docker.Side.LEFT, Docker.VerticalLocation.TOP)).build(); + public void putLocation(Docker docker, Docker.Location location) { + this.putLocation(docker.getId(), location); + } + public void putLocation(String id, Docker.Location location) { this.dockerLocations.value().put(id, location); } @@ -69,23 +75,23 @@ public void setHorizontalDividerLocation(Docker.Side side, int value) { } } - public static TrackedValue> getDefaultLocations(DockerManager manager) { - DockerConfig defaultConfig = new DockerConfig(); + public static Map getDefaultLocations(DockerManager manager) { + Map locations = new HashMap<>(); // left - defaultConfig.putLocation(manager.getDocker(ObfuscatedClassesDocker.class), Docker.Side.LEFT, Docker.VerticalLocation.TOP); - defaultConfig.putLocation(manager.getDocker(ClassesDocker.class), Docker.Side.LEFT, Docker.VerticalLocation.TOP); - defaultConfig.putLocation(manager.getDocker(DeobfuscatedClassesDocker.class), Docker.Side.LEFT, Docker.VerticalLocation.BOTTOM); + locations.put(manager.getDocker(ObfuscatedClassesDocker.class), new Docker.Location(Docker.Side.LEFT, Docker.VerticalLocation.TOP)); + locations.put(manager.getDocker(AllClassesDocker.class), new Docker.Location(Docker.Side.LEFT, Docker.VerticalLocation.TOP)); + locations.put(manager.getDocker(DeobfuscatedClassesDocker.class), new Docker.Location(Docker.Side.LEFT, Docker.VerticalLocation.BOTTOM)); // right - defaultConfig.putLocation(manager.getDocker(StructureDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); - defaultConfig.putLocation(manager.getDocker(InheritanceTreeDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); - defaultConfig.putLocation(manager.getDocker(ImplementationsTreeDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); - defaultConfig.putLocation(manager.getDocker(CallsTreeDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.TOP); + locations.put(manager.getDocker(StructureDocker.class), new Docker.Location(Docker.Side.RIGHT, Docker.VerticalLocation.TOP)); + locations.put(manager.getDocker(InheritanceTreeDocker.class), new Docker.Location(Docker.Side.RIGHT, Docker.VerticalLocation.TOP)); + locations.put(manager.getDocker(ImplementationsTreeDocker.class), new Docker.Location(Docker.Side.RIGHT, Docker.VerticalLocation.TOP)); + locations.put(manager.getDocker(CallsTreeDocker.class), new Docker.Location(Docker.Side.RIGHT, Docker.VerticalLocation.TOP)); - defaultConfig.putLocation(manager.getDocker(CollabDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.BOTTOM); - defaultConfig.putLocation(manager.getDocker(NotificationsDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.BOTTOM); + locations.put(manager.getDocker(CollabDocker.class), new Docker.Location(Docker.Side.RIGHT, Docker.VerticalLocation.BOTTOM)); + locations.put(manager.getDocker(NotificationsDocker.class), new Docker.Location(Docker.Side.RIGHT, Docker.VerticalLocation.BOTTOM)); - return defaultConfig.dockerLocations; + return locations; } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java index 6140d7495..8696c2bce 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java @@ -114,7 +114,7 @@ public String toString() { @Override public ConfigSerializableObject convertFrom(String representation) { - return new Location(Side.valueOf(representation.split(";")[0]), VerticalLocation.valueOf(representation.split(";")[0])); + return new Location(Side.valueOf(representation.split(";")[0]), VerticalLocation.valueOf(representation.split(";")[1])); } @Override From da5b66152b55fd9cada17248f7ee2d1d1751cc26 Mon Sep 17 00:00:00 2001 From: ix0rai Date: Sun, 3 Dec 2023 17:44:41 -0600 Subject: [PATCH 13/25] check the style --- .../enigma/gui/config/DockerConfig.java | 1 - .../enigma/gui/config/theme/Theme.java | 59 +++++++++---------- .../quiltmc/enigma/gui/dialog/FontDialog.java | 7 ++- .../org/quiltmc/enigma/gui/docker/Docker.java | 2 + .../quiltmc/enigma/gui/util/ScaleUtil.java | 5 +- 5 files changed, 38 insertions(+), 36 deletions(-) diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java index ac1067549..9c86dd2c1 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java @@ -5,7 +5,6 @@ import org.quiltmc.config.api.values.ValueMap; import org.quiltmc.enigma.gui.docker.AllClassesDocker; import org.quiltmc.enigma.gui.docker.CallsTreeDocker; -import org.quiltmc.enigma.gui.docker.ClassesDocker; import org.quiltmc.enigma.gui.docker.CollabDocker; import org.quiltmc.enigma.gui.docker.DeobfuscatedClassesDocker; import org.quiltmc.enigma.gui.docker.Docker; diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java index 1600c9d15..df8a9f3e2 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java @@ -5,7 +5,6 @@ import org.quiltmc.config.api.values.ConfigSerializableObject; import org.quiltmc.config.api.values.TrackedValue; import org.quiltmc.config.api.values.ValueMap; -import org.quiltmc.enigma.gui.util.ScaleUtil; import java.awt.Color; import java.awt.Font; @@ -20,11 +19,11 @@ public Theme(LookAndFeel lookAndFeel) { public final Fonts fonts = new Fonts(); public static class Fonts extends ReflectiveConfig.Section { - public final TrackedValue defaultFont = this.value(new SerializableFont(Font.decode(Font.DIALOG).deriveFont(Font.BOLD))); - public final TrackedValue small = this.value(new SerializableFont(Font.decode(Font.DIALOG))); - public final TrackedValue editor = this.value(new SerializableFont(Font.decode(Font.MONOSPACED))); + public final TrackedValue defaultFont = this.value(new SerializableFont(Font.decode(Font.DIALOG).deriveFont(Font.BOLD))); + public final TrackedValue small = this.value(new SerializableFont(Font.decode(Font.DIALOG))); + public final TrackedValue editor = this.value(new SerializableFont(Font.decode(Font.MONOSPACED))); - private static class SerializableFont extends Font implements ConfigSerializableObject> { + public static class SerializableFont extends Font implements ConfigSerializableObject> { public SerializableFont(Font font) { this(font.getName(), font.getStyle(), font.getSize()); } @@ -59,41 +58,41 @@ public ComplexConfigValue copy() { } public static class Colors extends ReflectiveConfig.Section { - public final TrackedValue lineNumbersForeground = this.value(new SerializableColor(0xFF333300)); - public final TrackedValue lineNumbersBackground = this.value(new SerializableColor(0xFFEEEEFF)); - public final TrackedValue lineNumbersSelected = this.value(new SerializableColor(0xFFCCCCEE)); + public final TrackedValue lineNumbersForeground = this.value(new SerializableColor(0xFF333300)); + public final TrackedValue lineNumbersBackground = this.value(new SerializableColor(0xFFEEEEFF)); + public final TrackedValue lineNumbersSelected = this.value(new SerializableColor(0xFFCCCCEE)); - public final TrackedValue obfuscated = this.value(new SerializableColor(0xFFFFDCDC)); - public final TrackedValue obfuscatedOutline = this.value(new SerializableColor(0xFFA05050)); + public final TrackedValue obfuscated = this.value(new SerializableColor(0xFFFFDCDC)); + public final TrackedValue obfuscatedOutline = this.value(new SerializableColor(0xFFA05050)); - public final TrackedValue proposed = this.value(new SerializableColor(0xFF000000)); - public final TrackedValue proposedOutline = this.value(new SerializableColor(0xBF000000)); + public final TrackedValue proposed = this.value(new SerializableColor(0xFF000000)); + public final TrackedValue proposedOutline = this.value(new SerializableColor(0xBF000000)); - public final TrackedValue deobfuscated = this.value(new SerializableColor(0xFFDCFFDC)); - public final TrackedValue deobfuscatedOutline = this.value(new SerializableColor(0xFF50A050)); + public final TrackedValue deobfuscated = this.value(new SerializableColor(0xFFDCFFDC)); + public final TrackedValue deobfuscatedOutline = this.value(new SerializableColor(0xFF50A050)); - public final TrackedValue editorBackground = this.value(new SerializableColor(0xFF50A050)); - public final TrackedValue highlight = this.value(new SerializableColor(0xFF50A050)); - public final TrackedValue caret = this.value(new SerializableColor(0xFF50A050)); - public final TrackedValue selectionHighlight = this.value(new SerializableColor(0xFF50A050)); - public final TrackedValue string = this.value(new SerializableColor(0xFFCC6600)); - public final TrackedValue number = this.value(new SerializableColor(0xFF999933)); - public final TrackedValue operator = this.value(new SerializableColor(0xFF000000)); - public final TrackedValue delimiter = this.value(new SerializableColor(0xFF000000)); - public final TrackedValue type = this.value(new SerializableColor(0xFF000000)); - public final TrackedValue identifier = this.value(new SerializableColor(0xFF000000)); - public final TrackedValue comment = this.value(new SerializableColor(0xFF339933)); - public final TrackedValue text = this.value(new SerializableColor(0xFF000000)); + public final TrackedValue editorBackground = this.value(new SerializableColor(0xFF50A050)); + public final TrackedValue highlight = this.value(new SerializableColor(0xFF50A050)); + public final TrackedValue caret = this.value(new SerializableColor(0xFF50A050)); + public final TrackedValue selectionHighlight = this.value(new SerializableColor(0xFF50A050)); + public final TrackedValue string = this.value(new SerializableColor(0xFFCC6600)); + public final TrackedValue number = this.value(new SerializableColor(0xFF999933)); + public final TrackedValue operator = this.value(new SerializableColor(0xFF000000)); + public final TrackedValue delimiter = this.value(new SerializableColor(0xFF000000)); + public final TrackedValue type = this.value(new SerializableColor(0xFF000000)); + public final TrackedValue identifier = this.value(new SerializableColor(0xFF000000)); + public final TrackedValue comment = this.value(new SerializableColor(0xFF339933)); + public final TrackedValue text = this.value(new SerializableColor(0xFF000000)); - public final TrackedValue debugToken = this.value(new SerializableColor(0xFFD9BEF9)); - public final TrackedValue debugTokenOutline = this.value(new SerializableColor(0xFFBD93F9)); + public final TrackedValue debugToken = this.value(new SerializableColor(0xFFD9BEF9)); + public final TrackedValue debugTokenOutline = this.value(new SerializableColor(0xFFBD93F9)); - public final TrackedValue dockHighlight = this.value(new SerializableColor(0xFF0000FF)); + public final TrackedValue dockHighlight = this.value(new SerializableColor(0xFF0000FF)); private static class SerializableColor extends Color implements ConfigSerializableObject { private final int rgba; - public SerializableColor(int rgba) { + SerializableColor(int rgba) { super(rgba, true); this.rgba = rgba; } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java index b8b283a64..3e72bf1e1 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java @@ -2,6 +2,7 @@ import org.quiltmc.config.api.values.TrackedValue; import org.quiltmc.enigma.gui.config.Config; +import org.quiltmc.enigma.gui.config.theme.Theme; import org.quiltmc.enigma.gui.util.GridBagConstraintsBuilder; import org.quiltmc.enigma.gui.util.ScaleUtil; import org.quiltmc.enigma.util.I18n; @@ -20,7 +21,7 @@ import javax.swing.JList; public class FontDialog extends JDialog { - private static final List> FONTS = List.of( + private static final List> FONTS = List.of( Config.currentFonts().defaultFont, Config.currentFonts().small, Config.currentFonts().editor @@ -35,7 +36,7 @@ public class FontDialog extends JDialog { private final JList entries = new JList<>(CATEGORY_TEXTS.stream().map(I18n::translate).toArray(String[]::new)); private final FontChooser chooser = new FontChooser(Font.decode(Font.DIALOG)); private final JCheckBox customCheckBox = new JCheckBox(I18n.translate("fonts.use_custom")); - private final Font[] fontValues = new Font[]{FONTS.get(0).value(), FONTS.get(1).value(), FONTS.get(2).value()}; + private final Theme.Fonts.SerializableFont[] fontValues = new Theme.Fonts.SerializableFont[]{FONTS.get(0).value(), FONTS.get(1).value(), FONTS.get(2).value()}; public FontDialog(Frame owner) { super(owner, "Fonts", true); @@ -85,7 +86,7 @@ private void categoryChanged() { private void selectedFontChanged() { int selectedIndex = this.entries.getSelectedIndex(); if (selectedIndex != -1) { - this.fontValues[selectedIndex] = this.chooser.getSelectedFont(); + this.fontValues[selectedIndex] = new Theme.Fonts.SerializableFont(this.chooser.getSelectedFont()); } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java index 8696c2bce..a41d5d8c3 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java @@ -130,6 +130,7 @@ public ComplexConfigValue copy() { /** * Represents the side of the screen a docker is located on. + * @implNote these names cannot be changed without breaking configurations */ public enum Side { LEFT, @@ -138,6 +139,7 @@ public enum Side { /** * Represents the occupied vertical location of a docker. + * @implNote these names cannot be changed without breaking configurations */ public enum VerticalLocation { TOP, diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java index 9916e2e9d..fed605a1d 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java @@ -7,6 +7,7 @@ import com.github.swingdpi.plaf.WindowsTweaker; import org.quiltmc.config.api.values.TrackedValue; import org.quiltmc.enigma.gui.config.Config; +import org.quiltmc.enigma.gui.config.theme.Theme; import org.quiltmc.syntaxpain.SyntaxpainConfiguration; import java.awt.Dimension; @@ -55,8 +56,8 @@ public static Font scaleFont(Font font) { return createTweakerForCurrentLook(Config.get().scaleFactor.value()).modifyFont("", font); } - private static void rescaleFontInConfig(TrackedValue font, float oldScale) { - font.setValue(rescaleFont(font.value(), oldScale), true); + private static void rescaleFontInConfig(TrackedValue font, float oldScale) { + font.setValue(new Theme.Fonts.SerializableFont(rescaleFont(font.value(), oldScale)), true); } // This does not use the font that's currently active in the UI! From cd9a80d6f6f761a7979c9b3a09805d1b6070d8b9 Mon Sep 17 00:00:00 2001 From: ix0rai Date: Sun, 3 Dec 2023 18:14:13 -0600 Subject: [PATCH 14/25] some refactors --- .../org/quiltmc/enigma/gui/config/Config.java | 25 +++++++++---------- ...KeyBindsConfig.java => KeyBindConfig.java} | 2 +- .../enigma/gui/config/theme/Themes.java | 1 + 3 files changed, 14 insertions(+), 14 deletions(-) rename enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/{KeyBindsConfig.java => KeyBindConfig.java} (92%) diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java index e84695e8c..fd027751a 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java @@ -23,16 +23,15 @@ import java.nio.file.Paths; public final class Config extends ReflectiveConfig { - private static final ConfigEnvironment ENVIRONMENT = new ConfigEnvironment(ConfigPaths.getConfigPathRoot(), "toml", new NightConfigSerializer<>("toml", new TomlParser(), new TomlWriter())); - private static final Config MAIN = ConfigFactory.create(ENVIRONMENT, "enigma", "main", Config.class); - private static final KeyBindsConfig KEYBINDS = ConfigFactory.create(ENVIRONMENT, "enigma", "keybinds", KeyBindsConfig.class); - private static final NetConfig NET = ConfigFactory.create(ENVIRONMENT, "enigma", "net", NetConfig.class); - private static final DockerConfig DOCKER = ConfigFactory.create(ENVIRONMENT, "enigma", "docker", DockerConfig.class); - private static final DecompilerConfig DECOMPILER = ConfigFactory.create(ENVIRONMENT, "enigma", "decompiler", DecompilerConfig.class); - - public Config() { - //updateSyntaxpain(); - } + private static final String FORMAT = "toml"; + private static final String FAMILY = "enigma"; + + private static final ConfigEnvironment ENVIRONMENT = new ConfigEnvironment(ConfigPaths.getConfigPathRoot(), FORMAT, new NightConfigSerializer<>(FORMAT, new TomlParser(), new TomlWriter())); + private static final Config MAIN = ConfigFactory.create(ENVIRONMENT, FAMILY, "main", Config.class); + private static final KeyBindConfig KEYBIND = ConfigFactory.create(ENVIRONMENT, FAMILY, "keybind", KeyBindConfig.class); + private static final NetConfig NET = ConfigFactory.create(ENVIRONMENT, FAMILY, "net", NetConfig.class); + private static final DockerConfig DOCKER = ConfigFactory.create(ENVIRONMENT, FAMILY, "docker", DockerConfig.class); + private static final DecompilerConfig DECOMPILER = ConfigFactory.create(ENVIRONMENT, FAMILY, "decompiler", DecompilerConfig.class); public final TrackedValue language = this.value(I18n.DEFAULT_LANGUAGE); public final TrackedValue scaleFactor = this.value(1.0f); @@ -64,8 +63,8 @@ public static DockerConfig dockers() { return DOCKER; } - public static KeyBindsConfig keyBinds() { - return KEYBINDS; + public static KeyBindConfig keyBinds() { + return KEYBIND; } public static NetConfig net() { @@ -169,7 +168,7 @@ public ComplexConfigValue copy() { /** * Updates the backend library Syntaxpain, used for code highlighting and other editor things. */ - private static void updateSyntaxpain() { + public static void updateSyntaxpain() { Theme.Fonts fonts = currentFonts(); Theme.Colors colors = currentColors(); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindsConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindConfig.java similarity index 92% rename from enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindsConfig.java rename to enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindConfig.java index 94a1798bf..e777d5757 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindsConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindConfig.java @@ -6,7 +6,7 @@ import org.quiltmc.config.api.values.ValueMap; import org.quiltmc.enigma.gui.config.keybind.KeyBind; -public final class KeyBindsConfig extends ReflectiveConfig { +public final class KeyBindConfig extends ReflectiveConfig { public final TrackedValue>> keyCodes = this.map(ValueList.create("")).build(); public String[] getKeyCodes(KeyBind keyBind) { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java index ba8965ad0..ad1dbe99a 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java @@ -29,6 +29,7 @@ public static void setupTheme() { Map boxHighlightPainters = getBoxHighlightPainters(); listeners.forEach(l -> l.onThemeChanged(laf, boxHighlightPainters)); ScaleUtil.applyScaling(); + Config.updateSyntaxpain(); } private static void setFonts() { From 60689840bd705b5b26897095b70c18745b396906 Mon Sep 17 00:00:00 2001 From: ix0rai Date: Tue, 5 Dec 2023 21:38:54 -0600 Subject: [PATCH 15/25] more reorg --- .../quiltmc/enigma/gui/config/Decompiler.java | 4 --- .../enigma/gui/config/DecompilerConfig.java | 26 +++++++++---------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Decompiler.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Decompiler.java index 690b93648..e66af2967 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Decompiler.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Decompiler.java @@ -27,8 +27,4 @@ public enum Decompiler { this.service = service; this.settingsDialog = settingsDialog; } - - static { - DecompilerConfig.bootstrap(); - } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java index 948d2e8ec..0736ac716 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java @@ -9,29 +9,29 @@ public class DecompilerConfig extends ReflectiveConfig { public DecompilerConfig() { - VineflowerPreferences.OPTIONS.putAll(this.stringValues.value()); - VineflowerPreferences.OPTIONS.putAll(this.intValues.value()); - VineflowerPreferences.OPTIONS.putAll(this.booleanValues.value()); + VineflowerPreferences.OPTIONS.putAll(this.vineflowerSection.stringValues.value()); + VineflowerPreferences.OPTIONS.putAll(this.vineflowerSection.intValues.value()); + VineflowerPreferences.OPTIONS.putAll(this.vineflowerSection.booleanValues.value()); } public final TrackedValue decompiler = this.value(Decompiler.VINEFLOWER); - public final TrackedValue> stringValues = this.map("").build(); - public final TrackedValue> intValues = this.map(0).build(); - public final TrackedValue> booleanValues = this.map(true).build(); + public final VineflowerSection vineflowerSection = new VineflowerSection(); + + public static final class VineflowerSection extends Section { + public final TrackedValue> stringValues = this.map("").build(); + public final TrackedValue> intValues = this.map(0).build(); + public final TrackedValue> booleanValues = this.map(true).build(); + } public static void updateVineflowerValues(Map options) { for (Map.Entry entry : options.entrySet()) { if (entry.getValue() instanceof String s) { - Config.decompiler().stringValues.value().put(entry.getKey(), s); + Config.decompiler().vineflowerSection.stringValues.value().put(entry.getKey(), s); } else if (entry.getValue() instanceof Integer i) { - Config.decompiler().intValues.value().put(entry.getKey(), i); + Config.decompiler().vineflowerSection.intValues.value().put(entry.getKey(), i); } else if (entry.getValue() instanceof Boolean b) { - Config.decompiler().booleanValues.value().put(entry.getKey(), b); + Config.decompiler().vineflowerSection.booleanValues.value().put(entry.getKey(), b); } } } - - public static void bootstrap() { - // Just run the static initialization - } } From 677236fc8b83beeca16804d5db13ae733be409c1 Mon Sep 17 00:00:00 2001 From: ix0rai Date: Wed, 6 Dec 2023 22:35:15 -0600 Subject: [PATCH 16/25] tentative update to new qconf --- .../org/quiltmc/enigma/gui/GuiController.java | 4 +- .../org/quiltmc/enigma/gui/config/Config.java | 25 ++- .../enigma/gui/config/DecompilerConfig.java | 22 ++- .../enigma/gui/config/DockerConfig.java | 7 + .../enigma/gui/config/KeyBindConfig.java | 2 + .../quiltmc/enigma/gui/config/NetConfig.java | 6 + .../gui/config/NightConfigSerializer.java | 147 ------------------ .../enigma/gui/config/StatsSection.java | 14 ++ .../enigma/gui/config/theme/Theme.java | 31 +++- .../enigma/gui/dialog/StatsDialog.java | 14 +- .../quiltmc/enigma/gui/element/MenuBar.java | 24 +-- 11 files changed, 113 insertions(+), 183 deletions(-) delete mode 100644 enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NightConfigSerializer.java create mode 100644 enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/StatsSection.java diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java index a36bfcb9d..b455fe1b5 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java @@ -124,7 +124,7 @@ public CompletableFuture openJar(final Path jarPath) { return ProgressDialog.runOffThread(this.gui, progress -> { this.project = this.enigma.openJar(jarPath, new ClasspathClassProvider(), progress); this.indexTreeBuilder = new IndexTreeBuilder(this.project.getJarIndex()); - this.chp = new ClassHandleProvider(this.project, Config.decompiler().decompiler.value().service); + this.chp = new ClassHandleProvider(this.project, Config.decompiler().activeDecompiler.value().service); this.statsGenerator = new StatsGenerator(this.project); SwingUtilities.invokeLater(() -> { @@ -556,7 +556,7 @@ private void applyChange0(ValidationContext vc, EntryChange change, boolean u public void openStatsTree(Set includedTypes) { ProgressDialog.runOffThread(this.gui, progress -> { StatsResult overall = this.getStatsGenerator().getResultNullable().getOverall(); - StatsTree tree = overall.buildTree(Config.get().lastTopLevelPackage.value(), includedTypes); + StatsTree tree = overall.buildTree(Config.get().stats.lastTopLevelPackage.value(), includedTypes); String treeJson = GSON.toJson(tree.root); try { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java index fd027751a..828aeb3b8 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java @@ -1,8 +1,8 @@ package org.quiltmc.enigma.gui.config; -import com.electronwill.nightconfig.toml.TomlParser; -import com.electronwill.nightconfig.toml.TomlWriter; import org.quiltmc.config.api.ReflectiveConfig; +import org.quiltmc.config.api.annotations.SerializedName; +import org.quiltmc.config.api.serializer.TomlSerializer; import org.quiltmc.config.api.values.ComplexConfigValue; import org.quiltmc.config.api.values.ConfigSerializableObject; import org.quiltmc.config.api.values.TrackedValue; @@ -26,33 +26,46 @@ public final class Config extends ReflectiveConfig { private static final String FORMAT = "toml"; private static final String FAMILY = "enigma"; - private static final ConfigEnvironment ENVIRONMENT = new ConfigEnvironment(ConfigPaths.getConfigPathRoot(), FORMAT, new NightConfigSerializer<>(FORMAT, new TomlParser(), new TomlWriter())); + private static final ConfigEnvironment ENVIRONMENT = new ConfigEnvironment(ConfigPaths.getConfigPathRoot(), FORMAT, new TomlSerializer()); private static final Config MAIN = ConfigFactory.create(ENVIRONMENT, FAMILY, "main", Config.class); private static final KeyBindConfig KEYBIND = ConfigFactory.create(ENVIRONMENT, FAMILY, "keybind", KeyBindConfig.class); private static final NetConfig NET = ConfigFactory.create(ENVIRONMENT, FAMILY, "net", NetConfig.class); private static final DockerConfig DOCKER = ConfigFactory.create(ENVIRONMENT, FAMILY, "docker", DockerConfig.class); private static final DecompilerConfig DECOMPILER = ConfigFactory.create(ENVIRONMENT, FAMILY, "decompiler", DecompilerConfig.class); + @SerializedName("language") public final TrackedValue language = this.value(I18n.DEFAULT_LANGUAGE); + @SerializedName("scale_factor") public final TrackedValue scaleFactor = this.value(1.0f); + @SerializedName("max_recent_files") public final TrackedValue maxRecentFiles = this.value(10); + @SerializedName("recent_projects") public final TrackedValue> recentProjects = this.list(new RecentProject("", "")); + @SerializedName("server_notification_level") public final TrackedValue serverNotificationLevel = this.value(NotificationManager.ServerNotificationLevel.FULL); + @SerializedName("use_custom_fonts") public final TrackedValue useCustomFonts = this.value(false); + @SerializedName("window_size") public final TrackedValue windowSize = this.value(new Vec2i(1024, 576)); + @SerializedName("window_pos") public final TrackedValue windowPos = this.value(new Vec2i(0, 0)); - public final TrackedValue lastSelectedDir = this.value(""); - public final TrackedValue lastTopLevelPackage = this.value(""); - public final TrackedValue shouldIncludeSyntheticParameters = this.value(false); + public final StatsSection stats = new StatsSection(); + + @SerializedName("look_and_feel") public final TrackedValue lookAndFeel = this.value(LookAndFeel.DEFAULT); // todo laf can't be changed while running public final transient LookAndFeel activeLookAndFeel = this.lookAndFeel.value(); + @SerializedName("default_theme") public final Theme defaultTheme = new Theme(LookAndFeel.DEFAULT); + @SerializedName("darcula_theme") public final Theme darculaTheme = new Theme(LookAndFeel.DARCULA); + @SerializedName("metal_theme") public final Theme metalTheme = new Theme(LookAndFeel.METAL); + @SerializedName("system_theme") public final Theme systemTheme = new Theme(LookAndFeel.SYSTEM); + @SerializedName("none_theme") public final Theme noneTheme = new Theme(LookAndFeel.NONE); public static Config get() { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java index 0736ac716..0d88fa2e7 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java @@ -1,6 +1,7 @@ package org.quiltmc.enigma.gui.config; import org.quiltmc.config.api.ReflectiveConfig; +import org.quiltmc.config.api.annotations.SerializedName; import org.quiltmc.config.api.values.TrackedValue; import org.quiltmc.config.api.values.ValueMap; import org.quiltmc.enigma.impl.source.vineflower.VineflowerPreferences; @@ -9,28 +10,33 @@ public class DecompilerConfig extends ReflectiveConfig { public DecompilerConfig() { - VineflowerPreferences.OPTIONS.putAll(this.vineflowerSection.stringValues.value()); - VineflowerPreferences.OPTIONS.putAll(this.vineflowerSection.intValues.value()); - VineflowerPreferences.OPTIONS.putAll(this.vineflowerSection.booleanValues.value()); + VineflowerPreferences.OPTIONS.putAll(this.vineflower.stringValues.value()); + VineflowerPreferences.OPTIONS.putAll(this.vineflower.intValues.value()); + VineflowerPreferences.OPTIONS.putAll(this.vineflower.booleanValues.value()); } - public final TrackedValue decompiler = this.value(Decompiler.VINEFLOWER); - public final VineflowerSection vineflowerSection = new VineflowerSection(); + @SerializedName("active_decompiler") + public final TrackedValue activeDecompiler = this.value(Decompiler.VINEFLOWER); + public final VineflowerSection vineflower = new VineflowerSection(); public static final class VineflowerSection extends Section { + @SerializedName("string_values") + public final TrackedValue> stringValues = this.map("").build(); + @SerializedName("int_values") public final TrackedValue> intValues = this.map(0).build(); + @SerializedName("boolean_values") public final TrackedValue> booleanValues = this.map(true).build(); } public static void updateVineflowerValues(Map options) { for (Map.Entry entry : options.entrySet()) { if (entry.getValue() instanceof String s) { - Config.decompiler().vineflowerSection.stringValues.value().put(entry.getKey(), s); + Config.decompiler().vineflower.stringValues.value().put(entry.getKey(), s); } else if (entry.getValue() instanceof Integer i) { - Config.decompiler().vineflowerSection.intValues.value().put(entry.getKey(), i); + Config.decompiler().vineflower.intValues.value().put(entry.getKey(), i); } else if (entry.getValue() instanceof Boolean b) { - Config.decompiler().vineflowerSection.booleanValues.value().put(entry.getKey(), b); + Config.decompiler().vineflower.booleanValues.value().put(entry.getKey(), b); } } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java index 9c86dd2c1..4c32793c8 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java @@ -1,6 +1,7 @@ package org.quiltmc.enigma.gui.config; import org.quiltmc.config.api.ReflectiveConfig; +import org.quiltmc.config.api.annotations.SerializedName; import org.quiltmc.config.api.values.TrackedValue; import org.quiltmc.config.api.values.ValueMap; import org.quiltmc.enigma.gui.docker.AllClassesDocker; @@ -21,12 +22,18 @@ import java.util.stream.Collectors; public class DockerConfig extends ReflectiveConfig { + @SerializedName("left_vertical_divider_location") public final TrackedValue leftVerticalDividerLocation = this.value(300); + @SerializedName("right_vertical_divider_location") public final TrackedValue rightVerticalDividerLocation = this.value(300); + @SerializedName("left_horizontal_divider_location") public final TrackedValue leftHorizontalDividerLocation = this.value(300); + @SerializedName("right_horizontal_divider_location") public final TrackedValue rightHorizontalDividerLocation = this.value(700); + @SerializedName("saved_with_left_docker_open") public final TrackedValue savedWithLeftDockerOpen = this.value(true); + @SerializedName("docker_locations") public final TrackedValue> dockerLocations = this.map(new Docker.Location(Docker.Side.LEFT, Docker.VerticalLocation.TOP)).build(); public void putLocation(Docker docker, Docker.Location location) { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindConfig.java index e777d5757..b11771d31 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindConfig.java @@ -1,12 +1,14 @@ package org.quiltmc.enigma.gui.config; import org.quiltmc.config.api.ReflectiveConfig; +import org.quiltmc.config.api.annotations.SerializedName; import org.quiltmc.config.api.values.TrackedValue; import org.quiltmc.config.api.values.ValueList; import org.quiltmc.config.api.values.ValueMap; import org.quiltmc.enigma.gui.config.keybind.KeyBind; public final class KeyBindConfig extends ReflectiveConfig { + @SerializedName("key_codes") public final TrackedValue>> keyCodes = this.map(ValueList.create("")).build(); public String[] getKeyCodes(KeyBind keyBind) { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NetConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NetConfig.java index 8b37eb287..79033043d 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NetConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NetConfig.java @@ -1,13 +1,19 @@ package org.quiltmc.enigma.gui.config; import org.quiltmc.config.api.ReflectiveConfig; +import org.quiltmc.config.api.annotations.SerializedName; import org.quiltmc.config.api.values.TrackedValue; import org.quiltmc.enigma.network.EnigmaServer; public final class NetConfig extends ReflectiveConfig { + @SerializedName("username") public final TrackedValue username = this.value(System.getProperty("user.name", "user")); + @SerializedName("password") public final TrackedValue password = this.value(""); + @SerializedName("remote_address") public final TrackedValue remoteAddress = this.value(""); + @SerializedName("server_password") public final TrackedValue serverPassword = this.value(""); + @SerializedName("server_port") public final TrackedValue serverPort = this.value(EnigmaServer.DEFAULT_PORT); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NightConfigSerializer.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NightConfigSerializer.java deleted file mode 100644 index 4553a5c68..000000000 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NightConfigSerializer.java +++ /dev/null @@ -1,147 +0,0 @@ -package org.quiltmc.enigma.gui.config; - -import com.electronwill.nightconfig.core.CommentedConfig; -import com.electronwill.nightconfig.core.InMemoryCommentedFormat; -import com.electronwill.nightconfig.core.UnmodifiableCommentedConfig; -import com.electronwill.nightconfig.core.io.ConfigParser; -import com.electronwill.nightconfig.core.io.ConfigWriter; -import org.quiltmc.config.api.Config; -import org.quiltmc.config.api.Constraint; -import org.quiltmc.config.api.MarshallingUtils; -import org.quiltmc.config.api.Serializer; -import org.quiltmc.config.api.annotations.Comment; -import org.quiltmc.config.api.values.CompoundConfigValue; -import org.quiltmc.config.api.values.ConfigSerializableObject; -import org.quiltmc.config.api.values.TrackedValue; -import org.quiltmc.config.api.values.ValueList; -import org.quiltmc.config.api.values.ValueMap; -import org.quiltmc.config.api.values.ValueTreeNode; - -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -public final class NightConfigSerializer implements Serializer { - private final String fileExtension; - private final ConfigParser parser; - private final ConfigWriter writer; - - public NightConfigSerializer(String fileExtension, ConfigParser parser, ConfigWriter writer) { - this.fileExtension = fileExtension; - this.parser = parser; - this.writer = writer; - } - - @Override - public String getFileExtension() { - return this.fileExtension; - } - - @Override - public void serialize(Config config, OutputStream to) { - this.writer.write(write(createCommentedConfig(), config.nodes()), to); - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - @Override - public void deserialize(Config config, InputStream from) { - CommentedConfig read = this.parser.parse(from); - - for (TrackedValue trackedValue : config.values()) { - if (read.contains(trackedValue.key().toString())) { - ((TrackedValue) trackedValue).setValue(MarshallingUtils.coerce(read.get(trackedValue.key().toString()), trackedValue.getDefaultValue(), (CommentedConfig c, MarshallingUtils.MapEntryConsumer entryConsumer) -> - c.entrySet().forEach(e -> entryConsumer.put(e.getKey(), e.getValue()))), false); - } - } - } - - private static List convertList(List list) { - List result = new ArrayList<>(list.size()); - - for (Object value : list) { - result.add(convertAny(value)); - } - - return result; - } - - private static UnmodifiableCommentedConfig convertMap(ValueMap map) { - CommentedConfig result = createCommentedConfig(); - - for (Map.Entry entry : map.entrySet()) { - result.add(entry.getKey(), convertAny(entry.getValue())); - } - - return result; - } - - private static Object convertAny(Object value) { - if (value instanceof ValueMap) { - return convertMap((ValueMap) value); - } else if (value instanceof ValueList) { - return convertList((ValueList) value); - } else if (value instanceof ConfigSerializableObject) { - return convertAny(((ConfigSerializableObject) value).getRepresentation()); - } else { - return value; - } - } - - private static CommentedConfig write(CommentedConfig config, Iterable nodes) { - for (ValueTreeNode node : nodes) { - List comments = new ArrayList<>(); - - if (node.hasMetadata(Comment.TYPE)) { - for (String string : node.metadata(Comment.TYPE)) { - comments.add(string); - } - } - - if (node instanceof TrackedValue trackedValue) { - Object defaultValue = trackedValue.getDefaultValue(); - - if (defaultValue.getClass().isEnum()) { - StringBuilder options = new StringBuilder("options: "); - Object[] enumConstants = defaultValue.getClass().getEnumConstants(); - - for (int i = 0, enumConstantsLength = enumConstants.length; i < enumConstantsLength; i++) { - Object o = enumConstants[i]; - - options.append(o); - - if (i < enumConstantsLength - 1) { - options.append(", "); - } - } - - comments.add(options.toString()); - } - - for (Constraint constraint : trackedValue.constraints()) { - comments.add(constraint.getRepresentation()); - } - - if (!(defaultValue instanceof CompoundConfigValue)) { - comments.add("default: " + defaultValue); - } - - config.add(trackedValue.key().toString(), convertAny(trackedValue.getRealValue())); - } else { - write(config, ((ValueTreeNode.Section) node)); - } - - if (!comments.isEmpty()) { - config.setComment(node.key().toString(), " " + String.join("\n ", comments)); - } - } - - return config; - } - - private static CommentedConfig createCommentedConfig() { - return InMemoryCommentedFormat.defaultInstance().createConfig(LinkedHashMap::new); - } -} diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/StatsSection.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/StatsSection.java new file mode 100644 index 000000000..40e4ffc41 --- /dev/null +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/StatsSection.java @@ -0,0 +1,14 @@ +package org.quiltmc.enigma.gui.config; + +import org.quiltmc.config.api.ReflectiveConfig; +import org.quiltmc.config.api.annotations.SerializedName; +import org.quiltmc.config.api.values.TrackedValue; + +public class StatsSection extends ReflectiveConfig.Section { + @SerializedName("last_selected_dir") + public final TrackedValue lastSelectedDir = this.value(""); + @SerializedName("last_top_level_package") + public final TrackedValue lastTopLevelPackage = this.value(""); + @SerializedName("should_include_synthetic_parameters") + public final TrackedValue shouldIncludeSyntheticParameters = this.value(false); +} diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java index df8a9f3e2..49447030d 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java @@ -1,6 +1,7 @@ package org.quiltmc.enigma.gui.config.theme; import org.quiltmc.config.api.ReflectiveConfig; +import org.quiltmc.config.api.annotations.SerializedName; import org.quiltmc.config.api.values.ComplexConfigValue; import org.quiltmc.config.api.values.ConfigSerializableObject; import org.quiltmc.config.api.values.TrackedValue; @@ -15,12 +16,17 @@ public Theme(LookAndFeel lookAndFeel) { this.lookAndFeel = lookAndFeel; } + @SerializedName("colors") public final Colors colors = new Colors(); + @SerializedName("fonts") public final Fonts fonts = new Fonts(); public static class Fonts extends ReflectiveConfig.Section { + @SerializedName("default") public final TrackedValue defaultFont = this.value(new SerializableFont(Font.decode(Font.DIALOG).deriveFont(Font.BOLD))); + @SerializedName("small") public final TrackedValue small = this.value(new SerializableFont(Font.decode(Font.DIALOG))); + @SerializedName("editor") public final TrackedValue editor = this.value(new SerializableFont(Font.decode(Font.MONOSPACED))); public static class SerializableFont extends Font implements ConfigSerializableObject> { @@ -58,35 +64,58 @@ public ComplexConfigValue copy() { } public static class Colors extends ReflectiveConfig.Section { + @SerializedName("line_numbers_foreground") public final TrackedValue lineNumbersForeground = this.value(new SerializableColor(0xFF333300)); + @SerializedName("line_numbers_background") public final TrackedValue lineNumbersBackground = this.value(new SerializableColor(0xFFEEEEFF)); + @SerializedName("line_numbers_selected") public final TrackedValue lineNumbersSelected = this.value(new SerializableColor(0xFFCCCCEE)); - + @SerializedName("obfuscated") public final TrackedValue obfuscated = this.value(new SerializableColor(0xFFFFDCDC)); + @SerializedName("obfuscated_outline") public final TrackedValue obfuscatedOutline = this.value(new SerializableColor(0xFFA05050)); + @SerializedName("proposed") public final TrackedValue proposed = this.value(new SerializableColor(0xFF000000)); + @SerializedName("proposed_outline") public final TrackedValue proposedOutline = this.value(new SerializableColor(0xBF000000)); + @SerializedName("deobfuscated") public final TrackedValue deobfuscated = this.value(new SerializableColor(0xFFDCFFDC)); + @SerializedName("deobfuscated_outline") public final TrackedValue deobfuscatedOutline = this.value(new SerializableColor(0xFF50A050)); + @SerializedName("editor_background") public final TrackedValue editorBackground = this.value(new SerializableColor(0xFF50A050)); + @SerializedName("highlight") public final TrackedValue highlight = this.value(new SerializableColor(0xFF50A050)); + @SerializedName("caret") public final TrackedValue caret = this.value(new SerializableColor(0xFF50A050)); + @SerializedName("selection_highlight") public final TrackedValue selectionHighlight = this.value(new SerializableColor(0xFF50A050)); + @SerializedName("string") public final TrackedValue string = this.value(new SerializableColor(0xFFCC6600)); + @SerializedName("number") public final TrackedValue number = this.value(new SerializableColor(0xFF999933)); + @SerializedName("operator") public final TrackedValue operator = this.value(new SerializableColor(0xFF000000)); + @SerializedName("delimiter") public final TrackedValue delimiter = this.value(new SerializableColor(0xFF000000)); + @SerializedName("type") public final TrackedValue type = this.value(new SerializableColor(0xFF000000)); + @SerializedName("identifier") public final TrackedValue identifier = this.value(new SerializableColor(0xFF000000)); + @SerializedName("comment") public final TrackedValue comment = this.value(new SerializableColor(0xFF339933)); + @SerializedName("text") public final TrackedValue text = this.value(new SerializableColor(0xFF000000)); + @SerializedName("debug_token") public final TrackedValue debugToken = this.value(new SerializableColor(0xFFD9BEF9)); + @SerializedName("debug_token_outline") public final TrackedValue debugTokenOutline = this.value(new SerializableColor(0xFFBD93F9)); + @SerializedName("dock_highlight") public final TrackedValue dockHighlight = this.value(new SerializableColor(0xFF0000FF)); private static class SerializableColor extends Color implements ConfigSerializableObject { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/StatsDialog.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/StatsDialog.java index 6e61ee25e..946944a5e 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/StatsDialog.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/StatsDialog.java @@ -65,12 +65,12 @@ public static void show(Gui gui, ProjectStatsResult result, String packageName) contentPane.add(topLevelPackageOption, cb1.pos(0, result.getOverall().getTypes().size() + 1).build()); JTextField topLevelPackage = new JTextField(); - topLevelPackage.setText(Config.get().lastTopLevelPackage.value()); + topLevelPackage.setText(Config.get().stats.lastTopLevelPackage.value()); contentPane.add(topLevelPackage, cb1.pos(0, result.getOverall().getTypes().size() + 2).fill(GridBagConstraints.HORIZONTAL).build()); // show synthetic members option JCheckBox syntheticParametersOption = new JCheckBox(I18n.translate("menu.file.stats.synthetic_parameters")); - syntheticParametersOption.setSelected(Config.get().shouldIncludeSyntheticParameters.value()); + syntheticParametersOption.setSelected(Config.get().stats.shouldIncludeSyntheticParameters.value()); contentPane.add(syntheticParametersOption, cb1.pos(0, result.getOverall().getTypes().size() + 4).build()); // show filter button @@ -78,10 +78,10 @@ public static void show(Gui gui, ProjectStatsResult result, String packageName) filterButton.addActionListener(action -> { dialog.dispose(); ProgressDialog.runOffThread(gui, listener -> { - Config.get().lastTopLevelPackage.setValue(topLevelPackage.getText(), true); + Config.get().stats.lastTopLevelPackage.setValue(topLevelPackage.getText(), true); - ProjectStatsResult projectResult = gui.getController().getStatsGenerator().getResult(syntheticParametersOption.isSelected()).filter(Config.get().lastTopLevelPackage.value()); - SwingUtilities.invokeLater(() -> show(gui, projectResult, Config.get().lastTopLevelPackage.value())); + ProjectStatsResult projectResult = gui.getController().getStatsGenerator().getResult(syntheticParametersOption.isSelected()).filter(Config.get().stats.lastTopLevelPackage.value()); + SwingUtilities.invokeLater(() -> show(gui, projectResult, Config.get().stats.lastTopLevelPackage.value())); }); }); contentPane.add(filterButton, cb1.pos(0, result.getOverall().getTypes().size() + 3).anchor(GridBagConstraints.EAST).build()); @@ -92,8 +92,8 @@ public static void show(Gui gui, ProjectStatsResult result, String packageName) button.addActionListener(action -> { dialog.dispose(); - Config.get().lastTopLevelPackage.setValue(topLevelPackage.getText(), true); - Config.get().shouldIncludeSyntheticParameters.setValue(syntheticParametersOption.isSelected(), true); + Config.get().stats.lastTopLevelPackage.setValue(topLevelPackage.getText(), true); + Config.get().stats.shouldIncludeSyntheticParameters.setValue(syntheticParametersOption.isSelected(), true); generateStats(gui, checkboxes); }); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java index 713f0f856..77b07d87d 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java @@ -274,7 +274,7 @@ public void retranslateUi() { private void onOpenJarClicked() { JFileChooser d = this.gui.jarFileChooser; - d.setCurrentDirectory(new File(Config.get().lastSelectedDir.value())); + d.setCurrentDirectory(new File(Config.get().stats.lastSelectedDir.value())); d.setVisible(true); int result = d.showOpenDialog(this.gui.getFrame()); @@ -291,7 +291,7 @@ private void onOpenJarClicked() { this.gui.getController().openJar(path); } - Config.get().lastSelectedDir.setValue(d.getCurrentDirectory().getAbsolutePath(), true); + Config.get().stats.lastSelectedDir.setValue(d.getCurrentDirectory().getAbsolutePath(), true); } } @@ -345,15 +345,15 @@ private void onReloadAllClicked() { } private void onExportSourceClicked() { - this.gui.exportSourceFileChooser.setCurrentDirectory(new File(Config.get().lastSelectedDir.value())); + this.gui.exportSourceFileChooser.setCurrentDirectory(new File(Config.get().stats.lastSelectedDir.value())); if (this.gui.exportSourceFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { - Config.get().lastSelectedDir.setValue(this.gui.exportSourceFileChooser.getCurrentDirectory().toString(), true); + Config.get().stats.lastSelectedDir.setValue(this.gui.exportSourceFileChooser.getCurrentDirectory().toString(), true); this.gui.getController().exportSource(this.gui.exportSourceFileChooser.getSelectedFile().toPath()); } } private void onExportJarClicked() { - this.gui.exportJarFileChooser.setCurrentDirectory(new File(Config.get().lastSelectedDir.value())); + this.gui.exportJarFileChooser.setCurrentDirectory(new File(Config.get().stats.lastSelectedDir.value())); this.gui.exportJarFileChooser.setVisible(true); int result = this.gui.exportJarFileChooser.showSaveDialog(this.gui.getFrame()); @@ -364,7 +364,7 @@ private void onExportJarClicked() { if (this.gui.exportJarFileChooser.getSelectedFile() != null) { Path path = this.gui.exportJarFileChooser.getSelectedFile().toPath(); this.gui.getController().exportJar(path); - Config.get().lastSelectedDir.setValue(this.gui.exportJarFileChooser.getCurrentDirectory().getAbsolutePath(), true); + Config.get().stats.lastSelectedDir.setValue(this.gui.exportJarFileChooser.getCurrentDirectory().getAbsolutePath(), true); } } @@ -457,10 +457,10 @@ private void onGithubClicked() { } private void onOpenMappingsClicked() { - this.gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(Config.get().lastSelectedDir.value())); + this.gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(Config.get().stats.lastSelectedDir.value())); if (this.gui.enigmaMappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { File selectedFile = this.gui.enigmaMappingsFileChooser.getSelectedFile(); - Config.get().lastSelectedDir.setValue(this.gui.enigmaMappingsFileChooser.getCurrentDirectory().toString(), true); + Config.get().stats.lastSelectedDir.setValue(this.gui.enigmaMappingsFileChooser.getCurrentDirectory().toString(), true); MappingFormat format = MappingFormat.parseFromFile(selectedFile.toPath()); if (format.getReader() != null) { @@ -539,13 +539,13 @@ private static void prepareSaveMappingsAsMenu(JMenu saveMappingsAsMenu, JMenuIte item.addActionListener(event -> { // TODO: Use a specific file chooser for it if (gui.enigmaMappingsFileChooser.getCurrentDirectory() == null) { - gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(Config.get().lastSelectedDir.value())); + gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(Config.get().stats.lastSelectedDir.value())); } if (gui.enigmaMappingsFileChooser.showSaveDialog(gui.getFrame()) == JFileChooser.APPROVE_OPTION) { gui.getController().saveMappings(gui.enigmaMappingsFileChooser.getSelectedFile().toPath(), format); saveMappingsItem.setEnabled(true); - Config.get().lastSelectedDir.setValue(gui.enigmaMappingsFileChooser.getCurrentDirectory().toString(), true); + Config.get().stats.lastSelectedDir.setValue(gui.enigmaMappingsFileChooser.getCurrentDirectory().toString(), true); } }); saveMappingsAsMenu.add(item); @@ -559,14 +559,14 @@ private static void prepareDecompilerMenu(JMenu decompilerMenu, JMenuItem decomp for (Decompiler decompiler : Decompiler.values()) { JRadioButtonMenuItem decompilerButton = new JRadioButtonMenuItem(decompiler.name); decompilerGroup.add(decompilerButton); - if (decompiler.equals(Config.decompiler().decompiler.value())) { + if (decompiler.equals(Config.decompiler().activeDecompiler.value())) { decompilerButton.setSelected(true); } decompilerButton.addActionListener(event -> { gui.getController().setDecompiler(decompiler.service); - Config.decompiler().decompiler.setValue(decompiler, true); + Config.decompiler().activeDecompiler.setValue(decompiler, true); }); decompilerMenu.add(decompilerButton); } From cd6848bf4632e0a6c92c8d50d3edb5195f0e03dc Mon Sep 17 00:00:00 2001 From: ix0rai Date: Sat, 9 Dec 2023 22:24:39 -0600 Subject: [PATCH 17/25] cleanups --- enigma-swing/build.gradle | 1 - .../main/java/org/quiltmc/enigma/gui/Gui.java | 16 +++---- .../org/quiltmc/enigma/gui/GuiController.java | 4 +- .../java/org/quiltmc/enigma/gui/Main.java | 4 +- .../org/quiltmc/enigma/gui/config/Config.java | 8 ++-- .../enigma/gui/config/theme/LookAndFeel.java | 2 +- .../enigma/gui/config/theme/Theme.java | 8 ++-- .../enigma/gui/config/theme/Themes.java | 2 +- .../quiltmc/enigma/gui/dialog/FontDialog.java | 4 +- .../enigma/gui/dialog/StatsDialog.java | 14 +++--- .../gui/docker/component/DockerButton.java | 2 +- .../quiltmc/enigma/gui/element/MenuBar.java | 46 +++++++++---------- .../quiltmc/enigma/gui/util/ScaleUtil.java | 20 ++++---- gradle/libs.versions.toml | 6 +-- 14 files changed, 65 insertions(+), 72 deletions(-) diff --git a/enigma-swing/build.gradle b/enigma-swing/build.gradle index a976c0b5a..62f4a2441 100644 --- a/enigma-swing/build.gradle +++ b/enigma-swing/build.gradle @@ -16,7 +16,6 @@ dependencies { implementation libs.quilt.config implementation libs.swing.dpi implementation libs.fontchooser - implementation libs.bundles.night.config testImplementation(testFixtures(project(':enigma'))) } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java index 89e8bb7f6..3dccc76b1 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java @@ -210,11 +210,11 @@ private void setupUi() { JFrame frame = this.mainWindow.getFrame(); frame.addWindowListener(GuiUtil.onWindowClose(e -> this.close())); - frame.setSize(Config.get().windowSize.value().toDimension()); + frame.setSize(Config.main().windowSize.value().toDimension()); frame.setMinimumSize(ScaleUtil.getDimension(640, 480)); frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - Point windowPos = Config.get().windowPos.value().toPoint(); + Point windowPos = Config.main().windowPos.value().toPoint(); frame.setLocation(windowPos); this.retranslateUi(); @@ -517,10 +517,10 @@ public void close() { } private void exit() { - Config.get().windowPos.setValue(Config.Vec2i.fromPoint(this.mainWindow.getFrame().getLocationOnScreen()), true); - Config.get().windowSize.setValue(Config.Vec2i.fromDimension(this.mainWindow.getFrame().getSize()), true); + Config.main().windowPos.setValue(Config.Vec2i.fromPoint(this.mainWindow.getFrame().getLocationOnScreen()), true); + Config.main().windowSize.setValue(Config.Vec2i.fromDimension(this.mainWindow.getFrame().getSize()), true); - Config.get().save(); + Config.main().save(); this.searchDialog.dispose(); this.mainWindow.getFrame().dispose(); @@ -616,17 +616,17 @@ public void addMessage(ServerMessage message) { // popup notifications switch (message.getType()) { case CHAT -> { - if (Config.get().serverNotificationLevel.value() == NotificationManager.ServerNotificationLevel.FULL && !message.user.equals(Config.net().username.value())) { + if (Config.main().serverNotificationLevel.value() == NotificationManager.ServerNotificationLevel.FULL && !message.user.equals(Config.net().username.value())) { this.notificationManager.notify(new ParameterizedMessage(Message.MULTIPLAYER_CHAT, message.translate())); } } case CONNECT -> { - if (Config.get().serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { + if (Config.main().serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { this.notificationManager.notify(new ParameterizedMessage(Message.MULTIPLAYER_USER_CONNECTED, message.translate())); } } case DISCONNECT -> { - if (Config.get().serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { + if (Config.main().serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { this.notificationManager.notify(new ParameterizedMessage(Message.MULTIPLAYER_USER_LEFT, message.translate())); } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java index b455fe1b5..87b73d66e 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/GuiController.java @@ -556,7 +556,7 @@ private void applyChange0(ValidationContext vc, EntryChange change, boolean u public void openStatsTree(Set includedTypes) { ProgressDialog.runOffThread(this.gui, progress -> { StatsResult overall = this.getStatsGenerator().getResultNullable().getOverall(); - StatsTree tree = overall.buildTree(Config.get().stats.lastTopLevelPackage.value(), includedTypes); + StatsTree tree = overall.buildTree(Config.main().stats.lastTopLevelPackage.value(), includedTypes); String treeJson = GSON.toJson(tree.root); try { @@ -647,7 +647,7 @@ public synchronized void disconnectIfConnected(String reason) { }); this.gui.setUserList(new ArrayList<>()); - if (Config.get().serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { + if (Config.main().serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { this.gui.getNotificationManager().notify(new ParameterizedMessage(Message.LEFT_SERVER)); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java index 0a95bf7ce..bba10288c 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Main.java @@ -96,7 +96,7 @@ public static void main(String[] args) throws IOException { EnigmaProfile parsedProfile = EnigmaProfile.read(options.valueOf(profile)); - I18n.setLanguage(Config.get().language.value()); + I18n.setLanguage(Config.main().language.value()); setDefaultSystemProperty("apple.laf.useScreenMenuBar", "true"); setDefaultSystemProperty("awt.useSystemAAFontSettings", "on"); setDefaultSystemProperty("swing.aatext", "true"); @@ -131,7 +131,7 @@ public static void main(String[] args) throws IOException { gui.getNotificationManager().notify(ParameterizedMessage.openedProject(jarPath.toString(), mappingsPath.toString())); } else { // search for mappings that are associated with the jar - for (Config.RecentProject recentProject : Config.get().recentProjects.value()) { + for (Config.RecentProject recentProject : Config.main().recentProjects.value()) { if (recentProject.getJarPath().equals(jarPath)) { gui.getNotificationManager().notify(ParameterizedMessage.openedProject(recentProject.jarPath(), recentProject.mappingsPath())); gui.getController().openMappings(recentProject.getMappingsPath()); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java index 828aeb3b8..d448897fe 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java @@ -26,7 +26,7 @@ public final class Config extends ReflectiveConfig { private static final String FORMAT = "toml"; private static final String FAMILY = "enigma"; - private static final ConfigEnvironment ENVIRONMENT = new ConfigEnvironment(ConfigPaths.getConfigPathRoot(), FORMAT, new TomlSerializer()); + private static final ConfigEnvironment ENVIRONMENT = new ConfigEnvironment(ConfigPaths.getConfigPathRoot(), FORMAT, TomlSerializer.INSTANCE); private static final Config MAIN = ConfigFactory.create(ENVIRONMENT, FAMILY, "main", Config.class); private static final KeyBindConfig KEYBIND = ConfigFactory.create(ENVIRONMENT, FAMILY, "keybind", KeyBindConfig.class); private static final NetConfig NET = ConfigFactory.create(ENVIRONMENT, FAMILY, "net", NetConfig.class); @@ -54,8 +54,6 @@ public final class Config extends ReflectiveConfig { @SerializedName("look_and_feel") public final TrackedValue lookAndFeel = this.value(LookAndFeel.DEFAULT); - // todo laf can't be changed while running - public final transient LookAndFeel activeLookAndFeel = this.lookAndFeel.value(); @SerializedName("default_theme") public final Theme defaultTheme = new Theme(LookAndFeel.DEFAULT); @@ -68,7 +66,7 @@ public final class Config extends ReflectiveConfig { @SerializedName("none_theme") public final Theme noneTheme = new Theme(LookAndFeel.NONE); - public static Config get() { + public static Config main() { return MAIN; } @@ -89,7 +87,7 @@ public static DecompilerConfig decompiler() { } public static Theme currentTheme() { - return switch (MAIN.activeLookAndFeel) { + return switch (MAIN.lookAndFeel.value()) { case DEFAULT -> MAIN.defaultTheme; case DARCULA -> MAIN.darculaTheme; case METAL -> MAIN.metalTheme; diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/LookAndFeel.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/LookAndFeel.java index 7c14b1a9c..92971a756 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/LookAndFeel.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/LookAndFeel.java @@ -38,7 +38,7 @@ public boolean needsScaling() { public void setGlobalLAF() { // Configure FlatLaf's UI scale to be our scale factor. // This is also used for the SVG icons, so it applies even when some other LaF is active. - System.setProperty(FlatSystemProperties.UI_SCALE, Float.toString(Config.get().scaleFactor.value())); + System.setProperty(FlatSystemProperties.UI_SCALE, Float.toString(Config.main().scaleFactor.value())); try { switch (this) { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java index 49447030d..d6e9c4d90 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java @@ -86,13 +86,13 @@ public static class Colors extends ReflectiveConfig.Section { public final TrackedValue deobfuscatedOutline = this.value(new SerializableColor(0xFF50A050)); @SerializedName("editor_background") - public final TrackedValue editorBackground = this.value(new SerializableColor(0xFF50A050)); + public final TrackedValue editorBackground = this.value(new SerializableColor(0xFFFFFFFF)); @SerializedName("highlight") - public final TrackedValue highlight = this.value(new SerializableColor(0xFF50A050)); + public final TrackedValue highlight = this.value(new SerializableColor(0xFF3333EE)); @SerializedName("caret") - public final TrackedValue caret = this.value(new SerializableColor(0xFF50A050)); + public final TrackedValue caret = this.value(new SerializableColor(0xFF000000)); @SerializedName("selection_highlight") - public final TrackedValue selectionHighlight = this.value(new SerializableColor(0xFF50A050)); + public final TrackedValue selectionHighlight = this.value(new SerializableColor(0xFF000000)); @SerializedName("string") public final TrackedValue string = this.value(new SerializableColor(0xFFCC6600)); @SerializedName("number") diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java index ad1dbe99a..691d9d7ee 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java @@ -20,7 +20,7 @@ public class Themes { // Calling this after the UI is initialized (e.g. when the user changes // theme settings) is currently not functional. public static void setupTheme() { - LookAndFeel laf = Config.get().lookAndFeel.value(); + LookAndFeel laf = Config.main().lookAndFeel.value(); laf.setGlobalLAF(); Config.currentColors().configure(LookAndFeel.isDarkLaf()); Themes.setFonts(); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java index 3e72bf1e1..499a225a7 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java @@ -41,7 +41,7 @@ public class FontDialog extends JDialog { public FontDialog(Frame owner) { super(owner, "Fonts", true); - this.customCheckBox.setSelected(Config.get().useCustomFonts.value()); + this.customCheckBox.setSelected(Config.main().useCustomFonts.value()); this.entries.setPreferredSize(ScaleUtil.getDimension(100, 0)); @@ -100,7 +100,7 @@ private void apply() { FONTS.get(i).setValue(this.fontValues[i], true); } - Config.get().useCustomFonts.setValue(this.customCheckBox.isSelected(), true); + Config.main().useCustomFonts.setValue(this.customCheckBox.isSelected(), true); ChangeDialog.show(this); this.dispose(); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/StatsDialog.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/StatsDialog.java index 946944a5e..b269fd2a4 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/StatsDialog.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/StatsDialog.java @@ -65,12 +65,12 @@ public static void show(Gui gui, ProjectStatsResult result, String packageName) contentPane.add(topLevelPackageOption, cb1.pos(0, result.getOverall().getTypes().size() + 1).build()); JTextField topLevelPackage = new JTextField(); - topLevelPackage.setText(Config.get().stats.lastTopLevelPackage.value()); + topLevelPackage.setText(Config.main().stats.lastTopLevelPackage.value()); contentPane.add(topLevelPackage, cb1.pos(0, result.getOverall().getTypes().size() + 2).fill(GridBagConstraints.HORIZONTAL).build()); // show synthetic members option JCheckBox syntheticParametersOption = new JCheckBox(I18n.translate("menu.file.stats.synthetic_parameters")); - syntheticParametersOption.setSelected(Config.get().stats.shouldIncludeSyntheticParameters.value()); + syntheticParametersOption.setSelected(Config.main().stats.shouldIncludeSyntheticParameters.value()); contentPane.add(syntheticParametersOption, cb1.pos(0, result.getOverall().getTypes().size() + 4).build()); // show filter button @@ -78,10 +78,10 @@ public static void show(Gui gui, ProjectStatsResult result, String packageName) filterButton.addActionListener(action -> { dialog.dispose(); ProgressDialog.runOffThread(gui, listener -> { - Config.get().stats.lastTopLevelPackage.setValue(topLevelPackage.getText(), true); + Config.main().stats.lastTopLevelPackage.setValue(topLevelPackage.getText(), true); - ProjectStatsResult projectResult = gui.getController().getStatsGenerator().getResult(syntheticParametersOption.isSelected()).filter(Config.get().stats.lastTopLevelPackage.value()); - SwingUtilities.invokeLater(() -> show(gui, projectResult, Config.get().stats.lastTopLevelPackage.value())); + ProjectStatsResult projectResult = gui.getController().getStatsGenerator().getResult(syntheticParametersOption.isSelected()).filter(Config.main().stats.lastTopLevelPackage.value()); + SwingUtilities.invokeLater(() -> show(gui, projectResult, Config.main().stats.lastTopLevelPackage.value())); }); }); contentPane.add(filterButton, cb1.pos(0, result.getOverall().getTypes().size() + 3).anchor(GridBagConstraints.EAST).build()); @@ -92,8 +92,8 @@ public static void show(Gui gui, ProjectStatsResult result, String packageName) button.addActionListener(action -> { dialog.dispose(); - Config.get().stats.lastTopLevelPackage.setValue(topLevelPackage.getText(), true); - Config.get().stats.shouldIncludeSyntheticParameters.setValue(syntheticParametersOption.isSelected(), true); + Config.main().stats.lastTopLevelPackage.setValue(topLevelPackage.getText(), true); + Config.main().stats.shouldIncludeSyntheticParameters.setValue(syntheticParametersOption.isSelected(), true); generateStats(gui, checkboxes); }); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java index e6899e458..21dc0cc83 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java @@ -122,7 +122,7 @@ public void paint(Graphics g) { // setup text String translatedText = this.textSupplier.get(); Font font = Config.currentFonts().defaultFont.value(); - if (Config.get().lookAndFeel.value().equals(LookAndFeel.SYSTEM)) { + if (Config.main().lookAndFeel.value().equals(LookAndFeel.SYSTEM)) { font = font.deriveFont(Font.BOLD); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java index 77b07d87d..dbb7492ea 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java @@ -274,7 +274,7 @@ public void retranslateUi() { private void onOpenJarClicked() { JFileChooser d = this.gui.jarFileChooser; - d.setCurrentDirectory(new File(Config.get().stats.lastSelectedDir.value())); + d.setCurrentDirectory(new File(Config.main().stats.lastSelectedDir.value())); d.setVisible(true); int result = d.showOpenDialog(this.gui.getFrame()); @@ -291,12 +291,12 @@ private void onOpenJarClicked() { this.gui.getController().openJar(path); } - Config.get().stats.lastSelectedDir.setValue(d.getCurrentDirectory().getAbsolutePath(), true); + Config.main().stats.lastSelectedDir.setValue(d.getCurrentDirectory().getAbsolutePath(), true); } } private void onMaxRecentFilesClicked() { - String input = JOptionPane.showInputDialog(this.gui.getFrame(), I18n.translate("menu.file.dialog.max_recent_projects.set"), Config.get().maxRecentFiles.value()); + String input = JOptionPane.showInputDialog(this.gui.getFrame(), I18n.translate("menu.file.dialog.max_recent_projects.set"), Config.main().maxRecentFiles.value()); if (input != null) { try { @@ -305,7 +305,7 @@ private void onMaxRecentFilesClicked() { throw new NumberFormatException(); } - Config.get().maxRecentFiles.setValue(max, true); + Config.main().maxRecentFiles.setValue(max, true); } catch (NumberFormatException e) { JOptionPane.showMessageDialog(this.gui.getFrame(), I18n.translate("prompt.invalid_input"), I18n.translate("prompt.error"), JOptionPane.ERROR_MESSAGE); } @@ -345,15 +345,15 @@ private void onReloadAllClicked() { } private void onExportSourceClicked() { - this.gui.exportSourceFileChooser.setCurrentDirectory(new File(Config.get().stats.lastSelectedDir.value())); + this.gui.exportSourceFileChooser.setCurrentDirectory(new File(Config.main().stats.lastSelectedDir.value())); if (this.gui.exportSourceFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { - Config.get().stats.lastSelectedDir.setValue(this.gui.exportSourceFileChooser.getCurrentDirectory().toString(), true); + Config.main().stats.lastSelectedDir.setValue(this.gui.exportSourceFileChooser.getCurrentDirectory().toString(), true); this.gui.getController().exportSource(this.gui.exportSourceFileChooser.getSelectedFile().toPath()); } } private void onExportJarClicked() { - this.gui.exportJarFileChooser.setCurrentDirectory(new File(Config.get().stats.lastSelectedDir.value())); + this.gui.exportJarFileChooser.setCurrentDirectory(new File(Config.main().stats.lastSelectedDir.value())); this.gui.exportJarFileChooser.setVisible(true); int result = this.gui.exportJarFileChooser.showSaveDialog(this.gui.getFrame()); @@ -364,13 +364,13 @@ private void onExportJarClicked() { if (this.gui.exportJarFileChooser.getSelectedFile() != null) { Path path = this.gui.exportJarFileChooser.getSelectedFile().toPath(); this.gui.getController().exportJar(path); - Config.get().stats.lastSelectedDir.setValue(this.gui.exportJarFileChooser.getCurrentDirectory().getAbsolutePath(), true); + Config.main().stats.lastSelectedDir.setValue(this.gui.exportJarFileChooser.getCurrentDirectory().getAbsolutePath(), true); } } private void onCustomScaleClicked() { String answer = (String) JOptionPane.showInputDialog(this.gui.getFrame(), I18n.translate("menu.view.scale.custom.title"), I18n.translate("menu.view.scale.custom.title"), - JOptionPane.QUESTION_MESSAGE, null, null, Double.toString(Config.get().scaleFactor.value() * 100)); + JOptionPane.QUESTION_MESSAGE, null, null, Double.toString(Config.main().scaleFactor.value() * 100)); if (answer == null) { return; @@ -411,7 +411,7 @@ public void onConnectClicked() { this.gui.getController().disconnectIfConnected(null); try { this.gui.getController().createClient(result.username(), result.address().address, result.address().port, result.password()); - if (Config.get().serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { + if (Config.main().serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { this.gui.getNotificationManager().notify(new ParameterizedMessage(Message.CONNECTED_TO_SERVER, result.addressStr())); } @@ -440,7 +440,7 @@ public void onStartServerClicked() { this.gui.getController().disconnectIfConnected(null); try { this.gui.getController().createServer(result.port(), result.password()); - if (Config.get().serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { + if (Config.main().serverNotificationLevel.value() != NotificationManager.ServerNotificationLevel.NONE) { this.gui.getNotificationManager().notify(new ParameterizedMessage(Message.SERVER_STARTED, result.port())); } @@ -457,10 +457,10 @@ private void onGithubClicked() { } private void onOpenMappingsClicked() { - this.gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(Config.get().stats.lastSelectedDir.value())); + this.gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(Config.main().stats.lastSelectedDir.value())); if (this.gui.enigmaMappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { File selectedFile = this.gui.enigmaMappingsFileChooser.getSelectedFile(); - Config.get().stats.lastSelectedDir.setValue(this.gui.enigmaMappingsFileChooser.getCurrentDirectory().toString(), true); + Config.main().stats.lastSelectedDir.setValue(this.gui.enigmaMappingsFileChooser.getCurrentDirectory().toString(), true); MappingFormat format = MappingFormat.parseFromFile(selectedFile.toPath()); if (format.getReader() != null) { @@ -474,7 +474,7 @@ private void onOpenMappingsClicked() { public void reloadOpenRecentMenu(Gui gui) { this.openRecentMenu.removeAll(); - List recentFilePairs = Config.get().recentProjects.value(); + List recentFilePairs = Config.main().recentProjects.value(); // find the longest common prefix among all mappings files // this is to clear the "/home/user/wherever-you-store-your-mappings-projects/" part of the path and only show relevant information @@ -539,13 +539,13 @@ private static void prepareSaveMappingsAsMenu(JMenu saveMappingsAsMenu, JMenuIte item.addActionListener(event -> { // TODO: Use a specific file chooser for it if (gui.enigmaMappingsFileChooser.getCurrentDirectory() == null) { - gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(Config.get().stats.lastSelectedDir.value())); + gui.enigmaMappingsFileChooser.setCurrentDirectory(new File(Config.main().stats.lastSelectedDir.value())); } if (gui.enigmaMappingsFileChooser.showSaveDialog(gui.getFrame()) == JFileChooser.APPROVE_OPTION) { gui.getController().saveMappings(gui.enigmaMappingsFileChooser.getSelectedFile().toPath(), format); saveMappingsItem.setEnabled(true); - Config.get().stats.lastSelectedDir.setValue(gui.enigmaMappingsFileChooser.getCurrentDirectory().toString(), true); + Config.main().stats.lastSelectedDir.setValue(gui.enigmaMappingsFileChooser.getCurrentDirectory().toString(), true); } }); saveMappingsAsMenu.add(item); @@ -580,12 +580,12 @@ private static void prepareThemesMenu(JMenu themesMenu, Gui gui) { for (LookAndFeel lookAndFeel : LookAndFeel.values()) { JRadioButtonMenuItem themeButton = new JRadioButtonMenuItem(I18n.translate("menu.view.themes." + lookAndFeel.name().toLowerCase(Locale.ROOT))); themeGroup.add(themeButton); - if (lookAndFeel.equals(Config.get().lookAndFeel.value())) { + if (lookAndFeel.equals(Config.main().lookAndFeel.value())) { themeButton.setSelected(true); } themeButton.addActionListener(e -> { - Config.get().lookAndFeel.setValue(lookAndFeel, true); + Config.main().lookAndFeel.setValue(lookAndFeel, true); Themes.setupTheme(); ChangeDialog.show(gui.getFrame()); }); @@ -598,12 +598,12 @@ private static void prepareLanguagesMenu(JMenu languagesMenu) { for (String lang : I18n.getAvailableLanguages()) { JRadioButtonMenuItem languageButton = new JRadioButtonMenuItem(I18n.getLanguageName(lang)); languageGroup.add(languageButton); - if (lang.equals(Config.get().language.value())) { + if (lang.equals(Config.main().language.value())) { languageButton.setSelected(true); } languageButton.addActionListener(event -> { - Config.get().language.setValue(lang, true); + Config.main().language.setValue(lang, true); I18n.setLanguage(lang); LanguageUtil.dispatchLanguageChange(); }); @@ -625,7 +625,7 @@ private static void prepareScaleMenu(JMenu scaleMenu, Gui gui) { }) .collect(Collectors.toMap(Pair::a, Pair::b)); - JRadioButtonMenuItem currentScaleButton = scaleButtons.get(Config.get().scaleFactor.value()); + JRadioButtonMenuItem currentScaleButton = scaleButtons.get(Config.main().scaleFactor.value()); if (currentScaleButton != null) { currentScaleButton.setSelected(true); } @@ -647,11 +647,11 @@ private static void prepareNotificationsMenu(JMenu notificationsMenu) { JRadioButtonMenuItem notificationsButton = new JRadioButtonMenuItem(level.getText()); notificationsGroup.add(notificationsButton); - if (level.equals(Config.get().serverNotificationLevel.value())) { + if (level.equals(Config.main().serverNotificationLevel.value())) { notificationsButton.setSelected(true); } - notificationsButton.addActionListener(event -> Config.get().serverNotificationLevel.setValue(level, true)); + notificationsButton.addActionListener(event -> Config.main().serverNotificationLevel.setValue(level, true)); notificationsMenu.add(notificationsButton); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java index fed605a1d..e6fc889f2 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java @@ -23,9 +23,9 @@ public class ScaleUtil { private static final List listeners = new ArrayList<>(); public static void setScaleFactor(float scaleFactor) { - float oldScale = Config.get().scaleFactor.value(); + float oldScale = Config.main().scaleFactor.value(); float clamped = Math.min(Math.max(0.25f, scaleFactor), 10.0f); - Config.get().scaleFactor.setValue(clamped, true); + Config.main().scaleFactor.setValue(clamped, true); rescaleFontInConfig(Config.currentFonts().defaultFont, oldScale); rescaleFontInConfig(Config.currentFonts().small, oldScale); rescaleFontInConfig(Config.currentFonts().editor, oldScale); @@ -53,7 +53,7 @@ public static Font getFont(String fontName, int style, int fontSize) { } public static Font scaleFont(Font font) { - return createTweakerForCurrentLook(Config.get().scaleFactor.value()).modifyFont("", font); + return createTweakerForCurrentLook(Config.main().scaleFactor.value()).modifyFont("", font); } private static void rescaleFontInConfig(TrackedValue font, float oldScale) { @@ -62,20 +62,20 @@ private static void rescaleFontInConfig(TrackedValue Date: Sat, 9 Dec 2023 23:04:12 -0600 Subject: [PATCH 18/25] laf stuff --- .../java/org/quiltmc/enigma/gui/config/Config.java | 11 ++++++++++- .../org/quiltmc/enigma/gui/config/theme/Themes.java | 1 + .../enigma/gui/docker/component/DockerButton.java | 2 +- .../java/org/quiltmc/enigma/gui/element/MenuBar.java | 2 -- .../java/org/quiltmc/enigma/gui/util/ScaleUtil.java | 2 +- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java index d448897fe..3626e2c05 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java @@ -52,8 +52,16 @@ public final class Config extends ReflectiveConfig { public final StatsSection stats = new StatsSection(); + /** + * The look and feel stored in the config: do not use this unless setting! Use {@link #activeLookAndFeel} instead, + * since look and feel is final once loaded. + */ @SerializedName("look_and_feel") public final TrackedValue lookAndFeel = this.value(LookAndFeel.DEFAULT); + /** + * Look and feel is not modifiable at runtime. I have tried and failed multiple times to get this running. + */ + public static LookAndFeel activeLookAndFeel; @SerializedName("default_theme") public final Theme defaultTheme = new Theme(LookAndFeel.DEFAULT); @@ -66,6 +74,7 @@ public final class Config extends ReflectiveConfig { @SerializedName("none_theme") public final Theme noneTheme = new Theme(LookAndFeel.NONE); + @SuppressWarnings("all") public static Config main() { return MAIN; } @@ -87,7 +96,7 @@ public static DecompilerConfig decompiler() { } public static Theme currentTheme() { - return switch (MAIN.lookAndFeel.value()) { + return switch (activeLookAndFeel) { case DEFAULT -> MAIN.defaultTheme; case DARCULA -> MAIN.darculaTheme; case METAL -> MAIN.metalTheme; diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java index 691d9d7ee..2ac0d20cd 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java @@ -21,6 +21,7 @@ public class Themes { // theme settings) is currently not functional. public static void setupTheme() { LookAndFeel laf = Config.main().lookAndFeel.value(); + Config.activeLookAndFeel = laf; laf.setGlobalLAF(); Config.currentColors().configure(LookAndFeel.isDarkLaf()); Themes.setFonts(); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java index 21dc0cc83..75353dc9e 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java @@ -122,7 +122,7 @@ public void paint(Graphics g) { // setup text String translatedText = this.textSupplier.get(); Font font = Config.currentFonts().defaultFont.value(); - if (Config.main().lookAndFeel.value().equals(LookAndFeel.SYSTEM)) { + if (Config.activeLookAndFeel.equals(LookAndFeel.SYSTEM)) { font = font.deriveFont(Font.BOLD); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java index dbb7492ea..e345e5c65 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java @@ -5,7 +5,6 @@ import org.quiltmc.enigma.gui.NotificationManager; import org.quiltmc.enigma.gui.config.Decompiler; import org.quiltmc.enigma.gui.config.theme.LookAndFeel; -import org.quiltmc.enigma.gui.config.theme.Themes; import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.config.keybind.KeyBinds; import org.quiltmc.enigma.gui.dialog.AboutDialog; @@ -586,7 +585,6 @@ private static void prepareThemesMenu(JMenu themesMenu, Gui gui) { themeButton.addActionListener(e -> { Config.main().lookAndFeel.setValue(lookAndFeel, true); - Themes.setupTheme(); ChangeDialog.show(gui.getFrame()); }); themesMenu.add(themeButton); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java index e6fc889f2..c5b7ec3b7 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java @@ -89,7 +89,7 @@ public static int invert(int i) { public static void applyScaling() { double scale = Config.main().scaleFactor.value(); - if (Config.main().lookAndFeel.value().needsScaling()) { + if (Config.activeLookAndFeel.needsScaling()) { UiDefaultsScaler.updateAndApplyGlobalScaling((int) (100 * scale), true); } From 24d83b7798d112d095fa30684a01c2c7bc1d8a7a Mon Sep 17 00:00:00 2001 From: ix0rai Date: Sat, 9 Dec 2023 23:10:18 -0600 Subject: [PATCH 19/25] strip out some pointless laf stuff --- .../main/java/org/quiltmc/enigma/gui/Gui.java | 2 +- .../org/quiltmc/enigma/gui/config/Config.java | 14 +++++----- .../enigma/gui/config/theme/Themes.java | 12 --------- .../enigma/gui/element/EditorTabbedPane.java | 1 - .../quiltmc/enigma/gui/panel/EditorPanel.java | 26 +------------------ 5 files changed, 9 insertions(+), 46 deletions(-) diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java index 3dccc76b1..f8e676d58 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java @@ -131,7 +131,7 @@ public Gui(EnigmaProfile profile, Set editableTypes, boolean visib this.setupUi(); LanguageUtil.addListener(this::retranslateUi); - Themes.addListener((lookAndFeel, boxHighlightPainters) -> SwingUtilities.updateComponentTreeUI(this.getFrame())); + //Themes.addListener((lookAndFeel, boxHighlightPainters) -> SwingUtilities.updateComponentTreeUI(this.getFrame())); this.mainWindow.setVisible(visible); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java index 3626e2c05..742154ab3 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java @@ -97,11 +97,11 @@ public static DecompilerConfig decompiler() { public static Theme currentTheme() { return switch (activeLookAndFeel) { - case DEFAULT -> MAIN.defaultTheme; - case DARCULA -> MAIN.darculaTheme; - case METAL -> MAIN.metalTheme; - case SYSTEM -> MAIN.systemTheme; - case NONE -> MAIN.noneTheme; + case DEFAULT -> main().defaultTheme; + case DARCULA -> main().darculaTheme; + case METAL -> main().metalTheme; + case SYSTEM -> main().systemTheme; + case NONE -> main().noneTheme; }; } @@ -114,11 +114,11 @@ public static Theme.Fonts currentFonts() { } public static void insertRecentProject(String jarPath, String mappingsPath) { - MAIN.recentProjects.value().add(0, new RecentProject(jarPath, mappingsPath)); + main().recentProjects.value().add(0, new RecentProject(jarPath, mappingsPath)); } public static RecentProject getMostRecentProject() { - return MAIN.recentProjects.value().get(0); + return main().recentProjects.value().get(0); } public record RecentProject(String jarPath, String mappingsPath) implements ConfigSerializableObject> { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java index 2ac0d20cd..bd29f6ba2 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java @@ -15,8 +15,6 @@ import javax.swing.UIManager; public class Themes { - private static final Set listeners = new HashSet<>(); - // Calling this after the UI is initialized (e.g. when the user changes // theme settings) is currently not functional. public static void setupTheme() { @@ -27,8 +25,6 @@ public static void setupTheme() { Themes.setFonts(); UIManager.put("ScrollBar.showButtons", true); JEditorPane.registerEditorKitForContentType("text/enigma-sources", JavaSyntaxKit.class.getName()); - Map boxHighlightPainters = getBoxHighlightPainters(); - listeners.forEach(l -> l.onThemeChanged(laf, boxHighlightPainters)); ScaleUtil.applyScaling(); Config.updateSyntaxpain(); } @@ -88,12 +84,4 @@ public static Map getBoxHighlightPainters() { TokenType.DEBUG, BoxHighlightPainter.create(Config.currentColors().debugToken.value(), Config.currentColors().debugTokenOutline.value()) ); } - - public static void addListener(ThemeChangeListener listener) { - listeners.add(listener); - } - - public static void removeListener(ThemeChangeListener listener) { - listeners.remove(listener); - } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/EditorTabbedPane.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/EditorTabbedPane.java index 31fd56aa6..7c491659f 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/EditorTabbedPane.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/EditorTabbedPane.java @@ -43,7 +43,6 @@ public EditorPanel openClass(ClassEntry entry) { if (ch == null) return null; this.navigator = new NavigatorPanel(this.gui); EditorPanel ed = new EditorPanel(this.gui, this.navigator); - ed.setup(); ed.setClassHandle(ch); this.openFiles.addTab(ed.getFileName(), ed.getUi()); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/panel/EditorPanel.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/panel/EditorPanel.java index 2a061ad4d..66707473d 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/panel/EditorPanel.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/panel/EditorPanel.java @@ -9,14 +9,12 @@ import org.quiltmc.enigma.gui.EditableType; import org.quiltmc.enigma.gui.Gui; import org.quiltmc.enigma.gui.GuiController; -import org.quiltmc.enigma.gui.config.theme.LookAndFeel; import org.quiltmc.enigma.gui.config.theme.Themes; import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.config.keybind.KeyBinds; import org.quiltmc.enigma.gui.element.EditorPopupMenu; import org.quiltmc.enigma.gui.element.NavigatorPanel; import org.quiltmc.enigma.gui.event.EditorActionListener; -import org.quiltmc.enigma.gui.event.ThemeChangeListener; import org.quiltmc.enigma.gui.highlight.BoxHighlightPainter; import org.quiltmc.enigma.gui.highlight.SelectionHighlightPainter; import org.quiltmc.enigma.gui.util.GridBagConstraintsBuilder; @@ -97,14 +95,11 @@ public class EditorPanel { private boolean mouseIsPressed = false; private boolean shouldNavigateOnClick; - public LookAndFeel editorLaf; private int fontSize = 12; - private Map boxHighlightPainters; + private final Map boxHighlightPainters; private final List listeners = new ArrayList<>(); - private final ThemeChangeListener themeChangeListener; - private ClassHandle classHandle; private DecompiledClassSource source; private boolean settingSource; @@ -210,20 +205,6 @@ public void keyReleased(KeyEvent event) { this.retryButton.addActionListener(e -> this.redecompileClass()); - this.themeChangeListener = (laf, boxHighlightPainters) -> { - if ((this.editorLaf == null || this.editorLaf != laf)) { - this.editor.updateUI(); - this.editor.setBackground(Config.currentColors().editorBackground.value()); - if (this.editorLaf != null) { - this.classHandle.invalidateMapped(); - } - - this.editorLaf = laf; - } - - this.boxHighlightPainters = boxHighlightPainters; - }; - this.ui.putClientProperty(EditorPanel.class, this); } @@ -289,12 +270,7 @@ public void onDeleted(ClassHandle h) { this.listeners.forEach(l -> l.onClassHandleChanged(this, old, handle)); } - public void setup() { - Themes.addListener(this.themeChangeListener); - } - public void destroy() { - Themes.removeListener(this.themeChangeListener); this.classHandle.close(); } From 9f3ed4a4506de8c26e27480f1eca514af9612ba7 Mon Sep 17 00:00:00 2001 From: ix0rai Date: Sat, 9 Dec 2023 23:17:25 -0600 Subject: [PATCH 20/25] fix divider states --- .../src/main/java/org/quiltmc/enigma/gui/Gui.java | 11 +++-------- .../org/quiltmc/enigma/gui/docker/DockerManager.java | 10 ---------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java index f8e676d58..1b8be4bb8 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java @@ -6,7 +6,6 @@ import org.quiltmc.enigma.api.translation.mapping.EntryMapping; import org.quiltmc.enigma.api.translation.mapping.EntryRemapper; import org.quiltmc.enigma.gui.config.DockerConfig; -import org.quiltmc.enigma.gui.config.theme.Themes; import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.dialog.JavadocDialog; import org.quiltmc.enigma.gui.dialog.SearchDialog; @@ -131,7 +130,6 @@ public Gui(EnigmaProfile profile, Set editableTypes, boolean visib this.setupUi(); LanguageUtil.addListener(this::retranslateUi); - //Themes.addListener((lookAndFeel, boxHighlightPainters) -> SwingUtilities.updateComponentTreeUI(this.getFrame())); this.mainWindow.setVisible(visible); } @@ -196,12 +194,7 @@ private void setupUi() { this.splitRight.setResizeWeight(1); this.splitLeft.setResizeWeight(0); - // todo probably doesn't work - if (!Config.dockers().getLocations(Docker.Side.LEFT).isEmpty() || !Config.dockers().getLocations(Docker.Side.RIGHT).isEmpty()) { - this.dockerManager.restoreStateFromConfig(); - } else { - this.dockerManager.setupDefaultConfiguration(); - } + this.dockerManager.restoreStateFromConfig(); // init state this.setConnectionState(ConnectionState.NOT_CONNECTED); @@ -517,6 +510,8 @@ public void close() { } private void exit() { + this.dockerManager.getLeftDock().saveDividerState(); + this.dockerManager.getRightDock().saveDividerState(); Config.main().windowPos.setValue(Config.Vec2i.fromPoint(this.mainWindow.getFrame().getLocationOnScreen()), true); Config.main().windowSize.setValue(Config.Vec2i.fromDimension(this.mainWindow.getFrame().getSize()), true); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/DockerManager.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/DockerManager.java index d1ebc3c77..2588bd327 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/DockerManager.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/DockerManager.java @@ -58,16 +58,6 @@ public void host(Docker docker, Docker.Side side, Docker.VerticalLocation locati } } - /** - * Sets up the default configuration of the docks. This corresponds to the default layout the GUI before the introduction of the docker system. - */ - public void setupDefaultConfiguration() { - this.host(this.getDocker(ObfuscatedClassesDocker.class), Docker.Side.LEFT, Docker.VerticalLocation.TOP); - this.host(this.getDocker(DeobfuscatedClassesDocker.class), Docker.Side.LEFT, Docker.VerticalLocation.BOTTOM); - - this.host(this.getDocker(StructureDocker.class), Docker.Side.RIGHT, Docker.VerticalLocation.FULL); - } - /** * Restores the state of both docks to the version saved in the config. * @see Dock#restoreState(DockerManager) From e7c45a8f667cccd11140a8fa5bb4e844a79ee7c0 Mon Sep 17 00:00:00 2001 From: ix0rai Date: Sun, 10 Dec 2023 17:26:59 -0600 Subject: [PATCH 21/25] save docker selections --- .../main/java/org/quiltmc/enigma/gui/Gui.java | 7 +- .../enigma/gui/config/DockerConfig.java | 120 ++++++++++++------ .../org/quiltmc/enigma/gui/docker/Dock.java | 10 +- .../org/quiltmc/enigma/gui/docker/Docker.java | 2 +- .../gui/docker/component/DockerSelector.java | 2 +- 5 files changed, 92 insertions(+), 49 deletions(-) diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java index 1b8be4bb8..3bd974911 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/Gui.java @@ -5,7 +5,6 @@ import org.quiltmc.enigma.api.analysis.EntryReference; import org.quiltmc.enigma.api.translation.mapping.EntryMapping; import org.quiltmc.enigma.api.translation.mapping.EntryRemapper; -import org.quiltmc.enigma.gui.config.DockerConfig; import org.quiltmc.enigma.gui.config.Config; import org.quiltmc.enigma.gui.dialog.JavadocDialog; import org.quiltmc.enigma.gui.dialog.SearchDialog; @@ -145,10 +144,8 @@ private void setupDockers() { this.dockerManager.registerDocker(new AllClassesDocker(this)); this.dockerManager.registerDocker(new DeobfuscatedClassesDocker(this)); - if (Config.dockers().dockerLocations.value().isEmpty()) { - for (var entry : DockerConfig.getDefaultLocations(this.dockerManager).entrySet()) { - Config.dockers().putLocation(entry.getKey(), entry.getValue()); - } + if (Config.dockers().buttonLocations.value().isEmpty()) { + Config.dockers().updateButtonLocations(this.dockerManager); } // set default docker sizes diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java index 4c32793c8..722d28bff 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java @@ -2,24 +2,16 @@ import org.quiltmc.config.api.ReflectiveConfig; import org.quiltmc.config.api.annotations.SerializedName; +import org.quiltmc.config.api.values.ComplexConfigValue; +import org.quiltmc.config.api.values.ConfigSerializableObject; import org.quiltmc.config.api.values.TrackedValue; import org.quiltmc.config.api.values.ValueMap; -import org.quiltmc.enigma.gui.docker.AllClassesDocker; -import org.quiltmc.enigma.gui.docker.CallsTreeDocker; -import org.quiltmc.enigma.gui.docker.CollabDocker; -import org.quiltmc.enigma.gui.docker.DeobfuscatedClassesDocker; import org.quiltmc.enigma.gui.docker.Docker; import org.quiltmc.enigma.gui.docker.DockerManager; -import org.quiltmc.enigma.gui.docker.ImplementationsTreeDocker; -import org.quiltmc.enigma.gui.docker.InheritanceTreeDocker; -import org.quiltmc.enigma.gui.docker.NotificationsDocker; -import org.quiltmc.enigma.gui.docker.ObfuscatedClassesDocker; -import org.quiltmc.enigma.gui.docker.StructureDocker; import javax.annotation.Nullable; import java.util.HashMap; import java.util.Map; -import java.util.stream.Collectors; public class DockerConfig extends ReflectiveConfig { @SerializedName("left_vertical_divider_location") @@ -33,28 +25,28 @@ public class DockerConfig extends ReflectiveConfig { @SerializedName("saved_with_left_docker_open") public final TrackedValue savedWithLeftDockerOpen = this.value(true); - @SerializedName("docker_locations") - public final TrackedValue> dockerLocations = this.map(new Docker.Location(Docker.Side.LEFT, Docker.VerticalLocation.TOP)).build(); + @SerializedName("button_locations") + public final TrackedValue> buttonLocations = this.map(new Docker.Location(Docker.Side.LEFT, Docker.VerticalLocation.TOP)).build(); + @SerializedName("left_dockers") + public final TrackedValue leftDockers = this.value(new SelectedDockers("", "", "all_classes")); + @SerializedName("right_dockers") + public final TrackedValue rightDockers = this.value(new SelectedDockers("", "", "structure")); - public void putLocation(Docker docker, Docker.Location location) { - this.putLocation(docker.getId(), location); + public SelectedDockers getSelectedDockers(Docker.Side side) { + return side == Docker.Side.LEFT ? this.leftDockers.value() : this.rightDockers.value(); } - public void putLocation(String id, Docker.Location location) { - this.dockerLocations.value().put(id, location); + public void putButtonLocation(String id, Docker.Location location) { + this.buttonLocations.value().put(id, location); } - public void putLocation(Docker docker, Docker.Side side, Docker.VerticalLocation verticalLocation) { - this.putLocation(docker.getId(), new Docker.Location(side, verticalLocation)); + public void putButtonLocation(Docker docker, Docker.Side side, Docker.VerticalLocation verticalLocation) { + this.putButtonLocation(docker.getId(), new Docker.Location(side, verticalLocation)); } @Nullable - public Docker.Location getLocation(String id) { - return this.dockerLocations.value().get(id); - } - - public Map getLocations(Docker.Side side) { - return this.dockerLocations.value().entrySet().stream().filter((entry) -> entry.getValue().side() == side).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + public Docker.Location getButtonLocation(String id) { + return this.buttonLocations.value().get(id); } public int getVerticalDividerLocation(Docker.Side side) { @@ -81,23 +73,75 @@ public void setHorizontalDividerLocation(Docker.Side side, int value) { } } - public static Map getDefaultLocations(DockerManager manager) { - Map locations = new HashMap<>(); + public void updateButtonLocations(DockerManager manager) { + for (Docker docker : manager.getDockers()) { + this.putButtonLocation(docker.getId(), docker.getPreferredButtonLocation()); + } + } + + public static class SelectedDockers implements ConfigSerializableObject> { + private String top; + private String bottom; + private String full; + + public SelectedDockers(String top, String bottom, String full) { + this.top = top; + this.bottom = bottom; + this.full = full; + } + + public void add(String id, Docker.VerticalLocation location) { + switch (location) { + case TOP -> { + this.full = ""; + this.top = id; + } + case BOTTOM -> { + this.full = ""; + this.bottom = id; + } + case FULL -> { + this.top = ""; + this.bottom = ""; + this.full = id; + } + } + } + + public Map asMap() { + Map map = new HashMap<>(); + if (!this.top.isBlank()) { + map.put(this.top, Docker.VerticalLocation.TOP); + } + + if (!this.bottom.isBlank()) { + map.put(this.bottom, Docker.VerticalLocation.BOTTOM); + } + + if (!this.full.isBlank()) { + map.put(this.full, Docker.VerticalLocation.FULL); + } - // left - locations.put(manager.getDocker(ObfuscatedClassesDocker.class), new Docker.Location(Docker.Side.LEFT, Docker.VerticalLocation.TOP)); - locations.put(manager.getDocker(AllClassesDocker.class), new Docker.Location(Docker.Side.LEFT, Docker.VerticalLocation.TOP)); - locations.put(manager.getDocker(DeobfuscatedClassesDocker.class), new Docker.Location(Docker.Side.LEFT, Docker.VerticalLocation.BOTTOM)); + return map; + } - // right - locations.put(manager.getDocker(StructureDocker.class), new Docker.Location(Docker.Side.RIGHT, Docker.VerticalLocation.TOP)); - locations.put(manager.getDocker(InheritanceTreeDocker.class), new Docker.Location(Docker.Side.RIGHT, Docker.VerticalLocation.TOP)); - locations.put(manager.getDocker(ImplementationsTreeDocker.class), new Docker.Location(Docker.Side.RIGHT, Docker.VerticalLocation.TOP)); - locations.put(manager.getDocker(CallsTreeDocker.class), new Docker.Location(Docker.Side.RIGHT, Docker.VerticalLocation.TOP)); + @Override + public SelectedDockers convertFrom(ValueMap representation) { + return new SelectedDockers(representation.get("top"), representation.get("bottom"), representation.get("full")); + } - locations.put(manager.getDocker(CollabDocker.class), new Docker.Location(Docker.Side.RIGHT, Docker.VerticalLocation.BOTTOM)); - locations.put(manager.getDocker(NotificationsDocker.class), new Docker.Location(Docker.Side.RIGHT, Docker.VerticalLocation.BOTTOM)); + @Override + public ValueMap getRepresentation() { + return ValueMap.builder("") + .put("top", this.top) + .put("bottom", this.bottom) + .put("full", this.full) + .build(); + } - return locations; + @Override + public ComplexConfigValue copy() { + return this; + } } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Dock.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Dock.java index 7ab53c936..2e91b8a4a 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Dock.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Dock.java @@ -2,6 +2,7 @@ import org.quiltmc.enigma.gui.Gui; import org.quiltmc.enigma.gui.config.Config; +import org.quiltmc.enigma.gui.config.DockerConfig; import org.quiltmc.enigma.gui.docker.component.DockerButton; import org.quiltmc.enigma.gui.docker.component.DockerSelector; import org.quiltmc.enigma.gui.docker.component.Draggable; @@ -17,7 +18,6 @@ import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.Objects; /** @@ -63,8 +63,8 @@ public Dock(Gui gui, Docker.Side side) { */ public void restoreState(DockerManager manager) { // restore docker state - Map hostedDockers = Config.dockers().getLocations(this.side); - hostedDockers.forEach((id, location) -> this.host(manager.getDocker(id), location.verticalLocation())); + DockerConfig.SelectedDockers hostedDockers = Config.dockers().getSelectedDockers(this.side); + hostedDockers.asMap().forEach((id, location) -> this.host(manager.getDocker(id), location)); this.restoreDividerState(true); @@ -135,6 +135,8 @@ public void host(Docker docker, Docker.VerticalLocation verticalLocation) { } public void host(Docker docker, Docker.VerticalLocation verticalLocation, boolean avoidEmptySpace) { + Config.dockers().getSelectedDockers(this.side).add(docker.getId(), verticalLocation); + Dock dock = Util.findDock(docker); if (dock != null) { dock.removeDocker(verticalLocation, avoidEmptySpace); @@ -175,7 +177,7 @@ public void host(Docker docker, Docker.VerticalLocation verticalLocation, boolea parent.remove(button); (verticalLocation == Docker.VerticalLocation.TOP ? selector.getTopSelector() : selector.getBottomSelector()).add(button); button.setSide(this.side); - Config.dockers().putLocation(docker, this.side, verticalLocation); + Config.dockers().putButtonLocation(docker, this.side, verticalLocation); button.getParent().revalidate(); button.getParent().repaint(); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java index a41d5d8c3..d9f63e6fc 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/Docker.java @@ -72,7 +72,7 @@ public DockerButton getButton() { * @return the position of the docker's button in the selector panels. this also represents where the docker will open when its button is clicked cannot use {@link Docker.VerticalLocation#FULL} */ public final Location getButtonLocation() { - Location savedLocation = Config.dockers().getLocation(this.getId()); + Location savedLocation = Config.dockers().getButtonLocation(this.getId()); return savedLocation == null ? this.getPreferredButtonLocation() : savedLocation; } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerSelector.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerSelector.java index 31c19b80a..bdb170f78 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerSelector.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerSelector.java @@ -97,7 +97,7 @@ private boolean dropButton(DockerButton button, MouseEvent event) { if (hoveredPanel != null) { hoveredPanel.add(button); button.setSide(this.side); - Config.dockers().putLocation(button.getDocker(), this.side, hoveredPanel.equals(this.bottomSelector) ? Docker.VerticalLocation.BOTTOM : Docker.VerticalLocation.TOP); + Config.dockers().putButtonLocation(button.getDocker(), this.side, hoveredPanel.equals(this.bottomSelector) ? Docker.VerticalLocation.BOTTOM : Docker.VerticalLocation.TOP); return true; } From b58481a62099edfb43088bf072b62051d5e2a4a5 Mon Sep 17 00:00:00 2001 From: ix0rai Date: Sun, 10 Dec 2023 18:03:53 -0600 Subject: [PATCH 22/25] reimplement default non-bold font --- .../enigma/gui/config/theme/Theme.java | 11 +++-- .../enigma/gui/config/theme/Themes.java | 36 ++++++++--------- .../quiltmc/enigma/gui/dialog/FontDialog.java | 40 +++---------------- .../gui/docker/component/DockerButton.java | 2 +- .../quiltmc/enigma/gui/util/ScaleUtil.java | 3 +- enigma/src/main/resources/lang/de_de.json | 2 - enigma/src/main/resources/lang/en_us.json | 4 +- enigma/src/main/resources/lang/fr_fr.json | 2 - enigma/src/main/resources/lang/ja_jp.json | 2 - 9 files changed, 36 insertions(+), 66 deletions(-) diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java index d6e9c4d90..23d15a697 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Theme.java @@ -22,8 +22,10 @@ public Theme(LookAndFeel lookAndFeel) { public final Fonts fonts = new Fonts(); public static class Fonts extends ReflectiveConfig.Section { - @SerializedName("default") - public final TrackedValue defaultFont = this.value(new SerializableFont(Font.decode(Font.DIALOG).deriveFont(Font.BOLD))); + @SerializedName("default_bold") + public final TrackedValue defaultBold = this.value(new SerializableFont(Font.decode(Font.DIALOG).deriveFont(Font.BOLD))); + @SerializedName("default_normal") + public final TrackedValue defaultNormal = this.value(new SerializableFont(Font.decode(Font.DIALOG))); @SerializedName("small") public final TrackedValue small = this.value(new SerializableFont(Font.decode(Font.DIALOG))); @SerializedName("editor") @@ -63,6 +65,9 @@ public ComplexConfigValue copy() { } } + /** + * Default values are for light themes. + */ public static class Colors extends ReflectiveConfig.Section { @SerializedName("line_numbers_foreground") public final TrackedValue lineNumbersForeground = this.value(new SerializableColor(0xFF333300)); @@ -76,7 +81,7 @@ public static class Colors extends ReflectiveConfig.Section { public final TrackedValue obfuscatedOutline = this.value(new SerializableColor(0xFFA05050)); @SerializedName("proposed") - public final TrackedValue proposed = this.value(new SerializableColor(0xFF000000)); + public final TrackedValue proposed = this.value(new SerializableColor(0x27000000)); @SerializedName("proposed_outline") public final TrackedValue proposedOutline = this.value(new SerializableColor(0xBF000000)); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java index bd29f6ba2..d7e211606 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/theme/Themes.java @@ -1,16 +1,13 @@ package org.quiltmc.enigma.gui.config.theme; import org.quiltmc.enigma.gui.config.Config; -import org.quiltmc.enigma.gui.event.ThemeChangeListener; import org.quiltmc.enigma.gui.highlight.BoxHighlightPainter; import org.quiltmc.enigma.gui.util.ScaleUtil; import org.quiltmc.enigma.api.source.TokenType; import org.quiltmc.syntaxpain.JavaSyntaxKit; import java.awt.Font; -import java.util.HashSet; import java.util.Map; -import java.util.Set; import javax.swing.JEditorPane; import javax.swing.UIManager; @@ -31,17 +28,18 @@ public static void setupTheme() { private static void setFonts() { Font small = Config.currentFonts().small.value(); - Font bold = Config.currentFonts().defaultFont.value(); + Font bold = Config.currentFonts().defaultBold.value(); + Font normal = Config.currentFonts().defaultNormal.value(); UIManager.put("CheckBox.font", bold); UIManager.put("CheckBoxMenuItem.font", bold); UIManager.put("CheckBoxMenuItem.acceleratorFont", small); - UIManager.put("ColorChooser.font", bold); // + UIManager.put("ColorChooser.font", normal); UIManager.put("ComboBox.font", bold); UIManager.put("DesktopIcon.font", bold); - UIManager.put("EditorPane.font", bold); // + UIManager.put("EditorPane.font", normal); UIManager.put("InternalFrame.titleFont", bold); - UIManager.put("FormattedTextField.font", bold); // + UIManager.put("FormattedTextField.font", normal); UIManager.put("Label.font", bold); UIManager.put("List.font", bold); UIManager.put("Menu.acceleratorFont", small); @@ -49,29 +47,29 @@ private static void setFonts() { UIManager.put("MenuBar.font", bold); UIManager.put("MenuItem.acceleratorFont", small); UIManager.put("MenuItem.font", bold); - UIManager.put("OptionPane.font", bold); // - UIManager.put("Panel.font", bold); // - UIManager.put("PasswordField.font", bold); // + UIManager.put("OptionPane.font", normal); + UIManager.put("Panel.font", normal); + UIManager.put("PasswordField.font", normal); UIManager.put("PopupMenu.font", bold); UIManager.put("ProgressBar.font", bold); UIManager.put("RadioButton.font", bold); UIManager.put("RadioButtonMenuItem.acceleratorFont", small); UIManager.put("RadioButtonMenuItem.font", bold); - UIManager.put("ScrollPane.font", bold); // + UIManager.put("ScrollPane.font", normal); UIManager.put("Slider.font", bold); UIManager.put("Spinner.font", bold); UIManager.put("TabbedPane.font", bold); - UIManager.put("Table.font", bold); // - UIManager.put("TableHeader.font", bold); // - UIManager.put("TextArea.font", bold); // - UIManager.put("TextField.font", bold); // - UIManager.put("TextPane.font", bold); // + UIManager.put("Table.font", normal); + UIManager.put("TableHeader.font", normal); + UIManager.put("TextArea.font", normal); + UIManager.put("TextField.font", normal); + UIManager.put("TextPane.font", normal); UIManager.put("TitledBorder.font", bold); UIManager.put("ToggleButton.font", bold); UIManager.put("ToolBar.font", bold); - UIManager.put("ToolTip.font", bold); // - UIManager.put("Tree.font", bold); // - UIManager.put("Viewport.font", bold); // + UIManager.put("ToolTip.font", normal); + UIManager.put("Tree.font", normal); + UIManager.put("Viewport.font", normal); UIManager.put("Button.font", bold); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java index 499a225a7..585189753 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/FontDialog.java @@ -8,7 +8,6 @@ import org.quiltmc.enigma.util.I18n; import org.drjekyll.fontchooser.FontChooser; -import java.awt.Component; import java.awt.Container; import java.awt.Font; import java.awt.Frame; @@ -16,38 +15,35 @@ import java.awt.GridBagLayout; import java.util.List; import javax.swing.JButton; -import javax.swing.JCheckBox; import javax.swing.JDialog; import javax.swing.JList; public class FontDialog extends JDialog { private static final List> FONTS = List.of( - Config.currentFonts().defaultFont, + Config.currentFonts().defaultNormal, + Config.currentFonts().defaultBold, Config.currentFonts().small, Config.currentFonts().editor ); private static final List CATEGORY_TEXTS = List.of( - "fonts.cat.default", + "fonts.cat.default_normal", + "fonts.cat.default_bold", "fonts.cat.small", "fonts.cat.editor" ); private final JList entries = new JList<>(CATEGORY_TEXTS.stream().map(I18n::translate).toArray(String[]::new)); private final FontChooser chooser = new FontChooser(Font.decode(Font.DIALOG)); - private final JCheckBox customCheckBox = new JCheckBox(I18n.translate("fonts.use_custom")); - private final Theme.Fonts.SerializableFont[] fontValues = new Theme.Fonts.SerializableFont[]{FONTS.get(0).value(), FONTS.get(1).value(), FONTS.get(2).value()}; + private final Theme.Fonts.SerializableFont[] fontValues = FONTS.stream().map(TrackedValue::value).toArray(Theme.Fonts.SerializableFont[]::new); public FontDialog(Frame owner) { super(owner, "Fonts", true); - this.customCheckBox.setSelected(Config.main().useCustomFonts.value()); - this.entries.setPreferredSize(ScaleUtil.getDimension(100, 0)); this.entries.addListSelectionListener(e -> this.categoryChanged()); this.chooser.addChangeListener(e -> this.selectedFontChanged()); - this.customCheckBox.addActionListener(e -> this.customFontsClicked()); JButton okButton = new JButton(I18n.translate("prompt.ok")); okButton.addActionListener(e -> this.apply()); JButton cancelButton = new JButton(I18n.translate("prompt.cancel")); @@ -59,24 +55,16 @@ public FontDialog(Frame owner) { GridBagConstraintsBuilder cb = GridBagConstraintsBuilder.create() .insets(2); - contentPane.add(this.entries, cb.pos(0, 0).weight(0.0, 1.0).fill(GridBagConstraints.BOTH).build()); + contentPane.add(this.entries, cb.pos(0, 0).weight(0.1, 1.0).fill(GridBagConstraints.BOTH).build()); contentPane.add(this.chooser, cb.pos(1, 0).weight(1.0, 1.0).fill(GridBagConstraints.BOTH).size(2, 1).build()); - contentPane.add(this.customCheckBox, cb.pos(0, 1).anchor(GridBagConstraints.WEST).size(2, 1).build()); contentPane.add(okButton, cb.pos(1, 1).anchor(GridBagConstraints.EAST).weight(1.0, 0.0).build()); contentPane.add(cancelButton, cb.pos(2, 1).anchor(GridBagConstraints.EAST).weight(0.0, 0.0).build()); - this.updateUiState(); - this.setSize(ScaleUtil.getDimension(640, 360)); this.setLocationRelativeTo(owner); } - private void customFontsClicked() { - this.updateUiState(); - } - private void categoryChanged() { - this.updateUiState(); int selectedIndex = this.entries.getSelectedIndex(); if (selectedIndex != -1) { this.chooser.setSelectedFont(this.fontValues[selectedIndex]); @@ -90,17 +78,11 @@ private void selectedFontChanged() { } } - private void updateUiState() { - recursiveSetEnabled(this.chooser, this.entries.getSelectedIndex() != -1 && this.customCheckBox.isSelected()); - this.entries.setEnabled(this.customCheckBox.isSelected()); - } - private void apply() { for (int i = 0; i < FONTS.size(); i++) { FONTS.get(i).setValue(this.fontValues[i], true); } - Config.main().useCustomFonts.setValue(this.customCheckBox.isSelected(), true); ChangeDialog.show(this); this.dispose(); } @@ -113,14 +95,4 @@ public static void display(Frame parent) { FontDialog d = new FontDialog(parent); d.setVisible(true); } - - private static void recursiveSetEnabled(Component self, boolean enabled) { - if (self instanceof Container container) { - for (Component component : container.getComponents()) { - recursiveSetEnabled(component, enabled); - } - - self.setEnabled(enabled); - } - } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java index 75353dc9e..fd94bc6e6 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/component/DockerButton.java @@ -121,7 +121,7 @@ public void paint(Graphics g) { // setup text String translatedText = this.textSupplier.get(); - Font font = Config.currentFonts().defaultFont.value(); + Font font = Config.currentFonts().defaultNormal.value(); if (Config.activeLookAndFeel.equals(LookAndFeel.SYSTEM)) { font = font.deriveFont(Font.BOLD); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java index c5b7ec3b7..438c6633c 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/util/ScaleUtil.java @@ -26,7 +26,8 @@ public static void setScaleFactor(float scaleFactor) { float oldScale = Config.main().scaleFactor.value(); float clamped = Math.min(Math.max(0.25f, scaleFactor), 10.0f); Config.main().scaleFactor.setValue(clamped, true); - rescaleFontInConfig(Config.currentFonts().defaultFont, oldScale); + rescaleFontInConfig(Config.currentFonts().defaultBold, oldScale); + rescaleFontInConfig(Config.currentFonts().defaultNormal, oldScale); rescaleFontInConfig(Config.currentFonts().small, oldScale); rescaleFontInConfig(Config.currentFonts().editor, oldScale); listeners.forEach(l -> l.onScaleChanged(clamped, oldScale)); diff --git a/enigma/src/main/resources/lang/de_de.json b/enigma/src/main/resources/lang/de_de.json index ed5d000a0..f35700898 100644 --- a/enigma/src/main/resources/lang/de_de.json +++ b/enigma/src/main/resources/lang/de_de.json @@ -17,10 +17,8 @@ "editor.decompile_error": "Ein Fehler ist während des Dekompilierens aufgetreten.", "editor.remap_error": "Ein Fehler ist während des Remappens aufgetreten.", - "fonts.cat.default": "Standard", "fonts.cat.small": "Klein", "fonts.cat.editor": "Editor", - "fonts.use_custom": "Benutzerdefinierte Schriftarten verwenden", "prompt.ok": "OK", "prompt.cancel": "Abbrechen", diff --git a/enigma/src/main/resources/lang/en_us.json b/enigma/src/main/resources/lang/en_us.json index f7ef3c497..9edf40cf3 100644 --- a/enigma/src/main/resources/lang/en_us.json +++ b/enigma/src/main/resources/lang/en_us.json @@ -206,10 +206,10 @@ "javadocs.edit": "Edit Javadocs", "javadocs.instruction": "Edit javadocs here.", - "fonts.cat.default": "Default", + "fonts.cat.default_normal": "Default (normal)", + "fonts.cat.default_bold": "Default (bold)", "fonts.cat.small": "Small", "fonts.cat.editor": "Editor", - "fonts.use_custom": "Use Custom Fonts", "prompt.ok": "OK", "prompt.cancel": "Cancel", diff --git a/enigma/src/main/resources/lang/fr_fr.json b/enigma/src/main/resources/lang/fr_fr.json index 689c36c81..8b4c72e39 100644 --- a/enigma/src/main/resources/lang/fr_fr.json +++ b/enigma/src/main/resources/lang/fr_fr.json @@ -191,10 +191,8 @@ "javadocs.edit": "Éditer les Javadocs", "javadocs.instruction": "Éditer les Javadocs ici.", - "fonts.cat.default": "Par défaut", "fonts.cat.small": "Petit", "fonts.cat.editor": "Éditeur", - "fonts.use_custom": "Utiliser des polices personnalisées", "prompt.ok": "OK", "prompt.cancel": "Annuler", diff --git a/enigma/src/main/resources/lang/ja_jp.json b/enigma/src/main/resources/lang/ja_jp.json index af9f6238c..0a323154e 100644 --- a/enigma/src/main/resources/lang/ja_jp.json +++ b/enigma/src/main/resources/lang/ja_jp.json @@ -144,10 +144,8 @@ "javadocs.edit": "Javadocを編集", "javadocs.instruction": "このJavadocを編集", - "fonts.cat.default": "デフォルト", "fonts.cat.small": "スモール", "fonts.cat.editor": "エディタ", - "fonts.use_custom": "カスタムフォントを使う", "prompt.ok": "OK", "prompt.cancel": "キャンセル", From 3c14d78ac61ce6a6425bc7b1acd9c7b55428658e Mon Sep 17 00:00:00 2001 From: ix0rai Date: Mon, 11 Dec 2023 21:12:35 -0600 Subject: [PATCH 23/25] fix some stuff being ignored --- .../org/quiltmc/enigma/gui/config/DockerConfig.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java index 722d28bff..08a026c74 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DockerConfig.java @@ -93,11 +93,19 @@ public SelectedDockers(String top, String bottom, String full) { public void add(String id, Docker.VerticalLocation location) { switch (location) { case TOP -> { - this.full = ""; + if (!this.full.isBlank()) { + this.bottom = this.full; + this.full = ""; + } + this.top = id; } case BOTTOM -> { - this.full = ""; + if (!this.full.isBlank()) { + this.top = this.full; + this.full = ""; + } + this.bottom = id; } case FULL -> { From 392f01ff25b617e651bff13b0f8bd9ad56b3f393 Mon Sep 17 00:00:00 2001 From: ix0rai Date: Sat, 16 Dec 2023 17:16:28 -0600 Subject: [PATCH 24/25] update qconf version --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a1feeddf8..38551706c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,7 +10,7 @@ syntaxpain = "0.1.1" swing_dpi = "0.10" fontchooser = "2.5.2" tinylog = "2.6.2" -quilt_config = "1.2.0" +quilt_config = "1.2.0-beta.1" vineflower = "1.10.0-20230713.053900-2" cfr = "0.2.1" From 12eb3f2b5fc6d35242fcaec98f6716a6157bad32 Mon Sep 17 00:00:00 2001 From: ix0rai Date: Mon, 18 Dec 2023 17:45:16 -0600 Subject: [PATCH 25/25] add some comments --- .../quiltmc/enigma/network/EnigmaServer.java | 1 - .../org/quiltmc/enigma/gui/config/Config.java | 18 ++++++++++++++---- .../enigma/gui/config/DecompilerConfig.java | 3 ++- .../enigma/gui/config/KeyBindConfig.java | 2 +- .../quiltmc/enigma/gui/config/NetConfig.java | 3 +++ .../quiltmc/enigma/gui/element/MenuBar.java | 4 ++-- 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/enigma-server/src/main/java/org/quiltmc/enigma/network/EnigmaServer.java b/enigma-server/src/main/java/org/quiltmc/enigma/network/EnigmaServer.java index 78a2fd758..10eb511d6 100644 --- a/enigma-server/src/main/java/org/quiltmc/enigma/network/EnigmaServer.java +++ b/enigma-server/src/main/java/org/quiltmc/enigma/network/EnigmaServer.java @@ -31,7 +31,6 @@ import java.util.concurrent.CopyOnWriteArrayList; public abstract class EnigmaServer { - // https://discordapp.com/channels/507304429255393322/566418023372816394/700292322918793347 public static final int DEFAULT_PORT = 34712; public static final int PROTOCOL_VERSION = 1; public static final int CHECKSUM_SIZE = 20; diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java index 742154ab3..85d817c1e 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java @@ -1,6 +1,7 @@ package org.quiltmc.enigma.gui.config; import org.quiltmc.config.api.ReflectiveConfig; +import org.quiltmc.config.api.annotations.Comment; import org.quiltmc.config.api.annotations.SerializedName; import org.quiltmc.config.api.serializer.TomlSerializer; import org.quiltmc.config.api.values.ComplexConfigValue; @@ -22,6 +23,11 @@ import java.nio.file.Path; import java.nio.file.Paths; +/** + * The Enigma config is separated into five different files: {@link Config the main config (this one)}, + * {@link NetConfig the networking configuration}, {@link KeyBindConfig the keybinding configuration}, + * {@link DockerConfig the docker configuration}, and {@link DecompilerConfig the decompiler configuration}. + */ public final class Config extends ReflectiveConfig { private static final String FORMAT = "toml"; private static final String FAMILY = "enigma"; @@ -34,20 +40,24 @@ public final class Config extends ReflectiveConfig { private static final DecompilerConfig DECOMPILER = ConfigFactory.create(ENVIRONMENT, FAMILY, "decompiler", DecompilerConfig.class); @SerializedName("language") + @Comment("The currently assigned UI language. This will be an ISO-639 two-letter language code, followed by an underscore and an ISO 3166-1 alpha-2 two-letter country code.") public final TrackedValue language = this.value(I18n.DEFAULT_LANGUAGE); @SerializedName("scale_factor") + @Comment("A float representing the current size of the UI. 1.0 represents 100% scaling.") public final TrackedValue scaleFactor = this.value(1.0f); - @SerializedName("max_recent_files") - public final TrackedValue maxRecentFiles = this.value(10); + @SerializedName("max_recent_projects") + @Comment("The maximum number of saved recent projects, for quickly reopening.") + public final TrackedValue maxRecentProjects = this.value(10); @SerializedName("recent_projects") public final TrackedValue> recentProjects = this.list(new RecentProject("", "")); @SerializedName("server_notification_level") + @Comment("Modifies how many notifications you'll get while part of a multiplayer mapping server.") public final TrackedValue serverNotificationLevel = this.value(NotificationManager.ServerNotificationLevel.FULL); - @SerializedName("use_custom_fonts") - public final TrackedValue useCustomFonts = this.value(false); @SerializedName("window_size") + @Comment("How big the Enigma window will open, in pixels.") public final TrackedValue windowSize = this.value(new Vec2i(1024, 576)); @SerializedName("window_pos") + @Comment("The position the top-left corner of Enigma's window will be the next time it opens, in pixels.") public final TrackedValue windowPos = this.value(new Vec2i(0, 0)); public final StatsSection stats = new StatsSection(); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java index 0d88fa2e7..2be6ef608 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/DecompilerConfig.java @@ -1,6 +1,7 @@ package org.quiltmc.enigma.gui.config; import org.quiltmc.config.api.ReflectiveConfig; +import org.quiltmc.config.api.annotations.Comment; import org.quiltmc.config.api.annotations.SerializedName; import org.quiltmc.config.api.values.TrackedValue; import org.quiltmc.config.api.values.ValueMap; @@ -17,11 +18,11 @@ public DecompilerConfig() { @SerializedName("active_decompiler") public final TrackedValue activeDecompiler = this.value(Decompiler.VINEFLOWER); + @Comment("The options passed to the Vineflower decompiler. What these do can be found here: https://vineflower.org/usage/.") public final VineflowerSection vineflower = new VineflowerSection(); public static final class VineflowerSection extends Section { @SerializedName("string_values") - public final TrackedValue> stringValues = this.map("").build(); @SerializedName("int_values") public final TrackedValue> intValues = this.map(0).build(); diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindConfig.java index b11771d31..4bce24fe5 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/KeyBindConfig.java @@ -13,7 +13,7 @@ public final class KeyBindConfig extends ReflectiveConfig { public String[] getKeyCodes(KeyBind keyBind) { ValueList codes = this.keyCodes.value().get(keyBind.name()); - return (codes == null || codes.size() == 0) ? keyBind.serializeCombinations() : codes.toArray(String[]::new); + return (codes == null || codes.isEmpty()) ? keyBind.serializeCombinations() : codes.toArray(String[]::new); } public void setBind(KeyBind keyBind) { diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NetConfig.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NetConfig.java index 79033043d..98831147f 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NetConfig.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/NetConfig.java @@ -1,12 +1,14 @@ package org.quiltmc.enigma.gui.config; import org.quiltmc.config.api.ReflectiveConfig; +import org.quiltmc.config.api.annotations.Comment; import org.quiltmc.config.api.annotations.SerializedName; import org.quiltmc.config.api.values.TrackedValue; import org.quiltmc.enigma.network.EnigmaServer; public final class NetConfig extends ReflectiveConfig { @SerializedName("username") + @Comment("Your username for multiplayer mapping. Defaults to the system username.") public final TrackedValue username = this.value(System.getProperty("user.name", "user")); @SerializedName("password") public final TrackedValue password = this.value(""); @@ -15,5 +17,6 @@ public final class NetConfig extends ReflectiveConfig { @SerializedName("server_password") public final TrackedValue serverPassword = this.value(""); @SerializedName("server_port") + @Comment("The network port of this server. Interesting fact! The default was decided pretty much at random in the Fabric discord: https://discordapp.com/channels/507304429255393322/566418023372816394/700292322918793347 (server: https://fabricmc.net/discuss/). You can still blame 2xsaiko if it conflicts with anything.") public final TrackedValue serverPort = this.value(EnigmaServer.DEFAULT_PORT); } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java index e345e5c65..355bb6b23 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/element/MenuBar.java @@ -295,7 +295,7 @@ private void onOpenJarClicked() { } private void onMaxRecentFilesClicked() { - String input = JOptionPane.showInputDialog(this.gui.getFrame(), I18n.translate("menu.file.dialog.max_recent_projects.set"), Config.main().maxRecentFiles.value()); + String input = JOptionPane.showInputDialog(this.gui.getFrame(), I18n.translate("menu.file.dialog.max_recent_projects.set"), Config.main().maxRecentProjects.value()); if (input != null) { try { @@ -304,7 +304,7 @@ private void onMaxRecentFilesClicked() { throw new NumberFormatException(); } - Config.main().maxRecentFiles.setValue(max, true); + Config.main().maxRecentProjects.setValue(max, true); } catch (NumberFormatException e) { JOptionPane.showMessageDialog(this.gui.getFrame(), I18n.translate("prompt.invalid_input"), I18n.translate("prompt.error"), JOptionPane.ERROR_MESSAGE); }