source: trunk/src/org/expeditee/settings/UserSettings.java@ 717

Last change on this file since 717 was 717, checked in by jts21, 10 years ago

Changes to settings tree generation, and added vertical/horizontal format help text. Also some commented out code from an attempt to fix XGroupItem ignoring nested rectangles in rectangles reached by an arrow (didn't get anywhere with that)

File size: 14.2 KB
Line 
1package org.expeditee.settings;
2
3import java.awt.Color;
4import java.io.File;
5import java.io.FileNotFoundException;
6import java.io.IOException;
7import java.util.ArrayList;
8import java.util.LinkedList;
9import java.util.List;
10
11import org.expeditee.agents.SearchGreenstone;
12import org.expeditee.agents.mail.MailSession;
13import org.expeditee.agents.wordprocessing.JSpellChecker;
14import org.expeditee.gui.AttributeValuePair;
15import org.expeditee.gui.DisplayIO;
16import org.expeditee.gui.Frame;
17import org.expeditee.gui.FrameIO;
18import org.expeditee.gui.FrameUtils;
19import org.expeditee.gui.FreeItems;
20import org.expeditee.gui.MessageBay;
21import org.expeditee.items.Item;
22import org.expeditee.items.ItemUtils;
23import org.expeditee.items.Text;
24import org.expeditee.setting.BooleanSetting;
25import org.expeditee.setting.FloatSetting;
26import org.expeditee.setting.FrameSetting;
27import org.expeditee.setting.FunctionSetting;
28import org.expeditee.setting.IntegerSetting;
29import org.expeditee.setting.ListSetting;
30import org.expeditee.setting.Setting;
31import org.expeditee.setting.StringSetting;
32import org.expeditee.setting.TextSetting;
33
34/**
35 * Central class to contain all values that can be set by the user on their
36 * profile frame. These values should be updated only by
37 * FrameUtils.ParseProfile.
38 */
39public abstract class UserSettings {
40
41 public final static String DEFAULT_PROFILE_NAME = "default";
42
43 public static final IntegerSetting Gravity = new IntegerSetting("Distance the cursor has to be from a text item to select the text item", 3);
44
45 /*
46 * Stuff that goes first
47 */
48 public static final StringSetting HomeFrame = new StringSetting("The home frame", null) {
49 @Override
50 public boolean setSetting(Text text) {
51 if(text.getText().indexOf(':') == -1 || !text.hasLink()) {
52 text.setLink(FrameIO.LoadProfile(UserSettings.ProfileName.get()).getName());
53 }
54 String first = FrameUtils.getLink(text, UserSettings.HomeFrame.get());
55 // do not use non-existant frames as the first frame
56 if (FrameIO.isValidFrameName(first)) {
57 _value = first;
58 }
59 // warn the user
60 else {
61 // MessageBay.warningMessage("Home frame: " + first
62 // + " is not a valid frame.");
63 _value = FrameIO.LoadProfile(UserSettings.ProfileName.get()).getName();
64 }
65 return true;
66 }
67 };
68 public static final StringSetting DefaultFrame = new StringSetting("The default frame", null) {
69 @Override
70 public boolean setSetting(Text text) {
71 _value = FrameUtils.getLink(text, _value);
72 return true;
73 }
74 };
75 public static final IntegerSetting InitialWidth = new IntegerSetting("Initial width of Expeditee window", 1024);
76
77 public static final IntegerSetting InitialHeight = new IntegerSetting("Initial height of Expeditee window", 768);
78
79 public static final TextSetting ItemTemplate = new TextSetting("Template for normal text items") {
80 @Override
81 public boolean setSetting(Text text) {
82 _value = text.getTemplateForm();
83 return true;
84 }
85
86 @Override
87 public Text generateText() {
88 return new Text("ItemTemplate");
89 }
90 };
91 public static final TextSetting AnnotationTemplate = new TextSetting("Template for annotation text items") {
92 @Override
93 public boolean setSetting(Text text) {
94 _value = text.getTemplateForm();
95 return true;
96 }
97 @Override
98 public Text generateText() {
99 Text t = new Text("AnnotationTemplate");
100 t.setColor(Color.gray);
101 return t;
102 }
103 };
104
105 public static final TextSetting CommentTemplate = new TextSetting("Template for code comment text items") {
106 @Override
107 public boolean setSetting(Text text) {
108 _value = text.getTemplateForm();
109 return true;
110 }
111 @Override
112 public Text generateText() {
113 Text t = new Text("CommentTemplate");
114 t.setColor(Color.green.darker());
115 return t;
116 }
117 };
118
119 public static final TextSetting StatTemplate = new TextSetting("Template for statistics (e.g. extracted attributes) text items") {
120 @Override
121 public boolean setSetting(Text text) {
122 _value = text.getTemplateForm();
123 return true;
124 }
125 @Override
126 public Text generateText() {
127 Text t = new Text("StatsTemplate");
128 t.setColor(Color.BLACK);
129 t.setBackgroundColor(new Color(0.9F, 0.9F, 0.9F));
130 t.setFamily(Text.MONOSPACED_FONT);
131 t.setSize(14);
132 return t;
133 }
134 };
135
136 /*
137 * General settings (no setter functions)
138 */
139
140 public static final FloatSetting ScaleFactor = new FloatSetting("Scale Factor for drawing (TODO: does this even do anything?)", 1F);
141
142 public static final FloatSetting FormatSpacingMin = new FloatSetting("Minimum spacing ratio", null);
143
144 public static final FloatSetting FormatSpacingMax = new FloatSetting("Maximum spacing ratio", null);
145
146 public static final IntegerSetting LineStraightenThreshold = new IntegerSetting("Threshold for straightening a line (TODO: does this even do anything?)", 15);
147
148 public static final IntegerSetting NoOpThreshold = new IntegerSetting("Distance the cursor may be dragged while clicking before the operation is cancelled", 60);
149
150 public static final IntegerSetting TitlePosition = new IntegerSetting("Position of title item in frame (TODO: find whether this is x-offset or y-offset)", 150);
151
152 public static final StringSetting ProfileName = new StringSetting("Profile name", FrameIO.ConvertToValidFramesetName(System.getProperty("user.name")));
153
154 public static final StringSetting UserName = new StringSetting("User name", ProfileName.get());
155
156 public static final BooleanSetting AntiAlias = new BooleanSetting("Whether anti-aliasing should be enabled", false);
157
158 public static final BooleanSetting LineHighlight = new BooleanSetting("Whether lines should be highlighted", false);
159
160 public static final BooleanSetting Logging = new BooleanSetting("Whether logging should be enabled", false);
161
162 public static final BooleanSetting LogStats = new BooleanSetting("Whether stats should be logged", true);
163
164 public static final BooleanSetting Threading = new BooleanSetting("Whether threading should be enabled", true);
165
166
167 /*
168 * Frames
169 */
170
171 public static final StringSetting StatisticsFrameset = new StringSetting("The statistics frameset", null);
172
173 public static final StringSetting MenuFrame = new StringSetting("The menu frame", null);
174
175 /*
176 * Directories
177 */
178 public static final ListSetting<String> FrameDirs = new ListSetting<String>("Directories to look in for frames") {
179 @Override
180 public boolean setSetting(Text text) {
181 _value.addAll(FrameUtils.getDirs(text));
182 return true;
183 }
184 };
185 public static final Setting FramesetDir = new Setting("Adds a directory to look in for frames") {
186 @Override
187 public boolean setSetting(Text text) {
188 if(text.getText().indexOf(':') == -1) {
189 return false;
190 }
191 AttributeValuePair avp = new AttributeValuePair(text.getText());
192 if(avp.getValue().trim().length() != 0) {
193 String dir = FrameUtils.getDir(avp.getValue());
194 if (dir != null) {
195 UserSettings.FrameDirs.get().add(dir);
196 return true;
197 }
198 }
199 return false;
200 }
201 };
202
203 public static ListSetting<String> ImageDirs = new ListSetting<String>("Directories to look in for images") {
204 @Override
205 public boolean setSetting(Text text) {
206 _value.addAll(FrameUtils.getDirs(text));
207 return true;
208 }
209 };
210 public static final Setting ImageDir = new Setting("Adds a directory to look in for images") {
211 @Override
212 public boolean setSetting(Text text) {
213 if(text.getText().indexOf(':') == -1) {
214 return false;
215 }
216 AttributeValuePair avp = new AttributeValuePair(text.getText());
217 if(avp.getValue().trim().length() != 0) {
218 String dir = FrameUtils.getDir(avp.getValue());
219 if(dir != null) {
220 UserSettings.ImageDirs.get().add(0, dir);
221 return true;
222 }
223 }
224 return false;
225 }
226 };
227
228 public static final Setting LogDir = new Setting("Set the directory to save logs") {
229 @Override
230 public boolean setSetting(Text text) {
231 if(text.getText().indexOf(':') == -1) {
232 return false;
233 }
234 AttributeValuePair avp = new AttributeValuePair(text.getText());
235 if(avp.getValue().trim().length() != 0) {
236 FrameIO.LOGS_DIR = FrameUtils.getDir(avp.getValue());
237 }
238 return true;
239 }
240 };
241
242 /*
243 * Templates
244 */
245 public static final TextSetting TitleTemplate = new TextSetting("Template for Title text item") {
246 @Override
247 public Text generateText() {
248 Text t = new Text("TitleTemplate");
249 t.setSize(30);
250 t.setFontStyle("Bold");
251 t.setFamily("SansSerif");
252 t.setColor(Color.BLUE);
253 t.setPosition(25, 50);
254 return t;
255 }
256 };
257
258 public static final TextSetting DotTemplate = new TextSetting("Template for dot items") {
259 @Override
260 public boolean setSetting(Text text) {
261 _value = text.getTemplateForm();
262 return true;
263 }
264
265 @Override
266 public Text generateText() {
267 return new Text("DotTemplate");
268 }
269 };
270
271 public static final TextSetting TooltipTemplate = new TextSetting("Template for tooltips") {
272 @Override
273 public boolean setSetting(Text text) {
274 _value = text.getTemplateForm();
275 return true;
276 }
277 @Override
278 public Text generateText() {
279 Text t = new Text("TooltipTemplate");
280 t.setColor(Color.BLACK);
281 t.setBackgroundColor(new Color(0.7F, 0.7F, 0.9F));
282 // t.setFamily(Text.MONOSPACED_FONT);
283 t.setSize(14);
284 return t;
285 }
286 };
287
288 /*
289 * Colorwheels
290 */
291 public static final FrameSetting ColorWheel = new FrameSetting("The colours of items in the child frame are used to populate the colour wheel") {
292 @Override
293 protected void run(Frame frame) {
294 Item.COLOR_WHEEL = FrameUtils.getColorWheel(frame);
295 }
296 };
297
298 public static final FrameSetting FillColorWheel = new FrameSetting("The colours of items in the child frame are used to populate the colour wheel") {
299 @Override
300 protected void run(Frame frame) {
301 Item.FILL_COLOR_WHEEL = FrameUtils.getColorWheel(frame);
302 }
303 };
304
305 public static final FrameSetting BackgroundColorWheel = new FrameSetting("The colours of items in the child frame are used to populate the colour wheel") {
306 @Override
307 protected void run(Frame frame) {
308 Frame.COLOR_WHEEL = FrameUtils.getColorWheel(frame);
309 }
310 };
311
312 /*
313 * Other
314 */
315 public static final ListSetting<Text> Style = new ListSetting<Text>("Set the style (TODO: what does this do?)") {
316 @Override
317 public boolean setSetting(Text text) {
318 Frame child = text.getChild();
319 if (child == null) {
320 _value = new LinkedList<Text>();
321 return true;
322 }
323
324
325 List<Text> style = new ArrayList<Text>(8);
326 for (int i = 0; i < 10; i++) {
327 style.add(null);
328 }
329
330 for (Text t : child.getBodyTextItems(false)) {
331 String type = t.getText();
332 char lastChar = type.charAt(type.length() - 1);
333 if (Character.isDigit(lastChar)) {
334 style.set(lastChar - '0', t);
335 } else {
336 style.set(0, t);
337 }
338 }
339 _value = style;
340 return true;
341 }
342 };
343
344 public static final FunctionSetting SpellChecker = new FunctionSetting("Enables the dictionary with the default dictionary") {
345 @Override
346 public void run() {
347 try {
348 JSpellChecker.create();
349 } catch (FileNotFoundException e) {
350 MessageBay.errorMessage("Could not find dictionary: " + e.getMessage());
351 } catch (IOException e) {
352 e.printStackTrace();
353 }
354 }
355 };
356 public static final FrameSetting Spelling = new FrameSetting("Enables the dictionary and adds the items in the child frame to the dictionary") {
357 @Override
358 public void run(Frame frame) {
359 try {
360 JSpellChecker.create(frame);
361 } catch (Exception e) {
362 e.printStackTrace();
363 }
364 }
365 };
366
367 public static final FrameSetting GreenstoneSettings = new FrameSetting("Greenstone settings (TODO: What are these for?)") {
368 @Override
369 public void run(Frame frame) {
370 SearchGreenstone.init(frame);
371 }
372 };
373
374 public static final FrameSetting Reminders = new FrameSetting("Reminders (TODO: What are these for?)") {
375 @Override
376 public void run(Frame frame) {
377 org.expeditee.gui.Reminders.init(frame);
378 }
379 };
380
381 public static final FrameSetting MailSettings = new FrameSetting("Mail Settings (TODO: How does this work?)") {
382 @Override
383 public void run(Frame frame) {
384 MailSession.init(frame);
385 }
386 };
387
388 public static final FrameSetting CursorFrame = new FrameSetting("Items on this frame will be used as the cursor (clearing the frame or removing the link will default back to a normal cursor)") {
389 @Override
390 public void run(Frame frame) {
391 FreeItems.getCursor().addAll(ItemUtils.CopyItems(frame.getAllItems()));
392 for (Item i : FreeItems.getCursor()) {
393 i.setParent(null);
394 }
395 DisplayIO.setCursor(Item.HIDDEN_CURSOR);
396 DisplayIO.setCursor(Item.DEFAULT_CURSOR);
397 }
398 };
399
400
401 // add default values
402 static {
403 String expeditee_home = System.getProperty("expeditee.home");
404 if (expeditee_home != null) {
405 FrameIO.changeParentFolder(expeditee_home + File.separator);
406 } else {
407 FrameIO.changeParentFolder(getSaveLocation());
408 }
409
410 UserSettings.FrameDirs.get().add(FrameIO.FRAME_PATH);
411 UserSettings.FrameDirs.get().add(FrameIO.PUBLIC_PATH);
412 UserSettings.FrameDirs.get().add(FrameIO.PROFILE_PATH);
413 UserSettings.FrameDirs.get().add(FrameIO.HELP_PATH);
414 UserSettings.FrameDirs.get().add(FrameIO.MESSAGES_PATH);
415 UserSettings.FrameDirs.setDefault(UserSettings.FrameDirs.get());
416 UserSettings.ImageDirs.get().add(FrameIO.IMAGES_PATH);
417 UserSettings.ImageDirs.setDefault(UserSettings.ImageDirs.get());
418 }
419
420 /**
421 * Find the appropriate directory to store application settings in for
422 * the current OS.
423 * This has only been tested on Linux so far, so if it doesn't work it
424 * may need to be modified or reverted. Should return:
425 * Linux: ~/.expeditee
426 * Windows: %appdata%\.expeditee
427 * Mac: ~/Library/Application\ Support/.expeditee
428 * @return the path to store expeditee's settings
429 */
430 public static String getSaveLocation() {
431 String OS=System.getProperty("os.name").toLowerCase();
432 if(OS.indexOf("win")>0) { //windoze
433 return System.getenv("APPDATA")+File.separator+".expeditee"+File.separator;
434 } else if(OS.indexOf("mac")>0) { //mac
435 return System.getProperty("user.home")+File.separator+"Library"+File.separator+"Application Support"+File.separator+".expeditee"+File.separator;
436 } else { //linux or other
437 return System.getProperty("user.home")+File.separator+".expeditee"+File.separator;
438 }
439 }
440}
Note: See TracBrowser for help on using the repository browser.