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

Last change on this file since 1467 was 1467, checked in by bnemhaus, 4 years ago

UserSettings.ProfileName is now null if not set. This also effects UserSettings.HomeFrame as you can only point to profile frame 1 if it is set.

File size: 12.7 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_FLAG)) {
72 if (profileName != null) {
73 text.setLink(profileName + "1");
74 }
75 //text.setLink(FrameIO.LoadProfile(UserSettings.ProfileName.get()).getName());
76 }
77 String first = FrameUtils.getLink(text, UserSettings.HomeFrame.get());
78 // do not use non-existent frames as the first frame
79 if (FrameIO.isValidFrameName(first)) {
80 _value = first;
81 }
82 // warn the user
83 else {
84 // MessageBay.warningMessage("Home frame: " + first
85 // + " is not a valid frame.");
86 _value = profileName + "1";//FrameIO.LoadProfile(UserSettings.ProfileName.get()).getName();
87 }
88 return true;
89 }
90 };
91 public static final IntegerSetting InitialWidth = new IntegerSetting("Initial width of Expeditee window", "InitialWidth", 1024);
92
93 public static final IntegerSetting InitialHeight = new IntegerSetting("Initial height of Expeditee window", "InitialHeight", 768);
94
95 /*
96 * General settings (no setter functions)
97 */
98
99 public static final FloatSetting ScaleFactor = new FloatSetting("Scale Factor for drawing (TODO: does this even do anything?)", "ScaleFactor", 1F);
100
101 public static final FloatSetting FormatSpacingMin = new FloatSetting("Minimum spacing ratio", "FormatSpacingMin", null);
102
103 public static final FloatSetting FormatSpacingMax = new FloatSetting("Maximum spacing ratio", "FormatSpacingMax", null);
104
105 public static final IntegerSetting LineStraightenThreshold = new IntegerSetting("Threshold for straightening a line (TODO: does this even do anything?)", "LineStraightenThreshold", 15);
106
107 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);
108
109 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);
110
111 public static final StringSetting UserName = new StringSetting("User name", ProfileManager.USER_NAME_FLAG);
112
113// public static final StringSetting ProfileName = new StringSetting("Profile name", ProfileManager.USER_NAME_FLAG); // FrameIO.ConvertToValidFramesetName(System.getProperty("user.name"))
114 public static final StringSetting ProfileName = new StringSetting("Profile name", null); // FrameIO.ConvertToValidFramesetName(System.getProperty("user.name"))
115
116 public static final BooleanSetting AntiAlias = new BooleanSetting("Whether anti-aliasing should be enabled", "AntiAlias", false);
117
118 public static final BooleanSetting LineHighlight = new BooleanSetting("Whether lines should be highlighted", "LineHighlight", false);
119
120 public static final BooleanSetting Logging = new BooleanSetting("Whether logging should be enabled", "Logging", false);
121
122 public static final BooleanSetting LogStats = new BooleanSetting("Whether stats should be logged", "LogStats", true);
123
124 public static final BooleanSetting Threading = new BooleanSetting("Whether threading should be enabled", "Threading", true);
125
126 /*
127 * Frames
128 */
129 public static final StringSetting StatisticsFrameset = new StringSetting("The statistics frameset", null);
130
131 public static final StringSetting MenuFrame = new StringSetting("The menu frame", null);
132
133 /*
134 * Other
135 */
136 public static final ListSetting<Text> Style = new ListSetting<Text>("Set the style (TODO: what does this do?)", "Style") {
137 @Override
138 public boolean setSetting(Text text) {
139 Frame child = text.getChild();
140 if (child == null) {
141 _value = new LinkedList<Text>();
142 return true;
143 }
144
145
146 List<Text> style = new ArrayList<Text>(8);
147 for (int i = 0; i < 10; i++) {
148 style.add(null);
149 }
150
151 for (Text t : child.getBodyTextItems(false)) {
152 String type = t.getText();
153 char lastChar = type.charAt(type.length() - 1);
154 if (Character.isDigit(lastChar)) {
155 style.set(lastChar - '0', t);
156 } else {
157 style.set(0, t);
158 }
159 }
160 _value = style;
161 return true;
162 }
163 };
164
165 public static final FunctionSetting SpellChecker = new FunctionSetting("Enables the dictionary with the default dictionary", "SpellChecker") {
166 @Override
167 public void run() {
168 try {
169 JSpellChecker.create();
170 } catch (FileNotFoundException e) {
171 MessageBay.errorMessage("Could not find dictionary: " + e.getMessage());
172 } catch (IOException e) {
173 e.printStackTrace();
174 }
175 }
176 };
177 public static final FrameSetting Spelling = new FrameSetting("Enables the dictionary and adds the items in the child frame to the dictionary", "Spelling") {
178 @Override
179 public void run(Frame frame) {
180 try {
181 JSpellChecker.create(frame);
182 } catch (Exception e) {
183 e.printStackTrace();
184 }
185 }
186 };
187
188 public static final FrameSetting GreenstoneSettings = new FrameSetting("Greenstone settings (TODO: What are these for?)", "GreenstoneSettings") {
189 @Override
190 public void run(Frame frame) {
191 SearchGreenstone.init(frame);
192 }
193 };
194
195 public static final FrameSetting Reminders = new FrameSetting("Reminders (TODO: What are these for?)", "Reminders") {
196 @Override
197 public void run(Frame frame) {
198 org.expeditee.gui.Reminders.init(frame);
199 }
200 };
201
202 public static final FrameSetting MailSettings = new FrameSetting("Mail Settings (TODO: How does this work?)", "MailSettings") {
203 @Override
204 public void run(Frame frame) {
205 MailSession.init(frame);
206 }
207 };
208
209 // add default values
210 static {
211 // Are we in the new regime or the old regime?
212 File resFile = Paths.get(getExpediteeHome()).resolve(".res").toFile();
213 File resourcesPrivateFile = Paths.get(getExpediteeHome() + "resources-private" + File.separator).toFile();
214 if (resourcesPrivateFile.exists()) {
215 // If resources-private exists then this is a good sign we have new regime available.
216 PublicAndPrivateResources = Boolean.TRUE;
217 } else if (resFile.exists()) {
218 // If we do not, but do have the .res file then this is a good sign we are in old regime.
219 PublicAndPrivateResources = Boolean.FALSE;
220 } else {
221 // If we have neither then we are unpacking and therefore will have new regime available once unpacked.
222 PublicAndPrivateResources = Boolean.TRUE;
223 }
224
225 setupDefaultFolders();
226 }
227
228 public static void setupDefaultFolders() {
229 String expeditee_home = getExpediteeHome();
230
231 FrameIO.changeParentAndSubFolders(expeditee_home);
232
233 FolderSettings.FrameDirs.get().clear();
234 FolderSettings.ImageDirs.get().clear();
235 FolderSettings.AudioDirs.get().clear();
236 appendDefaultFolders();
237
238 }
239
240 private static String getExpediteeHome() {
241 String home_property = System.getProperty("expeditee.home");
242 String expeditee_home = (home_property != null) ? home_property + File.separator : getSaveLocation();
243 return expeditee_home;
244 }
245
246 public static void appendDefaultFolders() {
247 if (PublicAndPrivateResources) {
248 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.HELP_USERNAME_PRIVATE_PATH);
249 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.HELP_PATH);
250 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.MESSAGES_PATH);
251 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.FRAME_USERNAME_PRIVATE_PATH);
252 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.FRAME_PATH);
253
254 if (AuthenticatorBrowser.isAuthenticated()) {
255 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.CONTACTS_PATH);
256 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.MAIL_PATH);
257 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.SHARED_FRAMESETS_PATH);
258 }
259
260 FolderSettings.ImageDirs.addAbsoluteDir("${CURRENT_FRAMESET}");
261 FolderSettings.ImageDirs.addAbsoluteDir(FrameIO.IMAGES_USERNAME_PRIVATE_PATH);
262 FolderSettings.ImageDirs.addAbsoluteDir(FrameIO.IMAGES_PATH);
263
264 FolderSettings.AudioDirs.addAbsoluteDir("${CURRENT_FRAMESET}");
265 FolderSettings.AudioDirs.addAbsoluteDir(FrameIO.AUDIO_PATH);
266 FolderSettings.AudioDirs.addAbsoluteDir(FrameIO.AUDIO_USERNAME_PRIVATE_PATH);
267
268 FolderSettings.FrameDirs.setDefault(FolderSettings.FrameDirs.get());
269 FolderSettings.ImageDirs.setDefault(FolderSettings.ImageDirs.get());
270 FolderSettings.AudioDirs.setDefault(FolderSettings.AudioDirs.get());
271 } else {
272 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.HELP_PATH);
273 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.FRAME_PATH);
274 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.MESSAGES_PATH);
275 if (AuthenticatorBrowser.isAuthenticated()) {
276 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.SHARED_FRAMESETS_PATH);
277 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.MAIL_PATH);
278 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.CONTACTS_PATH);
279 }
280
281 FolderSettings.ImageDirs.addAbsoluteDir(FrameIO.IMAGES_PATH);
282
283 FolderSettings.AudioDirs.addAbsoluteDir(FrameIO.AUDIO_PATH);
284 }
285
286 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.PUBLIC_PATH);
287 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.GROUP_PATH);
288 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.PROFILE_PATH);
289 FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.TRASH_PATH);
290
291 FolderSettings.FrameDirs.setDefault(FolderSettings.FrameDirs.get());
292 FolderSettings.ImageDirs.setDefault(FolderSettings.ImageDirs.get());
293 FolderSettings.AudioDirs.setDefault(FolderSettings.AudioDirs.get());
294 }
295
296 /**
297 * Find the appropriate directory to store application settings in for
298 * the current OS.
299 * This has only been tested on Linux so far, so if it doesn't work it
300 * may need to be modified or reverted. Should return:
301 * Linux: ~/.expeditee
302 * Windows: %appdata%\.expeditee
303 * Mac: ~/Library/Application\ Support/.expeditee
304 * @return the path to store expeditee's settings
305 */
306 public static String getSaveLocation() {
307 String OS=System.getProperty("os.name").toLowerCase();
308 if(OS.indexOf("win")>=0) { //windoze
309 return System.getenv("APPDATA")+File.separator+".expeditee"+File.separator;
310 } else if(OS.indexOf("mac")>=0) { //mac
311 return System.getProperty("user.home")+File.separator+"Library"+File.separator+"Application Support"+File.separator+".expeditee"+File.separator;
312 } else { //linux or other
313 return System.getProperty("user.home")+File.separator+".expeditee"+File.separator;
314 }
315 }
316}
Note: See TracBrowser for help on using the repository browser.