source: trunk/src/org/expeditee/settings/UserSettings.java@ 639

Last change on this file since 639 was 639, checked in by jts21, 10 years ago

Add method to generate a settings tree containing all settings, and their default values (if applicable)
TODO: Use mixed-case for the setting names instead of printing out the lowercase values (they're lowercase because they're keys for a hashmap)
TODO: Fix settings such as SpellChecker which are enabled simply by existing on the frame (i.e. modify them so they take a true/false value instead)

File size: 8.9 KB
Line 
1package org.expeditee.settings;
2
3import java.io.File;
4import java.io.FileNotFoundException;
5import java.io.IOException;
6import java.util.ArrayList;
7import java.util.LinkedList;
8import java.util.List;
9
10import org.expeditee.agents.SearchGreenstone;
11import org.expeditee.agents.mail.MailSession;
12import org.expeditee.agents.wordprocessing.JSpellChecker;
13import org.expeditee.gui.AttributeValuePair;
14import org.expeditee.gui.DisplayIO;
15import org.expeditee.gui.Frame;
16import org.expeditee.gui.FrameIO;
17import org.expeditee.gui.FrameUtils;
18import org.expeditee.gui.FreeItems;
19import org.expeditee.gui.MessageBay;
20import org.expeditee.gui.Reminders;
21import org.expeditee.items.Item;
22import org.expeditee.items.ItemUtils;
23import 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 */
30public 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 = null;
114 AttributeValuePair avp = new AttributeValuePair(t.getText());
115 if(avp.getValue().trim().length() != 0) {
116 dir = FrameUtils.getDir(avp.getValue());
117 }
118 if (dir != null) {
119 UserSettings.FrameDirs.add(dir);
120 }
121 }
122
123 public static List<String> ImageDirs = new LinkedList<String>();
124 public static void setImageDirs(Text t) {
125 UserSettings.ImageDirs.addAll(FrameUtils.getDirs(t));
126 }
127 public static void setImageDir(Text t) {
128 String dir = null;
129 AttributeValuePair avp = new AttributeValuePair(t.getText());
130 if(avp.getValue().trim().length() != 0) {
131 dir = FrameUtils.getDir(avp.getValue());
132 }
133 if (dir != null) {
134 UserSettings.ImageDirs.add(0, dir);
135 }
136 }
137
138 public static void setLogDir(Text t) {
139 AttributeValuePair avp = new AttributeValuePair(t.getText());
140 if(avp.getValue().trim().length() != 0) {
141 FrameIO.LOGS_DIR = FrameUtils.getDir(avp.getValue());
142 }
143 }
144
145 /*
146 * Templates
147 */
148 public static Text TitleTemplate = null;
149
150 public static Text ItemTemplate = new Text("@ItemTemplate");
151 public static void setItemTemplate(Text t) {
152 UserSettings.ItemTemplate = t.getTemplateForm();
153 }
154
155 public static Text DotTemplate = new Text("@DotTemplate");
156 public static void setDotTemplate(Text t) {
157 UserSettings.DotTemplate = t.getTemplateForm();
158 }
159
160 public static Text AnnotationTemplate = null;
161 public static void setAnnotationTemplate(Text t) {
162 UserSettings.AnnotationTemplate = t.getTemplateForm();
163 }
164
165 public static Text CodeCommentTemplate = null;
166 public static void setCommentTemplate(Text t) {
167 UserSettings.CodeCommentTemplate = t.getTemplateForm();
168 }
169
170 public static Text StatTemplate = null;
171 public static void setStatsTemplate(Text t) {
172 UserSettings.StatTemplate = t.getTemplateForm();
173 }
174
175 /*
176 * Colorwheels
177 */
178 public static void setColorWheel(Text t) {
179 Item.COLOR_WHEEL = FrameUtils.getColorWheel(t);
180 }
181
182 public static void setFillColorWheel(Text t) {
183 Item.FILL_COLOR_WHEEL = FrameUtils.getColorWheel(t);
184 }
185
186 public static void setBackgroundColorWheel(Text t) {
187 Frame.COLOR_WHEEL = FrameUtils.getColorWheel(t);
188 }
189
190 /*
191 * Other
192 */
193 public static List<Text> Style = new LinkedList<Text>();
194 public static void setStyle(Text t) {
195 Frame child = t.getChild();
196 if (child == null) {
197 UserSettings.Style = new LinkedList<Text>();
198 return;
199 }
200
201
202 List<Text> style = new ArrayList<Text>(8);
203 for (int i = 0; i < 10; i++) {
204 style.add(null);
205 }
206
207 for (Text text : child.getBodyTextItems(false)) {
208 String type = text.getText();
209 char lastChar = type.charAt(type.length() - 1);
210 if (Character.isDigit(lastChar)) {
211 style.set(lastChar - '0', text);
212 } else {
213 style.set(0, text);
214 }
215 }
216 UserSettings.Style = style;
217 }
218
219 public static void setSpellChecker(Text t) {
220 try {
221 JSpellChecker.create();
222 } catch (FileNotFoundException e) {
223 MessageBay.errorMessage("Could not find dictionary: "
224 + e.getMessage());
225 } catch (IOException e) {
226 e.printStackTrace();
227 }
228 }
229 public static void setSpelling(Text t) {
230 try {
231 JSpellChecker.create(t.getChild());
232 } catch (Exception e) {
233 e.printStackTrace();
234 }
235 }
236
237 public static void setGreenstoneSettings(Text t) {
238 SearchGreenstone.init(t.getChild());
239 }
240
241 public static void setReminders(Text t) {
242 Reminders.init(t.getChild());
243 }
244
245 public static void setFormatSpacingMin(Text t) {
246 FrameUtils.MINIMUM_SPACING_RATIO = new AttributeValuePair(t.getText()).getDoubleValue();
247 }
248
249 public static void setFormatSpacingMax(Text t) {
250 FrameUtils.MAXIMUM_SPACING_RATIO = new AttributeValuePair(t.getText()).getDoubleValue();
251 }
252
253 public static void setMailSettings(Text t) {
254 MailSession.init(t.getChild());
255 }
256
257 public static void setCursorFrame(Text t) {
258 if (t.getChild() != null) {
259 FreeItems.getCursor().addAll(ItemUtils.CopyItems(t.getChild().getAllItems()));
260 for (Item i : FreeItems.getCursor()) {
261 i.setParent(null);
262 }
263 DisplayIO.setCursor(Item.HIDDEN_CURSOR);
264 DisplayIO.setCursor(Item.DEFAULT_CURSOR);
265 }
266 }
267
268
269 // add default values
270 static {
271 String expeditee_home = System.getProperty("expeditee.home");
272 if (expeditee_home != null) {
273 FrameIO.changeParentFolder(expeditee_home + File.separator);
274 } else {
275 FrameIO.changeParentFolder(getSaveLocation());
276 }
277
278 UserSettings.FrameDirs.add(FrameIO.FRAME_PATH);
279 UserSettings.FrameDirs.add(FrameIO.PUBLIC_PATH);
280 UserSettings.FrameDirs.add(FrameIO.PROFILE_PATH);
281 UserSettings.FrameDirs.add(FrameIO.HELP_PATH);
282 UserSettings.ImageDirs.add(FrameIO.IMAGES_PATH);
283 UserSettings.FrameDirs.add(FrameIO.MESSAGES_PATH);
284 }
285
286 /**
287 * Find the appropriate directory to store application settings in for
288 * the current OS.
289 * This has only been tested on Linux so far, so if it doesn't work it
290 * may need to be modified or reverted. Should return:
291 * Linux: ~/.expeditee
292 * Windows: %appdata%\.expeditee
293 * Mac: ~/Library/Application\ Support/.expeditee
294 * @return the path to store expeditee's settings
295 */
296 public static String getSaveLocation() {
297 String OS=System.getProperty("os.name").toLowerCase();
298 if(OS.indexOf("win")>0) { //windoze
299 return System.getenv("APPDATA")+File.separator+".expeditee"+File.separator;
300 } else if(OS.indexOf("mac")>0) { //mac
301 return System.getProperty("user.home")+File.separator+"Library"+File.separator+"Application Support"+File.separator+".expeditee"+File.separator;
302 } else { //linux or other
303 return System.getProperty("user.home")+File.separator+".expeditee"+File.separator;
304 }
305 }
306}
Note: See TracBrowser for help on using the repository browser.