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

Last change on this file since 1242 was 1242, checked in by bln4, 5 years ago

Support for new regime in the form of new fields and conditional setting of all paths fields.

Settings are now able to generate their own representation. This allows for the user to explicitly inspect the default values.

When profiles are created, an optional parameter may now be provided. If not null, the new map parameter can contain default values for settings to apply to this profile. This allows for the creation of profiles to that have (for example), their username set to an explicit value. Multiuser mode uses this functionality for usernames and key values among other things.

Frames can now be asked were they are located on the file system. Furthermore, frame indirection is now a thing. Rather than containing data to display, an exp file can contain a line in the format of "REDIRECT:<path>" to go looking for that data. Frames are able to return both their logical (their exp file) and real (the file actually containing the data) paths.

Frames can now store data.

Further fixes to how edits from other users are loaded in.

File size: 11.9 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.gui.Frame;
33import org.expeditee.gui.FrameIO;
34import org.expeditee.gui.FrameUtils;
35import org.expeditee.gui.MessageBay;
36import org.expeditee.items.Text;
37import org.expeditee.setting.BooleanSetting;
38import org.expeditee.setting.FloatSetting;
39import org.expeditee.setting.FrameSetting;
40import org.expeditee.setting.FunctionSetting;
41import org.expeditee.setting.IntegerSetting;
42import org.expeditee.setting.ListSetting;
43import org.expeditee.setting.StringSetting;
44import org.expeditee.settings.folders.FolderSettings;
45
46/**
47 * Central class to contain all values that can be set by the user on their
48 * profile frame. These values should be updated only by
49 * FrameUtils.ParseProfile.
50 */
51public abstract class UserSettings {
52
53 public static String DEFAULT_PROFILE_NAME = "default";
54
55 public static Boolean multiUserMode;
56
57 public static final IntegerSetting Gravity = new IntegerSetting("Distance the cursor has to be from a text item to select the text item", "Gravity", 3);
58
59 public static final StringSetting StartFrame = new StringSetting("The frame to go to when Expeditee is started (defaults to the profile frame)", null);
60
61 /*
62 * Stuff that goes first
63 */
64 public static final StringSetting HomeFrame = new StringSetting("The home frame", null) {
65 @Override
66 public boolean setSetting(Text text) {
67 if(text.getText().indexOf(':') == -1 || !text.hasLink()) {
68 text.setLink(UserSettings.ProfileName.get() + "1");
69 //text.setLink(FrameIO.LoadProfile(UserSettings.ProfileName.get()).getName());
70 }
71 String first = FrameUtils.getLink(text, UserSettings.HomeFrame.get());
72 // do not use non-existant frames as the first frame
73 if (FrameIO.isValidFrameName(first)) {
74 _value = first;
75 }
76 // warn the user
77 else {
78 // MessageBay.warningMessage("Home frame: " + first
79 // + " is not a valid frame.");
80 _value = FrameIO.LoadProfile(UserSettings.ProfileName.get()).getName();
81 }
82 return true;
83 }
84 };
85 public static final IntegerSetting InitialWidth = new IntegerSetting("Initial width of Expeditee window", "InitialWidth", 1024);
86
87 public static final IntegerSetting InitialHeight = new IntegerSetting("Initial height of Expeditee window", "InitialHeight", 768);
88
89 /*
90 * General settings (no setter functions)
91 */
92
93 public static final FloatSetting ScaleFactor = new FloatSetting("Scale Factor for drawing (TODO: does this even do anything?)", "ScaleFactor", 1F);
94
95 public static final FloatSetting FormatSpacingMin = new FloatSetting("Minimum spacing ratio", "FormatSpacingMin", null);
96
97 public static final FloatSetting FormatSpacingMax = new FloatSetting("Maximum spacing ratio", "FormatSpacingMax", null);
98
99 public static final IntegerSetting LineStraightenThreshold = new IntegerSetting("Threshold for straightening a line (TODO: does this even do anything?)", "LineStraightenThreshold", 15);
100
101 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);
102
103 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);
104
105 public static final StringSetting ProfileName = new StringSetting("Profile name", FrameIO.ConvertToValidFramesetName(System.getProperty("user.name")));
106
107 public static final StringSetting UserName = new StringSetting("User name", ProfileName.get());
108
109 public static final BooleanSetting AntiAlias = new BooleanSetting("Whether anti-aliasing should be enabled", "AntiAlias", false);
110
111 public static final BooleanSetting LineHighlight = new BooleanSetting("Whether lines should be highlighted", "LineHighlight", false);
112
113 public static final BooleanSetting Logging = new BooleanSetting("Whether logging should be enabled", "Logging", false);
114
115 public static final BooleanSetting LogStats = new BooleanSetting("Whether stats should be logged", "LogStats", true);
116
117 public static final BooleanSetting Threading = new BooleanSetting("Whether threading should be enabled", "Threading", true);
118
119 /*
120 * Frames
121 */
122 public static final StringSetting StatisticsFrameset = new StringSetting("The statistics frameset", null);
123
124 public static final StringSetting MenuFrame = new StringSetting("The menu frame", null);
125
126 /*
127 * Other
128 */
129 public static final ListSetting<Text> Style = new ListSetting<Text>("Set the style (TODO: what does this do?)", "Style") {
130 @Override
131 public boolean setSetting(Text text) {
132 Frame child = text.getChild();
133 if (child == null) {
134 _value = new LinkedList<Text>();
135 return true;
136 }
137
138
139 List<Text> style = new ArrayList<Text>(8);
140 for (int i = 0; i < 10; i++) {
141 style.add(null);
142 }
143
144 for (Text t : child.getBodyTextItems(false)) {
145 String type = t.getText();
146 char lastChar = type.charAt(type.length() - 1);
147 if (Character.isDigit(lastChar)) {
148 style.set(lastChar - '0', t);
149 } else {
150 style.set(0, t);
151 }
152 }
153 _value = style;
154 return true;
155 }
156 };
157
158 public static final FunctionSetting SpellChecker = new FunctionSetting("Enables the dictionary with the default dictionary", "SpellChecker") {
159 @Override
160 public void run() {
161 try {
162 JSpellChecker.create();
163 } catch (FileNotFoundException e) {
164 MessageBay.errorMessage("Could not find dictionary: " + e.getMessage());
165 } catch (IOException e) {
166 e.printStackTrace();
167 }
168 }
169 };
170 public static final FrameSetting Spelling = new FrameSetting("Enables the dictionary and adds the items in the child frame to the dictionary", "Spelling") {
171 @Override
172 public void run(Frame frame) {
173 try {
174 JSpellChecker.create(frame);
175 } catch (Exception e) {
176 e.printStackTrace();
177 }
178 }
179 };
180
181 public static final FrameSetting GreenstoneSettings = new FrameSetting("Greenstone settings (TODO: What are these for?)", "GreenstoneSettings") {
182 @Override
183 public void run(Frame frame) {
184 SearchGreenstone.init(frame);
185 }
186 };
187
188 public static final FrameSetting Reminders = new FrameSetting("Reminders (TODO: What are these for?)", "Reminders") {
189 @Override
190 public void run(Frame frame) {
191 org.expeditee.gui.Reminders.init(frame);
192 }
193 };
194
195 public static final FrameSetting MailSettings = new FrameSetting("Mail Settings (TODO: How does this work?)", "MailSettings") {
196 @Override
197 public void run(Frame frame) {
198 MailSession.init(frame);
199 }
200 };
201
202 // add default values
203 static {
204 // Are we in the new regime or the old regime?
205 File resFile = Paths.get(getDesiredExpediteeHome()).resolve(".res").toFile();
206 File resourcesPrivateFile = Paths.get(getDesiredExpediteeHome() + "resources-private" + File.separator).toFile();
207 if (resourcesPrivateFile.exists()) {
208 // If resources-private exists than this is a good sign we have new regime available.
209 multiUserMode = Boolean.TRUE;
210 } else if (resFile.exists()) {
211 // If we do not, but do have the .res file then this is a good sign we are in old regime.
212 multiUserMode = Boolean.FALSE;
213 } else {
214 // If we have neither then we are unpacking and therefore will have new regime available once unpacked.
215 multiUserMode = Boolean.TRUE;
216 }
217
218 setupDefaultFolders();
219 }
220
221 public static void setupDefaultFolders() {
222 FrameIO.changeParentFolder(getDesiredExpediteeHome());
223
224 FolderSettings.FrameDirs.get().clear();
225 FolderSettings.ImageDirs.get().clear();
226 appendDefaultFolders();
227 }
228
229 private static String getDesiredExpediteeHome() {
230 String homeProperty = System.getProperty("expeditee.home");
231 String expeditee_home = homeProperty == null ? getSaveLocation() : homeProperty + File.separator;
232 return expeditee_home;
233 }
234
235 public static void appendDefaultFolders() {
236 if (multiUserMode) {
237 // The comments here explain how things have changed with the new regime.
238 // FrameDirs
239 // 1. PROFILE_PATH Still points to same place.
240 // 2. SHARED_FRAMESETS_PATH Still points to same place. (encryption stops just anyone reading it)
241 // 3. framesets-<username> Generated on user account creation and must be refreshed on user switching. Also gives access to tutorial stuffs.
242 // 4. FRAME_PATH <expeditee-home>\resources-public\framesets.
243 // 5. HELP_PUBLIC_PATH <expeditee-home>\resources-public\documentation.
244 // 6. MESSAGES_PATH Still points to same place. Should these be per user and encrypted?
245 // 7. PUBLIC_PATH Still points to same place. Kept for compatibility.
246 FolderSettings.FrameDirs.get().add(FrameIO.PROFILE_PATH);
247 FolderSettings.FrameDirs.get().add(FrameIO.FRAME_PRIVATE_PATH);
248 FolderSettings.FrameDirs.get().add(FrameIO.SHARED_FRAMESETS_PATH);
249 FolderSettings.FrameDirs.get().add(FrameIO.FRAME_PATH);
250 FolderSettings.FrameDirs.get().add(FrameIO.RESOURCES_PATH);
251 FolderSettings.FrameDirs.get().add(FrameIO.MESSAGES_PATH);
252 FolderSettings.FrameDirs.get().add(FrameIO.PUBLIC_PATH);
253 FolderSettings.FrameDirs.setDefault(FolderSettings.FrameDirs.get());
254
255 // ImageDirs
256 // 1. resources-<username>\images Generated on user account creation and must be refreshed on user switching.
257 // 2. IMAGES_PATH <expeditee-home>\resources-public\images
258 FolderSettings.ImageDirs.get().add(FrameIO.IMAGES_PRIVATE_PATH);
259 FolderSettings.ImageDirs.get().add(FrameIO.IMAGES_PATH);
260 FolderSettings.ImageDirs.setDefault(FolderSettings.ImageDirs.get());
261 } else {
262 FolderSettings.FrameDirs.get().add(FrameIO.FRAME_PATH);
263 FolderSettings.FrameDirs.get().add(FrameIO.PUBLIC_PATH);
264 FolderSettings.FrameDirs.get().add(FrameIO.PROFILE_PATH);
265 FolderSettings.FrameDirs.get().add(FrameIO.HELP_PATH);
266 FolderSettings.FrameDirs.get().add(FrameIO.MESSAGES_PATH);
267 FolderSettings.FrameDirs.setDefault(FolderSettings.FrameDirs.get());
268 FolderSettings.ImageDirs.get().add(FrameIO.IMAGES_PATH);
269 FolderSettings.ImageDirs.setDefault(FolderSettings.ImageDirs.get());
270 }
271 }
272
273 /**
274 * Find the appropriate directory to store application settings in for
275 * the current OS.
276 * This has only been tested on Linux so far, so if it doesn't work it
277 * may need to be modified or reverted. Should return:
278 * Linux: ~/.expeditee
279 * Windows: %appdata%\.expeditee
280 * Mac: ~/Library/Application\ Support/.expeditee
281 * @return the path to store expeditee's settings
282 */
283 public static String getSaveLocation() {
284 String OS=System.getProperty("os.name").toLowerCase();
285 if(OS.indexOf("win")>=0) { //windoze
286 return System.getenv("APPDATA")+File.separator+".expeditee"+File.separator;
287 } else if(OS.indexOf("mac")>=0) { //mac
288 return System.getProperty("user.home")+File.separator+"Library"+File.separator+"Application Support"+File.separator+".expeditee"+File.separator;
289 } else { //linux or other
290 return System.getProperty("user.home")+File.separator+".expeditee"+File.separator;
291 }
292 }
293}
Note: See TracBrowser for help on using the repository browser.