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