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 | return null;
|
---|
190 | }
|
---|
191 | };
|
---|
192 |
|
---|
193 | public static final TextSetting ItemTemplate = new TextSetting("Template for normal text items") {
|
---|
194 | @Override
|
---|
195 | public boolean setSetting(Text text) {
|
---|
196 | _value = text.getTemplateForm();
|
---|
197 | return true;
|
---|
198 | }
|
---|
199 |
|
---|
200 | @Override
|
---|
201 | public Text generateText() {
|
---|
202 | return new Text("@ItemTemplate");
|
---|
203 | }
|
---|
204 | };
|
---|
205 |
|
---|
206 | public static final TextSetting DotTemplate = new TextSetting("Template for dot items") {
|
---|
207 | @Override
|
---|
208 | public boolean setSetting(Text text) {
|
---|
209 | _value = text.getTemplateForm();
|
---|
210 | return true;
|
---|
211 | }
|
---|
212 |
|
---|
213 | @Override
|
---|
214 | public Text generateText() {
|
---|
215 | return new Text("@DotTemplate");
|
---|
216 | }
|
---|
217 | };
|
---|
218 |
|
---|
219 | public static final TextSetting AnnotationTemplate = new TextSetting("Template for annotation text items") {
|
---|
220 | @Override
|
---|
221 | public boolean setSetting(Text text) {
|
---|
222 | _value = text.getTemplateForm();
|
---|
223 | return true;
|
---|
224 | }
|
---|
225 | @Override
|
---|
226 | public Text generateText() {
|
---|
227 | Text t = new Text("@AnnotationTemplate");
|
---|
228 | t.setColor(Color.gray);
|
---|
229 | return t;
|
---|
230 | }
|
---|
231 | };
|
---|
232 |
|
---|
233 | public static final TextSetting CodeCommentTemplate = new TextSetting("Template for code comment text items") {
|
---|
234 | @Override
|
---|
235 | public boolean setSetting(Text text) {
|
---|
236 | _value = text.getTemplateForm();
|
---|
237 | return true;
|
---|
238 | }
|
---|
239 | @Override
|
---|
240 | public Text generateText() {
|
---|
241 | Text t = new Text("@CommentTemplate");
|
---|
242 | t.setColor(Color.green.darker());
|
---|
243 | return t;
|
---|
244 | }
|
---|
245 | };
|
---|
246 |
|
---|
247 | public static final TextSetting StatTemplate = new TextSetting("Template for statistics (e.g. extracted attributes) text items") {
|
---|
248 | @Override
|
---|
249 | public boolean setSetting(Text text) {
|
---|
250 | _value = text.getTemplateForm();
|
---|
251 | return true;
|
---|
252 | }
|
---|
253 | @Override
|
---|
254 | public Text generateText() {
|
---|
255 | Text t = new Text("@StatsTemplate");
|
---|
256 | t.setColor(Color.BLACK);
|
---|
257 | t.setBackgroundColor(new Color(0.9F, 0.9F, 0.9F));
|
---|
258 | t.setFamily(Text.MONOSPACED_FONT);
|
---|
259 | t.setSize(14);
|
---|
260 | return t;
|
---|
261 | }
|
---|
262 | };
|
---|
263 |
|
---|
264 | public static final TextSetting TooltipTemplate = new TextSetting("Template for tooltips") {
|
---|
265 | @Override
|
---|
266 | public boolean setSetting(Text text) {
|
---|
267 | _value = text.getTemplateForm();
|
---|
268 | return true;
|
---|
269 | }
|
---|
270 | @Override
|
---|
271 | public Text generateText() {
|
---|
272 | Text t = new Text("@StatsTemplate");
|
---|
273 | t.setColor(Color.BLACK);
|
---|
274 | t.setBackgroundColor(new Color(0.7F, 0.7F, 0.9F));
|
---|
275 | // t.setFamily(Text.MONOSPACED_FONT);
|
---|
276 | t.setSize(14);
|
---|
277 | return t;
|
---|
278 | }
|
---|
279 | };
|
---|
280 |
|
---|
281 | /*
|
---|
282 | * Colorwheels
|
---|
283 | */
|
---|
284 | public static final FrameSetting ColorWheel = new FrameSetting("The colours of items in the child frame are used to populate the colour wheel") {
|
---|
285 | @Override
|
---|
286 | protected void run(Frame frame) {
|
---|
287 | Item.COLOR_WHEEL = FrameUtils.getColorWheel(frame);
|
---|
288 | }
|
---|
289 | };
|
---|
290 |
|
---|
291 | public static final FrameSetting FillColorWheel = 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.FILL_COLOR_WHEEL = FrameUtils.getColorWheel(frame);
|
---|
295 | }
|
---|
296 | };
|
---|
297 |
|
---|
298 | public static final FrameSetting BackgroundColorWheel = 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 | Frame.COLOR_WHEEL = FrameUtils.getColorWheel(frame);
|
---|
302 | }
|
---|
303 | };
|
---|
304 |
|
---|
305 | /*
|
---|
306 | * Other
|
---|
307 | */
|
---|
308 | public static final ListSetting<Text> Style = new ListSetting<Text>("Set the style (TODO: what does this do?)") {
|
---|
309 | @Override
|
---|
310 | public boolean setSetting(Text text) {
|
---|
311 | Frame child = text.getChild();
|
---|
312 | if (child == null) {
|
---|
313 | _value = new LinkedList<Text>();
|
---|
314 | return true;
|
---|
315 | }
|
---|
316 |
|
---|
317 |
|
---|
318 | List<Text> style = new ArrayList<Text>(8);
|
---|
319 | for (int i = 0; i < 10; i++) {
|
---|
320 | style.add(null);
|
---|
321 | }
|
---|
322 |
|
---|
323 | for (Text t : child.getBodyTextItems(false)) {
|
---|
324 | String type = t.getText();
|
---|
325 | char lastChar = type.charAt(type.length() - 1);
|
---|
326 | if (Character.isDigit(lastChar)) {
|
---|
327 | style.set(lastChar - '0', t);
|
---|
328 | } else {
|
---|
329 | style.set(0, t);
|
---|
330 | }
|
---|
331 | }
|
---|
332 | _value = style;
|
---|
333 | return true;
|
---|
334 | }
|
---|
335 | };
|
---|
336 |
|
---|
337 | public static final FunctionSetting SpellChecker = new FunctionSetting("Enables the dictionary with the default dictionary") {
|
---|
338 | @Override
|
---|
339 | public void run() {
|
---|
340 | try {
|
---|
341 | JSpellChecker.create();
|
---|
342 | } catch (FileNotFoundException e) {
|
---|
343 | MessageBay.errorMessage("Could not find dictionary: " + e.getMessage());
|
---|
344 | } catch (IOException e) {
|
---|
345 | e.printStackTrace();
|
---|
346 | }
|
---|
347 | }
|
---|
348 | };
|
---|
349 | public static final FrameSetting Spelling = new FrameSetting("Enables the dictionary and adds the items in the child frame to the dictionary") {
|
---|
350 | @Override
|
---|
351 | public void run(Frame frame) {
|
---|
352 | try {
|
---|
353 | JSpellChecker.create(frame);
|
---|
354 | } catch (Exception e) {
|
---|
355 | e.printStackTrace();
|
---|
356 | }
|
---|
357 | }
|
---|
358 | };
|
---|
359 |
|
---|
360 | public static final FrameSetting GreenstoneSettings = new FrameSetting("Greenstone settings (TODO: What are these for?)") {
|
---|
361 | @Override
|
---|
362 | public void run(Frame frame) {
|
---|
363 | SearchGreenstone.init(frame);
|
---|
364 | }
|
---|
365 | };
|
---|
366 |
|
---|
367 | public static final FrameSetting Reminders = new FrameSetting("Reminders (TODO: What are these for?)") {
|
---|
368 | @Override
|
---|
369 | public void run(Frame frame) {
|
---|
370 | org.expeditee.gui.Reminders.init(frame);
|
---|
371 | }
|
---|
372 | };
|
---|
373 |
|
---|
374 | public static final FrameSetting MailSettings = new FrameSetting("Mail Settings (TODO: How does this work?)") {
|
---|
375 | @Override
|
---|
376 | public void run(Frame frame) {
|
---|
377 | MailSession.init(frame);
|
---|
378 | }
|
---|
379 | };
|
---|
380 |
|
---|
381 | 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)") {
|
---|
382 | @Override
|
---|
383 | public void run(Frame frame) {
|
---|
384 | FreeItems.getCursor().addAll(ItemUtils.CopyItems(frame.getAllItems()));
|
---|
385 | for (Item i : FreeItems.getCursor()) {
|
---|
386 | i.setParent(null);
|
---|
387 | }
|
---|
388 | DisplayIO.setCursor(Item.HIDDEN_CURSOR);
|
---|
389 | DisplayIO.setCursor(Item.DEFAULT_CURSOR);
|
---|
390 | }
|
---|
391 | };
|
---|
392 |
|
---|
393 |
|
---|
394 | // add default values
|
---|
395 | static {
|
---|
396 | String expeditee_home = System.getProperty("expeditee.home");
|
---|
397 | if (expeditee_home != null) {
|
---|
398 | FrameIO.changeParentFolder(expeditee_home + File.separator);
|
---|
399 | } else {
|
---|
400 | FrameIO.changeParentFolder(getSaveLocation());
|
---|
401 | }
|
---|
402 |
|
---|
403 | UserSettings.FrameDirs.get().add(FrameIO.FRAME_PATH);
|
---|
404 | UserSettings.FrameDirs.get().add(FrameIO.PUBLIC_PATH);
|
---|
405 | UserSettings.FrameDirs.get().add(FrameIO.PROFILE_PATH);
|
---|
406 | UserSettings.FrameDirs.get().add(FrameIO.HELP_PATH);
|
---|
407 | UserSettings.FrameDirs.get().add(FrameIO.MESSAGES_PATH);
|
---|
408 | UserSettings.FrameDirs.setDefault(UserSettings.FrameDirs.get());
|
---|
409 | UserSettings.ImageDirs.get().add(FrameIO.IMAGES_PATH);
|
---|
410 | UserSettings.ImageDirs.setDefault(UserSettings.ImageDirs.get());
|
---|
411 | }
|
---|
412 |
|
---|
413 | /**
|
---|
414 | * Find the appropriate directory to store application settings in for
|
---|
415 | * the current OS.
|
---|
416 | * This has only been tested on Linux so far, so if it doesn't work it
|
---|
417 | * may need to be modified or reverted. Should return:
|
---|
418 | * Linux: ~/.expeditee
|
---|
419 | * Windows: %appdata%\.expeditee
|
---|
420 | * Mac: ~/Library/Application\ Support/.expeditee
|
---|
421 | * @return the path to store expeditee's settings
|
---|
422 | */
|
---|
423 | public static String getSaveLocation() {
|
---|
424 | String OS=System.getProperty("os.name").toLowerCase();
|
---|
425 | if(OS.indexOf("win")>0) { //windoze
|
---|
426 | return System.getenv("APPDATA")+File.separator+".expeditee"+File.separator;
|
---|
427 | } else if(OS.indexOf("mac")>0) { //mac
|
---|
428 | return System.getProperty("user.home")+File.separator+"Library"+File.separator+"Application Support"+File.separator+".expeditee"+File.separator;
|
---|
429 | } else { //linux or other
|
---|
430 | return System.getProperty("user.home")+File.separator+".expeditee"+File.separator;
|
---|
431 | }
|
---|
432 | }
|
---|
433 | }
|
---|