|
5 | 5 | import java.lang.reflect.ParameterizedType; |
6 | 6 | import java.lang.reflect.Type; |
7 | 7 | import java.util.ArrayList; |
| 8 | +import java.util.Arrays; |
8 | 9 | import java.util.HashSet; |
9 | 10 | import java.util.List; |
10 | 11 | import java.util.Set; |
@@ -36,20 +37,22 @@ public SwingConfiguration(Object config) |
36 | 37 | { |
37 | 38 | if(IGNORED_VALUES.contains(field.getName())) |
38 | 39 | continue; |
39 | | - fieldsList.add(new ConfigItem(field)); |
| 40 | + fieldsList.add(new ConfigItem(config, field)); |
40 | 41 | } |
41 | 42 | } |
42 | 43 |
|
43 | 44 | public static class ConfigItem |
44 | 45 | { |
45 | 46 | private final Field field; |
46 | 47 | public final ItemType type; |
| 48 | + private Object instance; |
47 | 49 |
|
48 | 50 | /** The swing component that we'll use to call the set value */ |
49 | 51 | public Object component; |
50 | 52 |
|
51 | | - public ConfigItem(Field field) |
| 53 | + public ConfigItem(Object instance, Field field) |
52 | 54 | { |
| 55 | + this.instance = instance; |
53 | 56 | this.field = field; |
54 | 57 | if(field.getType().equals(File.class)) |
55 | 58 | type = ItemType.FILE; |
@@ -81,16 +84,54 @@ public Object getValue() |
81 | 84 | return ((JTextField)component).getText(); |
82 | 85 | if(type == ItemType.BOOLEAN) |
83 | 86 | return ((JCheckBox)component).isSelected(); |
84 | | - //For LIST types, we return DefaultListModel |
85 | | - return component; |
| 87 | + return Arrays.asList(((DefaultListModel<?>)component).toArray()); |
86 | 88 | } |
87 | 89 |
|
88 | 90 | /** |
89 | | - * Sets the value. Used when run deobfuscator is clicked. |
| 91 | + * Sets the component value with the field value. Used on first load and load config. |
| 92 | + */ |
| 93 | + public void setValue() |
| 94 | + { |
| 95 | + if(getFieldValue() == null) |
| 96 | + return; |
| 97 | + if(type == ItemType.FILE) |
| 98 | + ((JTextField)component).setText((String)getFieldValue()); |
| 99 | + else if(type == ItemType.BOOLEAN) |
| 100 | + ((JCheckBox)component).setSelected((Boolean)getFieldValue()); |
| 101 | + else |
| 102 | + { |
| 103 | + DefaultListModel<Object> listModel = (DefaultListModel<Object>)component; |
| 104 | + listModel.clear(); |
| 105 | + List<?> fieldValue = (List<?>)getFieldValue(); |
| 106 | + for(Object o : fieldValue) |
| 107 | + listModel.addElement(o); |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + /** |
| 112 | + * Gets the field value (used on first load) |
| 113 | + */ |
| 114 | + public Object getFieldValue() |
| 115 | + { |
| 116 | + try |
| 117 | + { |
| 118 | + return Reflect.getFieldO(instance, field.getName()); |
| 119 | + }catch(Exception e) |
| 120 | + { |
| 121 | + return null; |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * Sets the field value with the component value. Used when run deobfuscator is clicked. |
90 | 127 | */ |
91 | 128 | public void setFieldValue() |
92 | 129 | { |
93 | | - //TODO |
| 130 | + try |
| 131 | + { |
| 132 | + Reflect.setFieldO(instance, field.getName(), getValue()); |
| 133 | + }catch(Exception e) |
| 134 | + {} |
94 | 135 | } |
95 | 136 |
|
96 | 137 | } |
|
0 commit comments