1 | package org.expeditee.settings;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.io.FileNotFoundException;
|
---|
5 | import java.io.IOException;
|
---|
6 | import java.util.ArrayList;
|
---|
7 | import java.util.LinkedList;
|
---|
8 | import java.util.List;
|
---|
9 |
|
---|
10 | import org.expeditee.agents.SearchGreenstone;
|
---|
11 | import org.expeditee.agents.mail.MailSession;
|
---|
12 | import org.expeditee.agents.wordprocessing.JSpellChecker;
|
---|
13 | import org.expeditee.gui.AttributeValuePair;
|
---|
14 | import org.expeditee.gui.DisplayIO;
|
---|
15 | import org.expeditee.gui.Frame;
|
---|
16 | import org.expeditee.gui.FrameIO;
|
---|
17 | import org.expeditee.gui.FrameUtils;
|
---|
18 | import org.expeditee.gui.FreeItems;
|
---|
19 | import org.expeditee.gui.MessageBay;
|
---|
20 | import org.expeditee.gui.Reminders;
|
---|
21 | import org.expeditee.items.Item;
|
---|
22 | import org.expeditee.items.ItemUtils;
|
---|
23 | import org.expeditee.items.Text;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Central class to contain all values that can be set by the user on their
|
---|
27 | * profile frame. These values should be updated only by
|
---|
28 | * FrameUtils.ParseProfile.
|
---|
29 | */
|
---|
30 | public abstract class UserSettings {
|
---|
31 |
|
---|
32 | public final static String DEFAULT_PROFILE_NAME = "default";
|
---|
33 |
|
---|
34 | /*
|
---|
35 | * General settings (no setter functions)
|
---|
36 | */
|
---|
37 | public static int Gravity = 3;
|
---|
38 |
|
---|
39 | public static float ScaleFactor = 1F;
|
---|
40 |
|
---|
41 | public static int LineStraightenThreshold = 15;
|
---|
42 |
|
---|
43 | public static int NoOpThreshold = 60;
|
---|
44 |
|
---|
45 | public static int TitlePosition = 150;
|
---|
46 |
|
---|
47 | public static int InitialWidth = 1024;
|
---|
48 |
|
---|
49 | public static int InitialHeight = 768;
|
---|
50 |
|
---|
51 | public static String ProfileName;
|
---|
52 |
|
---|
53 | public static String UserName;
|
---|
54 |
|
---|
55 | public static boolean AntiAlias = false;
|
---|
56 |
|
---|
57 | public static boolean LineHighlight = false;
|
---|
58 |
|
---|
59 | public static boolean Logging = false;
|
---|
60 |
|
---|
61 | public static boolean LogStats = true;
|
---|
62 |
|
---|
63 | public static boolean Threading = true;
|
---|
64 |
|
---|
65 |
|
---|
66 | /*
|
---|
67 | * Frames
|
---|
68 | */
|
---|
69 | public static String DefaultFrame = null;
|
---|
70 | public static void setDefaultFrame(Text t) {
|
---|
71 | UserSettings.DefaultFrame = FrameUtils.getLink(t, UserSettings.DefaultFrame);
|
---|
72 | }
|
---|
73 |
|
---|
74 | public static String StatisticsFrameset = null;
|
---|
75 |
|
---|
76 | public static String MenuFrame = null;
|
---|
77 |
|
---|
78 | public static String HomeFrame = null;
|
---|
79 | public static void setHomeFrame(Text t) {
|
---|
80 | String first = FrameUtils.getLink(t, UserSettings.HomeFrame);
|
---|
81 | // do not use non-existant frames as the first frame
|
---|
82 | if (FrameIO.isValidFrameName(first)) {
|
---|
83 | UserSettings.HomeFrame = first;
|
---|
84 | }
|
---|
85 | // warn the user
|
---|
86 | else {
|
---|
87 | // MessageBay.warningMessage("Home frame: " + first
|
---|
88 | // + " is not a valid frame.");
|
---|
89 | UserSettings.HomeFrame = FrameIO.LoadProfile(UserSettings.ProfileName).getName();
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 | /*
|
---|
94 | * Directories
|
---|
95 | */
|
---|
96 | public static List<String> FrameDirs = new LinkedList<String>();
|
---|
97 | public static void setFrameDirs(Text t) {
|
---|
98 | UserSettings.FrameDirs.addAll(FrameUtils.getDirs(t));
|
---|
99 | }
|
---|
100 | public static void setFramesetDir(Text t) {
|
---|
101 | String dir = FrameUtils.getDir(new AttributeValuePair(t.getText()).getValue());
|
---|
102 | if (dir != null) {
|
---|
103 | UserSettings.FrameDirs.add(dir);
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | public static List<String> ImageDirs = new LinkedList<String>();
|
---|
108 | public static void setImageDirs(Text t) {
|
---|
109 | UserSettings.ImageDirs.addAll(FrameUtils.getDirs(t));
|
---|
110 | }
|
---|
111 | public static void setImageDir(Text t) {
|
---|
112 | String dir = FrameUtils.getDir(new AttributeValuePair(t.getText()).getValue());
|
---|
113 | if (dir != null) {
|
---|
114 | UserSettings.ImageDirs.add(0, dir);
|
---|
115 | }
|
---|
116 | }
|
---|
117 |
|
---|
118 | public static void setLogDir(Text t) {
|
---|
119 | org.expeditee.gui.FrameIO.LOGS_DIR = FrameUtils.getDir(new AttributeValuePair(t.getText()).getValue());
|
---|
120 | }
|
---|
121 |
|
---|
122 | /*
|
---|
123 | * Templates
|
---|
124 | */
|
---|
125 | public static Text TitleTemplate = null;
|
---|
126 |
|
---|
127 | public static Text ItemTemplate = new Text("@ItemTemplate");
|
---|
128 | public static void setItemTemplate(Text t) {
|
---|
129 | UserSettings.ItemTemplate = t.getTemplateForm();
|
---|
130 | }
|
---|
131 |
|
---|
132 | public static Text DotTemplate = new Text("@DotTemplate");
|
---|
133 | public static void setDotTemplate(Text t) {
|
---|
134 | UserSettings.DotTemplate = t.getTemplateForm();
|
---|
135 | }
|
---|
136 |
|
---|
137 | public static Text AnnotationTemplate = null;
|
---|
138 | public static void setAnnotationTemplate(Text t) {
|
---|
139 | UserSettings.AnnotationTemplate = t.getTemplateForm();
|
---|
140 | }
|
---|
141 |
|
---|
142 | public static Text CodeCommentTemplate = null;
|
---|
143 | public static void setCommentTemplate(Text t) {
|
---|
144 | UserSettings.CodeCommentTemplate = t.getTemplateForm();
|
---|
145 | }
|
---|
146 |
|
---|
147 | public static Text StatTemplate = null;
|
---|
148 | public static void setStatsTemplate(Text t) {
|
---|
149 | UserSettings.StatTemplate = t.getTemplateForm();
|
---|
150 | }
|
---|
151 |
|
---|
152 | /*
|
---|
153 | * Colorwheels
|
---|
154 | */
|
---|
155 | public static void setColorWheel(Text t) {
|
---|
156 | Item.COLOR_WHEEL = FrameUtils.getColorWheel(t);
|
---|
157 | }
|
---|
158 |
|
---|
159 | public static void setFillColorWheel(Text t) {
|
---|
160 | Item.FILL_COLOR_WHEEL = FrameUtils.getColorWheel(t);
|
---|
161 | }
|
---|
162 |
|
---|
163 | public static void setBackgroundColorWheel(Text t) {
|
---|
164 | Frame.COLOR_WHEEL = FrameUtils.getColorWheel(t);
|
---|
165 | }
|
---|
166 |
|
---|
167 | /*
|
---|
168 | * Other
|
---|
169 | */
|
---|
170 | public static List<Text> Style = new LinkedList<Text>();
|
---|
171 | public static void setStyle(Text t) {
|
---|
172 | Frame child = t.getChild();
|
---|
173 | if (child == null)
|
---|
174 | UserSettings.Style = new LinkedList<Text>();
|
---|
175 |
|
---|
176 | List<Text> style = new ArrayList<Text>(8);
|
---|
177 | for (int i = 0; i < 10; i++) {
|
---|
178 | style.add(null);
|
---|
179 | }
|
---|
180 |
|
---|
181 | for (Text text : child.getBodyTextItems(false)) {
|
---|
182 | String type = text.getText();
|
---|
183 | char lastChar = type.charAt(type.length() - 1);
|
---|
184 | if (Character.isDigit(lastChar)) {
|
---|
185 | style.set(lastChar - '0', text);
|
---|
186 | } else {
|
---|
187 | style.set(0, text);
|
---|
188 | }
|
---|
189 | }
|
---|
190 | UserSettings.Style = style;
|
---|
191 | }
|
---|
192 |
|
---|
193 | public static void setSpellChecker(Text t) {
|
---|
194 | try {
|
---|
195 | JSpellChecker.create();
|
---|
196 | } catch (FileNotFoundException e) {
|
---|
197 | MessageBay.errorMessage("Could not find dictionary: "
|
---|
198 | + e.getMessage());
|
---|
199 | } catch (IOException e) {
|
---|
200 | e.printStackTrace();
|
---|
201 | }
|
---|
202 | }
|
---|
203 | public static void setSpelling(Text t) {
|
---|
204 | try {
|
---|
205 | JSpellChecker.create(t.getChild());
|
---|
206 | } catch (Exception e) {
|
---|
207 | e.printStackTrace();
|
---|
208 | }
|
---|
209 | }
|
---|
210 |
|
---|
211 | public static void setGreenstoneSettings(Text t) {
|
---|
212 | SearchGreenstone.init(t.getChild());
|
---|
213 | }
|
---|
214 |
|
---|
215 | public static void setReminders(Text t) {
|
---|
216 | Reminders.init(t.getChild());
|
---|
217 | }
|
---|
218 |
|
---|
219 | public static void setFormatSpacingMin(Text t) {
|
---|
220 | FrameUtils.MINIMUM_SPACING_RATIO = new AttributeValuePair(t.getText()).getDoubleValue();
|
---|
221 | }
|
---|
222 |
|
---|
223 | public static void setFormatSpacingMax(Text t) {
|
---|
224 | FrameUtils.MAXIMUM_SPACING_RATIO = new AttributeValuePair(t.getText()).getDoubleValue();
|
---|
225 | }
|
---|
226 |
|
---|
227 | public static void setMailSettings(Text t) {
|
---|
228 | MailSession.init(t.getChild());
|
---|
229 | }
|
---|
230 |
|
---|
231 | public static void setCursorFrame(Text t) {
|
---|
232 | if (t.getChild() != null) {
|
---|
233 | FreeItems.getCursor().addAll(ItemUtils.CopyItems(t.getChild().getAllItems()));
|
---|
234 | for (Item i : FreeItems.getCursor()) {
|
---|
235 | i.setParent(null);
|
---|
236 | }
|
---|
237 | DisplayIO.setCursor(Item.HIDDEN_CURSOR);
|
---|
238 | DisplayIO.setCursor(Item.DEFAULT_CURSOR);
|
---|
239 | }
|
---|
240 | }
|
---|
241 |
|
---|
242 |
|
---|
243 | // add default values
|
---|
244 | static {
|
---|
245 | String expeditee_home = System.getProperty("expeditee.home");
|
---|
246 | if (expeditee_home != null) {
|
---|
247 | FrameIO.changeParentFolder(expeditee_home + File.separator);
|
---|
248 | } else {
|
---|
249 | FrameIO.changeParentFolder(getSaveLocation());
|
---|
250 | }
|
---|
251 |
|
---|
252 | UserSettings.FrameDirs.add(FrameIO.FRAME_PATH);
|
---|
253 | UserSettings.FrameDirs.add(FrameIO.PUBLIC_PATH);
|
---|
254 | UserSettings.FrameDirs.add(FrameIO.PROFILE_PATH);
|
---|
255 | UserSettings.FrameDirs.add(FrameIO.HELP_PATH);
|
---|
256 | UserSettings.ImageDirs.add(FrameIO.IMAGES_PATH);
|
---|
257 | UserSettings.FrameDirs.add(FrameIO.MESSAGES_PATH);
|
---|
258 | }
|
---|
259 |
|
---|
260 | /**
|
---|
261 | * Find the appropriate directory to store application settings in for
|
---|
262 | * the current OS.
|
---|
263 | * This has only been tested on Linux so far, so if it doesn't work it
|
---|
264 | * may need to be modified or reverted. Should return:
|
---|
265 | * Linux: ~/.expeditee
|
---|
266 | * Windows: %appdata%\.expeditee
|
---|
267 | * Mac: ~/Library/Application\ Support/.expeditee
|
---|
268 | * @return the path to store expeditee's settings
|
---|
269 | */
|
---|
270 | public static String getSaveLocation() {
|
---|
271 | String OS=System.getProperty("os.name").toLowerCase();
|
---|
272 | if(OS.indexOf("win")>0) { //windoze
|
---|
273 | return System.getenv("APPDATA")+File.separator+".expeditee"+File.separator;
|
---|
274 | } else if(OS.indexOf("mac")>0) { //mac
|
---|
275 | return System.getProperty("user.home")+File.separator+"Library"+File.separator+"Application Support"+File.separator+".expeditee"+File.separator;
|
---|
276 | } else { //linux or other
|
---|
277 | return System.getProperty("user.home")+File.separator+".expeditee"+File.separator;
|
---|
278 | }
|
---|
279 | }
|
---|
280 | }
|
---|