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