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

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

Move ColorWheels to UserSettings, store them as new ArraySetting type that handles default values (so now ColorWheels have defaults if you unlink their setting)

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