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