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

Last change on this file since 641 was 641, checked in by jts21, 11 years ago

Generated settings frames now use capitalised setting names, and settings are generated/displayed in the order they were declared in code.
Settings with no value no longer have a ':' after their name (good for some things, however maybe we should be showing somehow that some settings can have a value set after a colon, and others use a frame linked from the setting item, and others just use the properties of the setting item?).
Password setting(s) now use the password widget.
Fixed some problems with settings that try to work without having a value set (SpellChecker, ColorWheels, HomeFrame).

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