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