Changeset 1102 for trunk/src/org/expeditee/settings/Settings.java
- Timestamp:
- 05/10/18 16:04:51 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/settings/Settings.java
r919 r1102 26 26 27 27 import org.expeditee.gui.AttributeValuePair; 28 import org.expeditee.gui.DisplayIO;29 28 import org.expeditee.gui.Frame; 30 29 import org.expeditee.gui.FrameCreator; … … 32 31 import org.expeditee.gui.FrameUtils; 33 32 import org.expeditee.gui.MessageBay; 34 import org.expeditee.items.Item;35 33 import org.expeditee.items.Text; 36 34 import org.expeditee.items.widgets.Password; … … 56 54 // populate map of settings 57 55 for(Field f : clazz.getFields()) { 58 // only allow valid types 59 if(! Setting.class.isAssignableFrom(f.getType())) { 60 continue; 61 } 56 // Only allow classes that inherit from Setting 57 if(!Setting.class.isAssignableFrom(f.getType())) continue; 58 62 59 try { 63 60 Setting s = (Setting) f.get(null); 64 61 settings.put(f.getName().toLowerCase(), s); 65 if(s instanceof VariableSetting) { 66 settingsList.add((VariableSetting) s); 67 } 62 if (s instanceof VariableSetting) settingsList.add((VariableSetting) s); 68 63 orderedEntries.add(f.getName()); 69 64 } catch (Exception e) { … … 71 66 } 72 67 } 68 73 69 Method m = null; 70 74 71 try { 75 72 m = clazz.getMethod("onParsed", Text.class); … … 77 74 // System.err.println(clazz.getName() + " has no onParsed(Text t) callback"); 78 75 } 76 79 77 this.onParsed = m; 80 78 } 81 79 } 80 82 81 private static HashMap<String, PageDescriptor> _pages = new HashMap<String, PageDescriptor>(); 83 82 84 83 private static boolean _init = false; 85 public static void Init() { 84 85 public static void Init() 86 { 86 87 if(_init) return; 88 87 89 _init = true; 90 88 91 try { 89 92 for(Class<?> clazz : PackageLoader.getClassesNew(SETTINGS_PACKAGE)) { 90 93 // Ignore this class since it's the controller 91 if(clazz.equals(Settings.class)) { 92 continue; 93 } 94 String settingsPage = clazz.getPackage().getName().toLowerCase().substring(SETTINGS_PACKAGE_PARENT.length()); 94 if(clazz.equals(Settings.class)) continue; 95 96 String settingsPageName = clazz.getPackage().getName().toLowerCase().substring(SETTINGS_PACKAGE_PARENT.length()); 95 97 // System.out.println(settingsPage + " : " + clazz.getName()); 96 _pages.put(settingsPage , new PageDescriptor(clazz));98 _pages.put(settingsPageName, new PageDescriptor(clazz)); 97 99 } 98 100 … … 100 102 e.printStackTrace(); 101 103 } 102 FrameUtils.ParseProfile(FrameIO.LoadProfile(UserSettings.ProfileName.get())); 103 } 104 105 /** 106 * Parses the settings tree, then resets any settings that were not set 107 */ 108 public static void parseSettings(Text text) { 104 } 105 106 /** Parses the settings tree, then resets any settings that were not set. */ 107 public static void parseSettings(Text text) 108 { 109 109 List<VariableSetting> set = parseSettings(text, ""); 110 110 List<VariableSetting> toDefault = new LinkedList<VariableSetting>(); 111 for(PageDescriptor pd : _pages.values()) {112 113 }111 112 for(PageDescriptor pd : _pages.values()) toDefault.addAll(pd.settingsList); 113 114 114 toDefault.removeAll(set); 115 115 116 for(VariableSetting s : toDefault) { 116 117 try { 117 // System.out.println("Resetting " + s.getTooltip());118 118 s.reset(); 119 // System.out.println("Set " + f.getName() + " to default value " + f.get(null));120 119 } catch (Exception e) { 121 120 e.printStackTrace(); … … 135 134 136 135 List<VariableSetting> set = new LinkedList<VariableSetting>(); 136 137 137 Frame child = text.getChild(); 138 if(child == null) {139 140 }138 139 if(child == null) return set; 140 141 141 String settingsPage = prefix + text.getText().trim().toLowerCase().replaceAll("^@", ""); 142 142 PageDescriptor pd = _pages.get(settingsPage); 143 if(pd == null) { 144 return set; 145 } 143 if(pd == null) return set; 144 146 145 try { 147 146 // set the fields … … 160 159 } 161 160 } 161 162 162 // parse all the settings items on this page 163 163 for(Text t : items) { … … 186 186 } 187 187 } 188 // System.out.println(s); 189 if(s == null) { 190 continue; 191 } 188 189 if(s == null) continue; 190 192 191 if(validPages.size() > 1) { 193 192 StringBuffer warnMessage = new StringBuffer("Found multiple matching settings in the following settings subpages: "); … … 202 201 } 203 202 } 204 if(s.setSetting(t) && s instanceof VariableSetting) {205 206 }203 204 if(s.setSetting(t) && s instanceof VariableSetting) set.add((VariableSetting) s); 205 207 206 } catch (Exception e) { 208 207 e.printStackTrace(); 209 208 } 210 209 } 210 211 211 // call the onParsed method if one exists 212 212 if(pd.onParsed != null) { 213 213 pd.onParsed.invoke(null, text); 214 214 } 215 215 216 } catch (Exception e) { 216 217 e.printStackTrace(); 217 218 return set; 218 219 } 220 219 221 // if the page was a settings page, check if it has any subpages 220 222 for(Text t : child.getTextItems()) { … … 224 226 } 225 227 226 public static void generateSettingsTree(Text link) { 228 public static void generateSettingsTree(Text link) 229 { 227 230 generateSettingsTree("settings", link); 228 231 } 229 232 230 /** 231 * 232 * Generates settings tree 233 * 234 */ 235 private static void generateSettingsTree(String page, Text text) { 233 /** Generates settings tree */ 234 private static void generateSettingsTree(String page, Text text) 235 { 236 236 FrameCreator frames = new FrameCreator(text.getParentOrCurrentFrame().getFramesetName(), text.getParentOrCurrentFrame().getPath(), page, false, false); 237 237 // Frame frame = FrameIO.CreateFrame(text.getParentOrCurrentFrame().getFramesetName(), page, null);
Note:
See TracChangeset
for help on using the changeset viewer.