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

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

Moved the HomeFrame settings to be prior to the ProfileName and UserName setting because the HomeFrame setting CAN be dependent on having a profile name already set.

Added code to deal with legacy framesets that will still have HomeFrame setting appearing before ProfileName and UserName.

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