Changeset 1242 for trunk/src/org/expeditee/settings/UserSettings.java
- Timestamp:
- 03/15/19 16:48:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/settings/UserSettings.java
r1227 r1242 22 22 import java.io.FileNotFoundException; 23 23 import java.io.IOException; 24 import java.nio.file.Paths; 24 25 import java.util.ArrayList; 25 import java.util.Collection;26 26 import java.util.LinkedList; 27 27 import java.util.List; … … 34 34 import org.expeditee.gui.FrameUtils; 35 35 import org.expeditee.gui.MessageBay; 36 import org.expeditee.items.Item;37 36 import org.expeditee.items.Text; 38 37 import org.expeditee.setting.BooleanSetting; … … 53 52 54 53 public static String DEFAULT_PROFILE_NAME = "default"; 55 56 public static final IntegerSetting Gravity = new IntegerSetting("Distance the cursor has to be from a text item to select the text item", 3); 54 55 public static Boolean multiUserMode; 56 57 public static final IntegerSetting Gravity = new IntegerSetting("Distance the cursor has to be from a text item to select the text item", "Gravity", 3); 57 58 58 59 public static final StringSetting StartFrame = new StringSetting("The frame to go to when Expeditee is started (defaults to the profile frame)", null); … … 82 83 } 83 84 }; 84 public static final IntegerSetting InitialWidth = new IntegerSetting("Initial width of Expeditee window", 1024);85 86 public static final IntegerSetting InitialHeight = new IntegerSetting("Initial height of Expeditee window", 768);85 public static final IntegerSetting InitialWidth = new IntegerSetting("Initial width of Expeditee window", "InitialWidth", 1024); 86 87 public static final IntegerSetting InitialHeight = new IntegerSetting("Initial height of Expeditee window", "InitialHeight", 768); 87 88 88 89 /* … … 90 91 */ 91 92 92 public static final FloatSetting ScaleFactor = new FloatSetting("Scale Factor for drawing (TODO: does this even do anything?)", 1F); 93 94 public static final FloatSetting FormatSpacingMin = new FloatSetting("Minimum spacing ratio", null); 95 96 public static final FloatSetting FormatSpacingMax = new FloatSetting("Maximum spacing ratio", null); 97 98 public static final IntegerSetting LineStraightenThreshold = new IntegerSetting("Threshold for straightening a line (TODO: does this even do anything?)", 15); 99 100 public static final IntegerSetting NoOpThreshold = new IntegerSetting("Distance the cursor may be dragged before Gestures must be reinterpreted. E.g. Copy becomes range.", 10); 101 102 public static final IntegerSetting TitlePosition = new IntegerSetting("Position of title item in frame (TODO: find whether this is x-offset or y-offset)", 150); 103 104 public static final StringSetting ProfileName = new StringSetting("Profile name", FrameIO.ConvertToValidFramesetName(System.getProperty("user.name"))) { 93 public static final FloatSetting ScaleFactor = new FloatSetting("Scale Factor for drawing (TODO: does this even do anything?)", "ScaleFactor", 1F); 94 95 public static final FloatSetting FormatSpacingMin = new FloatSetting("Minimum spacing ratio", "FormatSpacingMin", null); 96 97 public static final FloatSetting FormatSpacingMax = new FloatSetting("Maximum spacing ratio", "FormatSpacingMax", null); 98 99 public static final IntegerSetting LineStraightenThreshold = new IntegerSetting("Threshold for straightening a line (TODO: does this even do anything?)", "LineStraightenThreshold", 15); 100 101 public static final IntegerSetting NoOpThreshold = new IntegerSetting("Distance the cursor may be dragged before Gestures must be reinterpreted. E.g. Copy becomes range.", "NoOpThreshold", 10); 102 103 public static final IntegerSetting TitlePosition = new IntegerSetting("Position of title item in frame (TODO: find whether this is x-offset or y-offset)", "TitlePosition", 150); 104 105 public static final StringSetting ProfileName = new StringSetting("Profile name", FrameIO.ConvertToValidFramesetName(System.getProperty("user.name"))); 106 107 public static final StringSetting UserName = new StringSetting("User name", ProfileName.get()); 105 108 106 /** Commit the change to the appropriate frame */ 107 public void set(String value) { 108 super.set(value); 109 commitToSettingsFrameItem(value, "ProfileName:"); 110 }; 111 112 /** If authenticated, then resetting ProfileName should not do anything. */ 113 public void reset() { 114 if (!Authenticated.get()) { 115 super.reset(); 116 } 117 }; 118 }; 119 120 public static final StringSetting UserName = new StringSetting("User name", ProfileName.get()) { 121 /** Commit the change to the appropriate frame */ 122 public void set(String value) { 123 super.set(value); 124 commitToSettingsFrameItem(value, "UserName:"); 125 }; 126 127 /** If authenticated, then resetting UserName should not do anything. */ 128 public void reset() { 129 if (!Authenticated.get()) { 130 super.reset(); 131 } 132 }; 133 }; 134 135 public static final BooleanSetting AntiAlias = new BooleanSetting("Whether anti-aliasing should be enabled", false); 136 137 public static final BooleanSetting LineHighlight = new BooleanSetting("Whether lines should be highlighted", false); 138 139 public static final BooleanSetting Logging = new BooleanSetting("Whether logging should be enabled", false); 140 141 public static final BooleanSetting LogStats = new BooleanSetting("Whether stats should be logged", true); 142 143 public static final BooleanSetting Threading = new BooleanSetting("Whether threading should be enabled", true); 144 145 public static final BooleanSetting Authenticated = new BooleanSetting("Whether the current user is authenticated", false) { 146 public void set(Boolean value) { 147 super.set(value); 148 commitToSettingsFrameItem(value, "Authenticated:"); 149 } 150 151 // Authenticated must be maintained rather than rely on default value. 152 public void reset() {}; 153 154 public boolean setSetting(Text text) { 155 return super.setSetting(text); 156 }; 157 }; 158 109 public static final BooleanSetting AntiAlias = new BooleanSetting("Whether anti-aliasing should be enabled", "AntiAlias", false); 110 111 public static final BooleanSetting LineHighlight = new BooleanSetting("Whether lines should be highlighted", "LineHighlight", false); 112 113 public static final BooleanSetting Logging = new BooleanSetting("Whether logging should be enabled", "Logging", false); 114 115 public static final BooleanSetting LogStats = new BooleanSetting("Whether stats should be logged", "LogStats", true); 116 117 public static final BooleanSetting Threading = new BooleanSetting("Whether threading should be enabled", "Threading", true); 118 159 119 /* 160 120 * Frames … … 167 127 * Other 168 128 */ 169 public static final ListSetting<Text> Style = new ListSetting<Text>("Set the style (TODO: what does this do?)" ) {129 public static final ListSetting<Text> Style = new ListSetting<Text>("Set the style (TODO: what does this do?)", "Style") { 170 130 @Override 171 131 public boolean setSetting(Text text) { … … 196 156 }; 197 157 198 public static final FunctionSetting SpellChecker = new FunctionSetting("Enables the dictionary with the default dictionary" ) {158 public static final FunctionSetting SpellChecker = new FunctionSetting("Enables the dictionary with the default dictionary", "SpellChecker") { 199 159 @Override 200 160 public void run() { … … 208 168 } 209 169 }; 210 public static final FrameSetting Spelling = new FrameSetting("Enables the dictionary and adds the items in the child frame to the dictionary" ) {170 public static final FrameSetting Spelling = new FrameSetting("Enables the dictionary and adds the items in the child frame to the dictionary", "Spelling") { 211 171 @Override 212 172 public void run(Frame frame) { … … 219 179 }; 220 180 221 public static final FrameSetting GreenstoneSettings = new FrameSetting("Greenstone settings (TODO: What are these for?)" ) {181 public static final FrameSetting GreenstoneSettings = new FrameSetting("Greenstone settings (TODO: What are these for?)", "GreenstoneSettings") { 222 182 @Override 223 183 public void run(Frame frame) { … … 226 186 }; 227 187 228 public static final FrameSetting Reminders = new FrameSetting("Reminders (TODO: What are these for?)" ) {188 public static final FrameSetting Reminders = new FrameSetting("Reminders (TODO: What are these for?)", "Reminders") { 229 189 @Override 230 190 public void run(Frame frame) { … … 233 193 }; 234 194 235 public static final FrameSetting MailSettings = new FrameSetting("Mail Settings (TODO: How does this work?)" ) {195 public static final FrameSetting MailSettings = new FrameSetting("Mail Settings (TODO: How does this work?)", "MailSettings") { 236 196 @Override 237 197 public void run(Frame frame) { … … 242 202 // add default values 243 203 static { 204 // Are we in the new regime or the old regime? 205 File resFile = Paths.get(getDesiredExpediteeHome()).resolve(".res").toFile(); 206 File resourcesPrivateFile = Paths.get(getDesiredExpediteeHome() + "resources-private" + File.separator).toFile(); 207 if (resourcesPrivateFile.exists()) { 208 // If resources-private exists than this is a good sign we have new regime available. 209 multiUserMode = Boolean.TRUE; 210 } else if (resFile.exists()) { 211 // If we do not, but do have the .res file then this is a good sign we are in old regime. 212 multiUserMode = Boolean.FALSE; 213 } else { 214 // If we have neither then we are unpacking and therefore will have new regime available once unpacked. 215 multiUserMode = Boolean.TRUE; 216 } 217 244 218 setupDefaultFolders(); 245 219 } 246 247 public static void setupDefaultFolders() { 248 String expeditee_home = System.getProperty("expeditee.home"); 249 if (expeditee_home != null) { 250 FrameIO.changeParentFolder(expeditee_home + File.separator); 251 } else { 252 FrameIO.changeParentFolder(getSaveLocation()); 253 } 220 221 public static void setupDefaultFolders() { 222 FrameIO.changeParentFolder(getDesiredExpediteeHome()); 254 223 255 224 FolderSettings.FrameDirs.get().clear(); … … 258 227 } 259 228 229 private static String getDesiredExpediteeHome() { 230 String homeProperty = System.getProperty("expeditee.home"); 231 String expeditee_home = homeProperty == null ? getSaveLocation() : homeProperty + File.separator; 232 return expeditee_home; 233 } 234 260 235 public static void appendDefaultFolders() { 261 FolderSettings.FrameDirs.get().add(FrameIO.FRAME_PATH); 262 FolderSettings.FrameDirs.get().add(FrameIO.PUBLIC_PATH); 263 FolderSettings.FrameDirs.get().add(FrameIO.PROFILE_PATH); 264 FolderSettings.FrameDirs.get().add(FrameIO.HELP_PATH); 265 FolderSettings.FrameDirs.get().add(FrameIO.MESSAGES_PATH); 266 FolderSettings.FrameDirs.get().add(FrameIO.SHARED_BY_ME_FRAMESETS); 267 FolderSettings.FrameDirs.get().add(FrameIO.SHARED_WITH_ME_FRAMESETS); 268 FolderSettings.FrameDirs.setDefault(FolderSettings.FrameDirs.get()); 269 FolderSettings.ImageDirs.get().add(FrameIO.IMAGES_PATH); 270 FolderSettings.ImageDirs.setDefault(FolderSettings.ImageDirs.get()); 236 if (multiUserMode) { 237 // The comments here explain how things have changed with the new regime. 238 // FrameDirs 239 // 1. PROFILE_PATH Still points to same place. 240 // 2. SHARED_FRAMESETS_PATH Still points to same place. (encryption stops just anyone reading it) 241 // 3. framesets-<username> Generated on user account creation and must be refreshed on user switching. Also gives access to tutorial stuffs. 242 // 4. FRAME_PATH <expeditee-home>\resources-public\framesets. 243 // 5. HELP_PUBLIC_PATH <expeditee-home>\resources-public\documentation. 244 // 6. MESSAGES_PATH Still points to same place. Should these be per user and encrypted? 245 // 7. PUBLIC_PATH Still points to same place. Kept for compatibility. 246 FolderSettings.FrameDirs.get().add(FrameIO.PROFILE_PATH); 247 FolderSettings.FrameDirs.get().add(FrameIO.FRAME_PRIVATE_PATH); 248 FolderSettings.FrameDirs.get().add(FrameIO.SHARED_FRAMESETS_PATH); 249 FolderSettings.FrameDirs.get().add(FrameIO.FRAME_PATH); 250 FolderSettings.FrameDirs.get().add(FrameIO.RESOURCES_PATH); 251 FolderSettings.FrameDirs.get().add(FrameIO.MESSAGES_PATH); 252 FolderSettings.FrameDirs.get().add(FrameIO.PUBLIC_PATH); 253 FolderSettings.FrameDirs.setDefault(FolderSettings.FrameDirs.get()); 254 255 // ImageDirs 256 // 1. resources-<username>\images Generated on user account creation and must be refreshed on user switching. 257 // 2. IMAGES_PATH <expeditee-home>\resources-public\images 258 FolderSettings.ImageDirs.get().add(FrameIO.IMAGES_PRIVATE_PATH); 259 FolderSettings.ImageDirs.get().add(FrameIO.IMAGES_PATH); 260 FolderSettings.ImageDirs.setDefault(FolderSettings.ImageDirs.get()); 261 } else { 262 FolderSettings.FrameDirs.get().add(FrameIO.FRAME_PATH); 263 FolderSettings.FrameDirs.get().add(FrameIO.PUBLIC_PATH); 264 FolderSettings.FrameDirs.get().add(FrameIO.PROFILE_PATH); 265 FolderSettings.FrameDirs.get().add(FrameIO.HELP_PATH); 266 FolderSettings.FrameDirs.get().add(FrameIO.MESSAGES_PATH); 267 FolderSettings.FrameDirs.setDefault(FolderSettings.FrameDirs.get()); 268 FolderSettings.ImageDirs.get().add(FrameIO.IMAGES_PATH); 269 FolderSettings.ImageDirs.setDefault(FolderSettings.ImageDirs.get()); 270 } 271 271 } 272 272 … … 291 291 } 292 292 } 293 294 private static void commitToSettingsFrameItem(Object value, String contentMatch) {295 String profileName = UserSettings.UserName.get();296 int lastNumber = FrameIO.getLastNumber(profileName);297 for (int i = 1; i <= lastNumber; i++) {298 Frame frame = FrameIO.LoadFrame(profileName + i);299 if (frame != null) {300 Collection<Item> items = frame.getAllItems();301 boolean found = false;302 for (Item item: items) {303 if (item.getText().startsWith(contentMatch)) {304 item.setText(contentMatch + " " + value);305 }306 }307 if (found) { break; }308 }309 }310 }311 293 }
Note:
See TracChangeset
for help on using the changeset viewer.