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

Last change on this file since 1440 was 1440, checked in by bnemhaus, 5 years ago

Reordered the default FrameDirs, ImageDirs and AudioDirs to what I think is a logical order.
Also renamed the CURRENT.USER flag to CURRENT_USER to be inline with other flags like CURRENT_FRAMESET

File size: 12.5 KB
Line 
1/**
2 * UserSettings.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.settings;
20
21import java.io.File;
22import java.io.FileNotFoundException;
23import java.io.IOException;
24import java.nio.file.Paths;
25import java.util.ArrayList;
26import java.util.LinkedList;
27import java.util.List;
28
29import org.expeditee.agents.SearchGreenstone;
30import org.expeditee.agents.mail.MailSession;
31import org.expeditee.agents.wordprocessing.JSpellChecker;
32import org.expeditee.auth.AuthenticatorBrowser;
33import org.expeditee.gui.Frame;
34import org.expeditee.gui.FrameIO;
35import org.expeditee.gui.FrameUtils;
36import org.expeditee.gui.MessageBay;
37import org.expeditee.gui.management.ProfileManager;
38import org.expeditee.items.Text;
39import org.expeditee.setting.BooleanSetting;
40import org.expeditee.setting.FloatSetting;
41import org.expeditee.setting.FrameSetting;
42import org.expeditee.setting.FunctionSetting;
43import org.expeditee.setting.IntegerSetting;
44import org.expeditee.setting.ListSetting;
45import org.expeditee.setting.StringSetting;
46import org.expeditee.settings.folders.FolderSettings;
47
48/**
49 * Central class to contain all values that can be set by the user on their
50 * profile frame. These values should be updated only by
51 * FrameUtils.ParseProfile.
52 */
53public abstract class UserSettings {
54
55 public static final String DEFAULT_PROFILE_NAME = "default";
56
57 public static Boolean PublicAndPrivateResources;
58
59 public static final IntegerSetting Gravity = new IntegerSetting("Distance the cursor has to be from a text item to select the text item", "Gravity", 3);
60
61 public static final StringSetting StartFrame = new StringSetting("The frame to go to when Expeditee is started (defaults to the profile frame)", null);
62
63 /*
64 * Stuff that goes first
65 */
66 public static final StringSetting HomeFrame = new StringSetting("The home frame", null) {
67 @Override
68 public boolean setSetting(Text text) {
69 String profileName = UserSettings.ProfileName.get();
70 if(text.getText().indexOf(':') == -1 || !text.hasLink()) {
71 if (!profileName.equals(ProfileManager.USER_NAME_PATTERN)) {
72 text.setLink(profileName + "1");
73 }
74 //text.setLink(FrameIO.LoadProfile(UserSettings.ProfileName.get()).getName());
75 }
76 String first = FrameUtils.getLink(text, UserSettings.HomeFrame.get());
77 // do not use non-existent frames as the first frame
78 if (FrameIO.isValidFrameName(first)) {
79 _value = first;
80 }
81 // warn the user
82 else {
83 // MessageBay.warningMessage("Home frame: " + first
84 // + " is not a valid frame.");
85 _value = profileName + "1";//FrameIO.LoadProfile(UserSettings.ProfileName.get()).getName();
86 }
87 return true;
88 }
89 };
90 public static final IntegerSetting InitialWidth = new IntegerSetting("Initial width of Expeditee window", "InitialWidth", 1024);
91
92 public static final IntegerSetting InitialHeight = new IntegerSetting("Initial height of Expeditee window", "InitialHeight", 768);
93
94 /*
95 * General settings (no setter functions)
96 */
97
98 public static final FloatSetting ScaleFactor = new FloatSetting("Scale Factor for drawing (TODO: does this even do anything?)", "ScaleFactor", 1F);
99
100 public static final FloatSetting FormatSpacingMin = new FloatSetting("Minimum spacing ratio", "FormatSpacingMin", null);
101
102 public static final FloatSetting FormatSpacingMax = new FloatSetting("Maximum spacing ratio", "FormatSpacingMax", null);
103
104 public static final IntegerSetting LineStraightenThreshold = new IntegerSetting("Threshold for straightening a line (TODO: does this even do anything?)", "LineStraightenThreshold", 15);
105
106 public static final IntegerSetting NoOpThreshold = new IntegerSetting("Distance the cursor may be dragged before Gestures must be reinterpreted. E.g. Copy becomes range.", "NoOpThreshold", 10);
107
108 public static final IntegerSetting TitlePosition = new IntegerSetting("Position of title item in frame (TODO: find whether this is x-offset or y-offset)", "TitlePosition", 150);
109
110 public static final StringSetting UserName = new StringSetting("User name", "${USER_NAME}"); // FrameIO.ConvertToValidFramesetName(System.getProperty("user.name"))
111
112 public static final StringSetting ProfileName = new StringSetting("Profile name", "${USER_NAME}");
113
114 public static final BooleanSetting AntiAlias = new BooleanSetting("Whether anti-aliasing should be enabled", "AntiAlias", false);
115
116 public static final BooleanSetting LineHighlight = new BooleanSetting("Whether lines should be highlighted", "LineHighlight", false);
117
118 public static final BooleanSetting Logging = new BooleanSetting("Whether logging should be enabled", "Logging", false);
119
120 public static final BooleanSetting LogStats = new BooleanSetting("Whether stats should be logged", "LogStats", true);
121
122 public static final BooleanSetting Threading = new BooleanSetting("Whether threading should be enabled", "Threading", true);
123
124 /*
125 * Frames
126 */
127 public static final StringSetting StatisticsFrameset = new StringSetting("The statistics frameset", null);
128
129 public static final StringSetting MenuFrame = new StringSetting("The menu frame", null);
130
131 /*
132 * Other
133 */
134 public static final ListSetting<Text> Style = new ListSetting<Text>("Set the style (TODO: what does this do?)", "Style") {
135 @Override
136 public boolean setSetting(Text text) {
137 Frame child = text.getChild();
138 if (child == null) {
139 _value = new LinkedList<Text>();
140 return true;
141 }
142
143
144 List<Text> style = new ArrayList<Text>(8);
145 for (int i = 0; i < 10; i++) {
146 style.add(null);
147 }
148
149 for (Text t : child.getBodyTextItems(false)) {
150 String type = t.getText();
151 char lastChar = type.charAt(type.length() - 1);
152 if (Character.isDigit(lastChar)) {
153 style.set(lastChar - '0', t);
154 } else {
155 style.set(0, t);
156 }
157 }
158 _value = style;
159 return true;
160 }
161 };
162
163 public static final FunctionSetting SpellChecker = new FunctionSetting("Enables the dictionary with the default dictionary", "SpellChecker") {
164 @Override
165 public void run() {
166 try {
167 JSpellChecker.create();
168 } catch (FileNotFoundException e) {
169 MessageBay.errorMessage("Could not find dictionary: " + e.getMessage());
170 } catch (IOException e) {
171 e.printStackTrace();
172 }
173 }
174 };
175 public static final FrameSetting Spelling = new FrameSetting("Enables the dictionary and adds the items in the child frame to the dictionary", "Spelling") {
176 @Override
177 public void run(Frame frame) {
178 try {
179 JSpellChecker.create(frame);
180 } catch (Exception e) {
181 e.printStackTrace();
182 }
183 }
184 };
185
186 public static final FrameSetting GreenstoneSettings = new FrameSetting("Greenstone settings (TODO: What are these for?)", "GreenstoneSettings") {
187 @Override
188 public void run(Frame frame) {
189 SearchGreenstone.init(frame);
190 }
191 };
192
193 public static final FrameSetting Reminders = new FrameSetting("Reminders (TODO: What are these for?)", "Reminders") {
194 @Override
195 public void run(Frame frame) {
196 org.expeditee.gui.Reminders.init(frame);
197 }
198 };
199
200 public static final FrameSetting MailSettings = new FrameSetting("Mail Settings (TODO: How does this work?)", "MailSettings") {
201 @Override
202 public void run(Frame frame) {
203 MailSession.init(frame);
204 }
205 };
206
207 // add default values
208 static {
209 // Are we in the new regime or the old regime?
210 File resFile = Paths.get(getExpediteeHome()).resolve(".res").toFile();
211 File resourcesPrivateFile = Paths.get(getExpediteeHome() + "resources-private" + File.separator).toFile();
212 if (resourcesPrivateFile.exists()) {
213 // If resources-private exists then this is a good sign we have new regime available.
214 PublicAndPrivateResources = Boolean.TRUE;
215 } else if (resFile.exists()) {
216 // If we do not, but do have the .res file then this is a good sign we are in old regime.
217 PublicAndPrivateResources = Boolean.FALSE;
218 } else {
219 // If we have neither then we are unpacking and therefore will have new regime available once unpacked.
220 PublicAndPrivateResources = Boolean.TRUE;
221 }
222
223 setupDefaultFolders();
224 }
225
226 public static void setupDefaultFolders() {
227 String expeditee_home = getExpediteeHome();
228
229 FrameIO.changeParentAndSubFolders(expeditee_home);
230
231 FolderSettings.FrameDirs.get().clear();
232 FolderSettings.ImageDirs.get().clear();
233 FolderSettings.AudioDirs.get().clear();
234 appendDefaultFolders();
235
236 }
237
238 private static String getExpediteeHome() {
239 String home_property = System.getProperty("expeditee.home");
240 String expeditee_home = (home_property != null) ? home_property + File.separator : getSaveLocation();
241 return expeditee_home;
242 }
243
244 public static void appendDefaultFolders() {
245 if (PublicAndPrivateResources) {
246 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.HELP_USERNAME_PRIVATE_PATH);
247 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.HELP_PATH);
248 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.MESSAGES_PATH);
249 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.FRAME_USERNAME_PRIVATE_PATH);
250 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.FRAME_PATH);
251
252 if (AuthenticatorBrowser.isAuthenticated()) {
253 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.CONTACTS_PATH);
254 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.MAIL_PATH);
255 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.SHARED_FRAMESETS_PATH);
256 }
257
258 FolderSettings.ImageDirs.addAbsoluteDir("${CURRENT_FRAMESET}");
259 FolderSettings.ImageDirs.addAbsoluteDir(FrameIO.IMAGES_USERNAME_PRIVATE_PATH);
260 FolderSettings.ImageDirs.addAbsoluteDir(FrameIO.IMAGES_PATH);
261
262 FolderSettings.AudioDirs.addAbsoluteDir("${CURRENT_FRAMESET}");
263 FolderSettings.AudioDirs.addAbsoluteDir(FrameIO.AUDIO_PATH);
264 FolderSettings.AudioDirs.addAbsoluteDir(FrameIO.AUDIO_USERNAME_PRIVATE_PATH);
265
266 FolderSettings.FrameDirs.setDefault(FolderSettings.FrameDirs.get());
267 FolderSettings.ImageDirs.setDefault(FolderSettings.ImageDirs.get());
268 FolderSettings.AudioDirs.setDefault(FolderSettings.AudioDirs.get());
269 } else {
270 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.HELP_PATH);
271 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.FRAME_PATH);
272 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.MESSAGES_PATH);
273 if (AuthenticatorBrowser.isAuthenticated()) {
274 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.SHARED_FRAMESETS_PATH);
275 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.MAIL_PATH);
276 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.CONTACTS_PATH);
277 }
278
279 FolderSettings.ImageDirs.addAbsoluteDir(FrameIO.IMAGES_PATH);
280
281 FolderSettings.AudioDirs.addAbsoluteDir(FrameIO.AUDIO_PATH);
282 }
283
284 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.PUBLIC_PATH);
285 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.GROUP_PATH);
286 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.PROFILE_PATH);
287 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.TRASH_PATH);
288
289 FolderSettings.FrameDirs.setDefault(FolderSettings.FrameDirs.get());
290 FolderSettings.ImageDirs.setDefault(FolderSettings.ImageDirs.get());
291 FolderSettings.AudioDirs.setDefault(FolderSettings.AudioDirs.get());
292 }
293
294 /**
295 * Find the appropriate directory to store application settings in for
296 * the current OS.
297 * This has only been tested on Linux so far, so if it doesn't work it
298 * may need to be modified or reverted. Should return:
299 * Linux: ~/.expeditee
300 * Windows: %appdata%\.expeditee
301 * Mac: ~/Library/Application\ Support/.expeditee
302 * @return the path to store expeditee's settings
303 */
304 public static String getSaveLocation() {
305 String OS=System.getProperty("os.name").toLowerCase();
306 if(OS.indexOf("win")>=0) { //windoze
307 return System.getenv("APPDATA")+File.separator+".expeditee"+File.separator;
308 } else if(OS.indexOf("mac")>=0) { //mac
309 return System.getProperty("user.home")+File.separator+"Library"+File.separator+"Application Support"+File.separator+".expeditee"+File.separator;
310 } else { //linux or other
311 return System.getProperty("user.home")+File.separator+".expeditee"+File.separator;
312 }
313 }
314}
Note: See TracBrowser for help on using the repository browser.