Skip to content

Commit c666d36

Browse files
committed
Integrate settings types into regular settings (#22)
1 parent 96b1b5d commit c666d36

File tree

4 files changed

+42
-21
lines changed

4 files changed

+42
-21
lines changed

src/main/java/the/bytecode/club/jda/decompilers/FernflowerDecompiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public FernflowerDecompiler() {
4848
settings.registerSetting(new SettingsEntry("udv", "Recover variable names", true));
4949
settings.registerSetting(new SettingsEntry("rer", "Remove empty exceptions", true));
5050
settings.registerSetting(new SettingsEntry("fdi", "De-inline finally", true));
51-
settings.registerSetting(new SettingsEntry("mpm", "Maximum processing time", "0", Setting.SettingType.INT)); // this is a numeric setting!
51+
settings.registerSetting(new SettingsEntry("mpm", "Maximum processing time", 0, Setting.SettingType.INT)); // this is a numeric setting!
5252
settings.registerSetting(new SettingsEntry("ren", "Rename ambigious members", false));
5353
// urc: IIDentifierRenamer
5454
settings.registerSetting(new SettingsEntry("inn", "Remove IntelliJ @NotNull", true));

src/main/java/the/bytecode/club/jda/settings/DecompilerSettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public static class SettingsEntry extends Setting {
140140
public final String param;
141141

142142
public SettingsEntry(String param, String key, Object value, SettingType type) {
143-
super("todo lmao", key, value, type);
143+
super(null, key, value, type);
144144
this.param = param;
145145
}
146146

src/main/java/the/bytecode/club/jda/settings/Setting.java

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,59 @@
11
package the.bytecode.club.jda.settings;
22

3+
import static the.bytecode.club.jda.settings.Setting.SettingType.*;
4+
35
public class Setting {
46
public final String node; //TODO: convert to JSON node or something
57
public final String key;
68
public final SettingType type;
79
private Object value;
810

9-
public Setting(String key, String value) {
10-
this("settings", key, value, SettingType.STRING);
11-
}
12-
13-
public Setting(String node, String key, Object value) {
14-
this(node, key, value, SettingType.STRING);
15-
}
16-
1711
public Setting(String node, String key, Object value, SettingType type) {
1812
this.node = node;
1913
this.key = key;
2014
this.value = value;
2115
this.type = type;
2216
}
2317

18+
public Setting(String node, String key, Object value) {
19+
this(node, key, value, STRING);
20+
}
21+
22+
public Setting(String key, Object value, SettingType type) {
23+
this("settings", key, value, type);
24+
}
25+
26+
public Setting(String key, String value) {
27+
this(key, (Object)value, STRING);
28+
}
29+
2430
public String get() {
2531
return value.toString();
2632
}
2733

2834
public boolean getBool() {
29-
return Boolean.parseBoolean(get());
35+
return (boolean) value;
3036
}
3137

3238
public int getInt() {
33-
return Integer.parseInt(get());
39+
return (int) value;
3440
}
3541

3642
public void set(Object value) {
37-
this.value = value.toString();
43+
switch (type) {
44+
case BOOLEAN:
45+
this.value = value instanceof Boolean ? value : Boolean.parseBoolean(value.toString());
46+
break;
47+
case INT:
48+
this.value = value instanceof Integer ? value : Integer.parseInt(value.toString());
49+
break;
50+
case OPTIONS:
51+
throw new UnsupportedOperationException();
52+
case STRING:
53+
default:
54+
this.value = value.toString();
55+
break;
56+
}
3857
}
3958

4059
public boolean isEmpty() {

src/main/java/the/bytecode/club/jda/settings/Settings.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import java.util.ArrayList;
1515
import java.util.List;
1616

17+
import static the.bytecode.club.jda.settings.Setting.SettingType.*;
18+
1719
/**
1820
* Used to handle loading/saving the GUI (options).
1921
*
@@ -24,14 +26,14 @@ public class Settings {
2426

2527
// todo: I should really refactor this
2628
public static final Setting PATH = new Setting("path", "");
27-
public static final Setting SHOW_CONTAINER_NAME = new Setting("showfilename", "false");
28-
public static final Setting SNAP_TO_EDGES = new Setting("snaptoedges", "false");
29-
public static final Setting DO_UPDATE_CHECK = new Setting("doupdatecheck", "true");
30-
public static final Setting REFRESH_ON_VIEW_CHANGE = new Setting("refreshonviewchange", "false");
31-
32-
public static final Setting FONT_SIZE = new Setting("font", "fontsize", "12");
33-
public static final Setting FONT_FAMILY = new Setting("font", "fontfamily", Font.MONOSPACED); // TODO: Doesn't save properly.
34-
public static final Setting FONT_OPTIONS = new Setting("font", "fontoptions", String.valueOf(Font.PLAIN));
29+
public static final Setting SHOW_CONTAINER_NAME = new Setting("showfilename", false, BOOLEAN);
30+
public static final Setting SNAP_TO_EDGES = new Setting("snaptoedges", false, BOOLEAN);
31+
public static final Setting DO_UPDATE_CHECK = new Setting("doupdatecheck", true, BOOLEAN);
32+
public static final Setting REFRESH_ON_VIEW_CHANGE = new Setting("refreshonviewchange", false, BOOLEAN);
33+
34+
public static final Setting FONT_SIZE = new Setting("font", "fontsize", 12, INT);
35+
public static final Setting FONT_FAMILY = new Setting("font", "fontfamily", Font.MONOSPACED);
36+
public static final Setting FONT_OPTIONS = new Setting("font", "fontoptions", Font.PLAIN, INT);
3537

3638
static
3739
{

0 commit comments

Comments
 (0)