[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] | 19 | package org.expeditee.settings;
|
---|
[4] | 20 |
|
---|
| 21 | import java.io.File;
|
---|
[572] | 22 | import java.io.FileNotFoundException;
|
---|
| 23 | import java.io.IOException;
|
---|
[1242] | 24 | import java.nio.file.Paths;
|
---|
[572] | 25 | import java.util.ArrayList;
|
---|
[4] | 26 | import java.util.LinkedList;
|
---|
| 27 | import java.util.List;
|
---|
| 28 |
|
---|
[572] | 29 | import org.expeditee.agents.SearchGreenstone;
|
---|
| 30 | import org.expeditee.agents.mail.MailSession;
|
---|
| 31 | import org.expeditee.agents.wordprocessing.JSpellChecker;
|
---|
[1287] | 32 | import org.expeditee.auth.AuthenticatorBrowser;
|
---|
[571] | 33 | import org.expeditee.gui.Frame;
|
---|
[570] | 34 | import org.expeditee.gui.FrameIO;
|
---|
[571] | 35 | import org.expeditee.gui.FrameUtils;
|
---|
[572] | 36 | import org.expeditee.gui.MessageBay;
|
---|
[1434] | 37 | import org.expeditee.gui.management.ProfileManager;
|
---|
[4] | 38 | import org.expeditee.items.Text;
|
---|
[666] | 39 | import org.expeditee.setting.BooleanSetting;
|
---|
| 40 | import org.expeditee.setting.FloatSetting;
|
---|
[655] | 41 | import org.expeditee.setting.FrameSetting;
|
---|
| 42 | import org.expeditee.setting.FunctionSetting;
|
---|
[666] | 43 | import org.expeditee.setting.IntegerSetting;
|
---|
[655] | 44 | import org.expeditee.setting.ListSetting;
|
---|
[666] | 45 | import org.expeditee.setting.StringSetting;
|
---|
[778] | 46 | import org.expeditee.settings.folders.FolderSettings;
|
---|
[4] | 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 | */
|
---|
| 53 | public abstract class UserSettings {
|
---|
[348] | 54 |
|
---|
[1434] | 55 | public static final String DEFAULT_PROFILE_NAME = "default";
|
---|
[1242] | 56 |
|
---|
[1244] | 57 | public static Boolean PublicAndPrivateResources;
|
---|
[289] | 58 |
|
---|
[1242] | 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);
|
---|
[717] | 60 |
|
---|
[732] | 61 | public static final StringSetting StartFrame = new StringSetting("The frame to go to when Expeditee is started (defaults to the profile frame)", null);
|
---|
| 62 |
|
---|
[572] | 63 | /*
|
---|
[717] | 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) {
|
---|
[1434] | 69 | String profileName = UserSettings.ProfileName.get();
|
---|
| 70 | if(text.getText().indexOf(':') == -1 || !text.hasLink()) {
|
---|
[1441] | 71 | if (!profileName.equals(ProfileManager.USER_NAME_FLAG)) {
|
---|
[1434] | 72 | text.setLink(profileName + "1");
|
---|
| 73 | }
|
---|
[1213] | 74 | //text.setLink(FrameIO.LoadProfile(UserSettings.ProfileName.get()).getName());
|
---|
[717] | 75 | }
|
---|
| 76 | String first = FrameUtils.getLink(text, UserSettings.HomeFrame.get());
|
---|
[1244] | 77 | // do not use non-existent frames as the first frame
|
---|
[717] | 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.");
|
---|
[1434] | 85 | _value = profileName + "1";//FrameIO.LoadProfile(UserSettings.ProfileName.get()).getName();
|
---|
[717] | 86 | }
|
---|
| 87 | return true;
|
---|
| 88 | }
|
---|
| 89 | };
|
---|
[1242] | 90 | public static final IntegerSetting InitialWidth = new IntegerSetting("Initial width of Expeditee window", "InitialWidth", 1024);
|
---|
[717] | 91 |
|
---|
[1242] | 92 | public static final IntegerSetting InitialHeight = new IntegerSetting("Initial height of Expeditee window", "InitialHeight", 768);
|
---|
[717] | 93 |
|
---|
| 94 | /*
|
---|
[572] | 95 | * General settings (no setter functions)
|
---|
| 96 | */
|
---|
[289] | 97 |
|
---|
[1242] | 98 | public static final FloatSetting ScaleFactor = new FloatSetting("Scale Factor for drawing (TODO: does this even do anything?)", "ScaleFactor", 1F);
|
---|
[655] | 99 |
|
---|
[1242] | 100 | public static final FloatSetting FormatSpacingMin = new FloatSetting("Minimum spacing ratio", "FormatSpacingMin", null);
|
---|
[655] | 101 |
|
---|
[1242] | 102 | public static final FloatSetting FormatSpacingMax = new FloatSetting("Maximum spacing ratio", "FormatSpacingMax", null);
|
---|
[4] | 103 |
|
---|
[1242] | 104 | public static final IntegerSetting LineStraightenThreshold = new IntegerSetting("Threshold for straightening a line (TODO: does this even do anything?)", "LineStraightenThreshold", 15);
|
---|
[4] | 105 |
|
---|
[1242] | 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);
|
---|
[74] | 107 |
|
---|
[1242] | 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);
|
---|
[1272] | 109 |
|
---|
[1440] | 110 | public static final StringSetting UserName = new StringSetting("User name", "${USER_NAME}"); // FrameIO.ConvertToValidFramesetName(System.getProperty("user.name"))
|
---|
[4] | 111 |
|
---|
[1440] | 112 | public static final StringSetting ProfileName = new StringSetting("Profile name", "${USER_NAME}");
|
---|
[1213] | 113 |
|
---|
[1242] | 114 | public static final BooleanSetting AntiAlias = new BooleanSetting("Whether anti-aliasing should be enabled", "AntiAlias", false);
|
---|
[572] | 115 |
|
---|
[1242] | 116 | public static final BooleanSetting LineHighlight = new BooleanSetting("Whether lines should be highlighted", "LineHighlight", false);
|
---|
[572] | 117 |
|
---|
[1242] | 118 | public static final BooleanSetting Logging = new BooleanSetting("Whether logging should be enabled", "Logging", false);
|
---|
[572] | 119 |
|
---|
[1242] | 120 | public static final BooleanSetting LogStats = new BooleanSetting("Whether stats should be logged", "LogStats", true);
|
---|
[572] | 121 |
|
---|
[1242] | 122 | public static final BooleanSetting Threading = new BooleanSetting("Whether threading should be enabled", "Threading", true);
|
---|
[1213] | 123 |
|
---|
[572] | 124 | /*
|
---|
| 125 | * Frames
|
---|
| 126 | */
|
---|
[666] | 127 | public static final StringSetting StatisticsFrameset = new StringSetting("The statistics frameset", null);
|
---|
[4] | 128 |
|
---|
[666] | 129 | public static final StringSetting MenuFrame = new StringSetting("The menu frame", null);
|
---|
[572] | 130 |
|
---|
| 131 | /*
|
---|
| 132 | * Other
|
---|
| 133 | */
|
---|
[1242] | 134 | public static final ListSetting<Text> Style = new ListSetting<Text>("Set the style (TODO: what does this do?)", "Style") {
|
---|
[655] | 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;
|
---|
[639] | 160 | }
|
---|
[655] | 161 | };
|
---|
[572] | 162 |
|
---|
[1242] | 163 | public static final FunctionSetting SpellChecker = new FunctionSetting("Enables the dictionary with the default dictionary", "SpellChecker") {
|
---|
[655] | 164 | @Override
|
---|
| 165 | public void run() {
|
---|
| 166 | try {
|
---|
[641] | 167 | JSpellChecker.create();
|
---|
| 168 | } catch (FileNotFoundException e) {
|
---|
[655] | 169 | MessageBay.errorMessage("Could not find dictionary: " + e.getMessage());
|
---|
[641] | 170 | } catch (IOException e) {
|
---|
| 171 | e.printStackTrace();
|
---|
| 172 | }
|
---|
[572] | 173 | }
|
---|
[655] | 174 | };
|
---|
[1242] | 175 | public static final FrameSetting Spelling = new FrameSetting("Enables the dictionary and adds the items in the child frame to the dictionary", "Spelling") {
|
---|
[655] | 176 | @Override
|
---|
| 177 | public void run(Frame frame) {
|
---|
| 178 | try {
|
---|
| 179 | JSpellChecker.create(frame);
|
---|
| 180 | } catch (Exception e) {
|
---|
| 181 | e.printStackTrace();
|
---|
| 182 | }
|
---|
[641] | 183 | }
|
---|
[655] | 184 | };
|
---|
[572] | 185 |
|
---|
[1242] | 186 | public static final FrameSetting GreenstoneSettings = new FrameSetting("Greenstone settings (TODO: What are these for?)", "GreenstoneSettings") {
|
---|
[655] | 187 | @Override
|
---|
| 188 | public void run(Frame frame) {
|
---|
| 189 | SearchGreenstone.init(frame);
|
---|
| 190 | }
|
---|
| 191 | };
|
---|
[572] | 192 |
|
---|
[1242] | 193 | public static final FrameSetting Reminders = new FrameSetting("Reminders (TODO: What are these for?)", "Reminders") {
|
---|
[655] | 194 | @Override
|
---|
| 195 | public void run(Frame frame) {
|
---|
| 196 | org.expeditee.gui.Reminders.init(frame);
|
---|
[642] | 197 | }
|
---|
[655] | 198 | };
|
---|
[572] | 199 |
|
---|
[1242] | 200 | public static final FrameSetting MailSettings = new FrameSetting("Mail Settings (TODO: How does this work?)", "MailSettings") {
|
---|
[655] | 201 | @Override
|
---|
| 202 | public void run(Frame frame) {
|
---|
| 203 | MailSession.init(frame);
|
---|
[642] | 204 | }
|
---|
[655] | 205 | };
|
---|
[761] | 206 |
|
---|
[4] | 207 | // add default values
|
---|
[355] | 208 | static {
|
---|
[1242] | 209 | // Are we in the new regime or the old regime?
|
---|
[1244] | 210 | File resFile = Paths.get(getExpediteeHome()).resolve(".res").toFile();
|
---|
| 211 | File resourcesPrivateFile = Paths.get(getExpediteeHome() + "resources-private" + File.separator).toFile();
|
---|
[1242] | 212 | if (resourcesPrivateFile.exists()) {
|
---|
[1244] | 213 | // If resources-private exists then this is a good sign we have new regime available.
|
---|
| 214 | PublicAndPrivateResources = Boolean.TRUE;
|
---|
[1330] | 215 | } else if (resFile.exists()) {
|
---|
[1242] | 216 | // If we do not, but do have the .res file then this is a good sign we are in old regime.
|
---|
[1244] | 217 | PublicAndPrivateResources = Boolean.FALSE;
|
---|
[1330] | 218 | } else {
|
---|
[1242] | 219 | // If we have neither then we are unpacking and therefore will have new regime available once unpacked.
|
---|
[1244] | 220 | PublicAndPrivateResources = Boolean.TRUE;
|
---|
[1242] | 221 | }
|
---|
| 222 |
|
---|
[946] | 223 | setupDefaultFolders();
|
---|
| 224 | }
|
---|
[1242] | 225 |
|
---|
[1244] | 226 | public static void setupDefaultFolders() {
|
---|
| 227 | String expeditee_home = getExpediteeHome();
|
---|
| 228 |
|
---|
| 229 | FrameIO.changeParentAndSubFolders(expeditee_home);
|
---|
| 230 |
|
---|
[946] | 231 | FolderSettings.FrameDirs.get().clear();
|
---|
| 232 | FolderSettings.ImageDirs.get().clear();
|
---|
[1244] | 233 | FolderSettings.AudioDirs.get().clear();
|
---|
[946] | 234 | appendDefaultFolders();
|
---|
[1244] | 235 |
|
---|
[946] | 236 | }
|
---|
| 237 |
|
---|
[1244] | 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();
|
---|
[1242] | 241 | return expeditee_home;
|
---|
| 242 | }
|
---|
[1328] | 243 |
|
---|
[1440] | 244 | public static void appendDefaultFolders() {
|
---|
[1328] | 245 | if (PublicAndPrivateResources) {
|
---|
[1440] | 246 | FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.HELP_USERNAME_PRIVATE_PATH);
|
---|
[1328] | 247 | FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.HELP_PATH);
|
---|
[1440] | 248 | FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.MESSAGES_PATH);
|
---|
| 249 | FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.FRAME_USERNAME_PRIVATE_PATH);
|
---|
[1328] | 250 | FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.FRAME_PATH);
|
---|
[1440] | 251 |
|
---|
[1328] | 252 | if (AuthenticatorBrowser.isAuthenticated()) {
|
---|
[1440] | 253 | FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.CONTACTS_PATH);
|
---|
[1360] | 254 | FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.MAIL_PATH);
|
---|
[1440] | 255 | FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.SHARED_FRAMESETS_PATH);
|
---|
[1328] | 256 | }
|
---|
| 257 |
|
---|
[1440] | 258 | FolderSettings.ImageDirs.addAbsoluteDir("${CURRENT_FRAMESET}");
|
---|
[1434] | 259 | FolderSettings.ImageDirs.addAbsoluteDir(FrameIO.IMAGES_USERNAME_PRIVATE_PATH);
|
---|
[1440] | 260 | FolderSettings.ImageDirs.addAbsoluteDir(FrameIO.IMAGES_PATH);
|
---|
[1244] | 261 |
|
---|
[1440] | 262 | FolderSettings.AudioDirs.addAbsoluteDir("${CURRENT_FRAMESET}");
|
---|
[1328] | 263 | FolderSettings.AudioDirs.addAbsoluteDir(FrameIO.AUDIO_PATH);
|
---|
[1434] | 264 | FolderSettings.AudioDirs.addAbsoluteDir(FrameIO.AUDIO_USERNAME_PRIVATE_PATH);
|
---|
[1440] | 265 |
|
---|
| 266 | FolderSettings.FrameDirs.setDefault(FolderSettings.FrameDirs.get());
|
---|
| 267 | FolderSettings.ImageDirs.setDefault(FolderSettings.ImageDirs.get());
|
---|
[1244] | 268 | FolderSettings.AudioDirs.setDefault(FolderSettings.AudioDirs.get());
|
---|
[1242] | 269 | } else {
|
---|
[1328] | 270 | FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.HELP_PATH);
|
---|
[1244] | 271 | FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.FRAME_PATH);
|
---|
| 272 | FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.MESSAGES_PATH);
|
---|
[1328] | 273 | if (AuthenticatorBrowser.isAuthenticated()) {
|
---|
| 274 | FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.SHARED_FRAMESETS_PATH);
|
---|
[1360] | 275 | FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.MAIL_PATH);
|
---|
[1375] | 276 | FolderSettings.FrameDirs.addAbsoluteDir(FrameIO.CONTACTS_PATH);
|
---|
[1328] | 277 | }
|
---|
| 278 |
|
---|
[1245] | 279 | FolderSettings.ImageDirs.addAbsoluteDir(FrameIO.IMAGES_PATH);
|
---|
[1244] | 280 |
|
---|
[1245] | 281 | FolderSettings.AudioDirs.addAbsoluteDir(FrameIO.AUDIO_PATH);
|
---|
[1242] | 282 | }
|
---|
[1440] | 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());
|
---|
[4] | 292 | }
|
---|
| 293 |
|
---|
| 294 | /**
|
---|
[504] | 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
|
---|
[4] | 303 | */
|
---|
[504] | 304 | public static String getSaveLocation() {
|
---|
| 305 | String OS=System.getProperty("os.name").toLowerCase();
|
---|
[768] | 306 | if(OS.indexOf("win")>=0) { //windoze
|
---|
[504] | 307 | return System.getenv("APPDATA")+File.separator+".expeditee"+File.separator;
|
---|
[768] | 308 | } else if(OS.indexOf("mac")>=0) { //mac
|
---|
[504] | 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;
|
---|
[4] | 312 | }
|
---|
| 313 | }
|
---|
| 314 | }
|
---|