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