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