[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;
|
---|
| 24 | import java.util.ArrayList;
|
---|
[4] | 25 | import java.util.LinkedList;
|
---|
| 26 | import java.util.List;
|
---|
| 27 |
|
---|
[572] | 28 | import org.expeditee.agents.SearchGreenstone;
|
---|
| 29 | import org.expeditee.agents.mail.MailSession;
|
---|
| 30 | import org.expeditee.agents.wordprocessing.JSpellChecker;
|
---|
[571] | 31 | import org.expeditee.gui.Frame;
|
---|
[570] | 32 | import org.expeditee.gui.FrameIO;
|
---|
[571] | 33 | import org.expeditee.gui.FrameUtils;
|
---|
[572] | 34 | import org.expeditee.gui.MessageBay;
|
---|
[4] | 35 | import org.expeditee.items.Text;
|
---|
[666] | 36 | import org.expeditee.setting.BooleanSetting;
|
---|
| 37 | import org.expeditee.setting.FloatSetting;
|
---|
[655] | 38 | import org.expeditee.setting.FrameSetting;
|
---|
| 39 | import org.expeditee.setting.FunctionSetting;
|
---|
[666] | 40 | import org.expeditee.setting.IntegerSetting;
|
---|
[655] | 41 | import org.expeditee.setting.ListSetting;
|
---|
[666] | 42 | import org.expeditee.setting.StringSetting;
|
---|
[778] | 43 | import org.expeditee.settings.folders.FolderSettings;
|
---|
[4] | 44 |
|
---|
| 45 | /**
|
---|
| 46 | * Central class to contain all values that can be set by the user on their
|
---|
| 47 | * profile frame. These values should be updated only by
|
---|
| 48 | * FrameUtils.ParseProfile.
|
---|
| 49 | */
|
---|
| 50 | public abstract class UserSettings {
|
---|
[348] | 51 |
|
---|
| 52 | public final static String DEFAULT_PROFILE_NAME = "default";
|
---|
[289] | 53 |
|
---|
[717] | 54 | public static final IntegerSetting Gravity = new IntegerSetting("Distance the cursor has to be from a text item to select the text item", 3);
|
---|
| 55 |
|
---|
[732] | 56 | public static final StringSetting StartFrame = new StringSetting("The frame to go to when Expeditee is started (defaults to the profile frame)", null);
|
---|
| 57 |
|
---|
[572] | 58 | /*
|
---|
[717] | 59 | * Stuff that goes first
|
---|
| 60 | */
|
---|
| 61 | public static final StringSetting HomeFrame = new StringSetting("The home frame", null) {
|
---|
| 62 | @Override
|
---|
| 63 | public boolean setSetting(Text text) {
|
---|
| 64 | if(text.getText().indexOf(':') == -1 || !text.hasLink()) {
|
---|
| 65 | text.setLink(FrameIO.LoadProfile(UserSettings.ProfileName.get()).getName());
|
---|
| 66 | }
|
---|
| 67 | String first = FrameUtils.getLink(text, UserSettings.HomeFrame.get());
|
---|
| 68 | // do not use non-existant frames as the first frame
|
---|
| 69 | if (FrameIO.isValidFrameName(first)) {
|
---|
| 70 | _value = first;
|
---|
| 71 | }
|
---|
| 72 | // warn the user
|
---|
| 73 | else {
|
---|
| 74 | // MessageBay.warningMessage("Home frame: " + first
|
---|
| 75 | // + " is not a valid frame.");
|
---|
| 76 | _value = FrameIO.LoadProfile(UserSettings.ProfileName.get()).getName();
|
---|
| 77 | }
|
---|
| 78 | return true;
|
---|
| 79 | }
|
---|
| 80 | };
|
---|
| 81 | public static final IntegerSetting InitialWidth = new IntegerSetting("Initial width of Expeditee window", 1024);
|
---|
| 82 |
|
---|
| 83 | public static final IntegerSetting InitialHeight = new IntegerSetting("Initial height of Expeditee window", 768);
|
---|
| 84 |
|
---|
| 85 | /*
|
---|
[572] | 86 | * General settings (no setter functions)
|
---|
| 87 | */
|
---|
[289] | 88 |
|
---|
[666] | 89 | public static final FloatSetting ScaleFactor = new FloatSetting("Scale Factor for drawing (TODO: does this even do anything?)", 1F);
|
---|
[655] | 90 |
|
---|
[666] | 91 | public static final FloatSetting FormatSpacingMin = new FloatSetting("Minimum spacing ratio", null);
|
---|
[655] | 92 |
|
---|
[666] | 93 | public static final FloatSetting FormatSpacingMax = new FloatSetting("Maximum spacing ratio", null);
|
---|
[4] | 94 |
|
---|
[666] | 95 | public static final IntegerSetting LineStraightenThreshold = new IntegerSetting("Threshold for straightening a line (TODO: does this even do anything?)", 15);
|
---|
[4] | 96 |
|
---|
[666] | 97 | public static final IntegerSetting NoOpThreshold = new IntegerSetting("Distance the cursor may be dragged while clicking before the operation is cancelled", 60);
|
---|
[74] | 98 |
|
---|
[666] | 99 | public static final IntegerSetting TitlePosition = new IntegerSetting("Position of title item in frame (TODO: find whether this is x-offset or y-offset)", 150);
|
---|
[4] | 100 |
|
---|
[666] | 101 | public static final StringSetting ProfileName = new StringSetting("Profile name", FrameIO.ConvertToValidFramesetName(System.getProperty("user.name")));
|
---|
[348] | 102 |
|
---|
[666] | 103 | public static final StringSetting UserName = new StringSetting("User name", ProfileName.get());
|
---|
[655] | 104 |
|
---|
[666] | 105 | public static final BooleanSetting AntiAlias = new BooleanSetting("Whether anti-aliasing should be enabled", false);
|
---|
[572] | 106 |
|
---|
[666] | 107 | public static final BooleanSetting LineHighlight = new BooleanSetting("Whether lines should be highlighted", false);
|
---|
[572] | 108 |
|
---|
[666] | 109 | public static final BooleanSetting Logging = new BooleanSetting("Whether logging should be enabled", false);
|
---|
[572] | 110 |
|
---|
[666] | 111 | public static final BooleanSetting LogStats = new BooleanSetting("Whether stats should be logged", true);
|
---|
[572] | 112 |
|
---|
[666] | 113 | public static final BooleanSetting Threading = new BooleanSetting("Whether threading should be enabled", true);
|
---|
[572] | 114 |
|
---|
| 115 |
|
---|
| 116 | /*
|
---|
| 117 | * Frames
|
---|
| 118 | */
|
---|
[427] | 119 |
|
---|
[666] | 120 | public static final StringSetting StatisticsFrameset = new StringSetting("The statistics frameset", null);
|
---|
[4] | 121 |
|
---|
[666] | 122 | public static final StringSetting MenuFrame = new StringSetting("The menu frame", null);
|
---|
[572] | 123 |
|
---|
| 124 | /*
|
---|
| 125 | * Other
|
---|
| 126 | */
|
---|
[655] | 127 | public static final ListSetting<Text> Style = new ListSetting<Text>("Set the style (TODO: what does this do?)") {
|
---|
| 128 | @Override
|
---|
| 129 | public boolean setSetting(Text text) {
|
---|
| 130 | Frame child = text.getChild();
|
---|
| 131 | if (child == null) {
|
---|
| 132 | _value = new LinkedList<Text>();
|
---|
| 133 | return true;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 |
|
---|
| 137 | List<Text> style = new ArrayList<Text>(8);
|
---|
| 138 | for (int i = 0; i < 10; i++) {
|
---|
| 139 | style.add(null);
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | for (Text t : child.getBodyTextItems(false)) {
|
---|
| 143 | String type = t.getText();
|
---|
| 144 | char lastChar = type.charAt(type.length() - 1);
|
---|
| 145 | if (Character.isDigit(lastChar)) {
|
---|
| 146 | style.set(lastChar - '0', t);
|
---|
| 147 | } else {
|
---|
| 148 | style.set(0, t);
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 | _value = style;
|
---|
| 152 | return true;
|
---|
[639] | 153 | }
|
---|
[655] | 154 | };
|
---|
[572] | 155 |
|
---|
[655] | 156 | public static final FunctionSetting SpellChecker = new FunctionSetting("Enables the dictionary with the default dictionary") {
|
---|
| 157 | @Override
|
---|
| 158 | public void run() {
|
---|
| 159 | try {
|
---|
[641] | 160 | JSpellChecker.create();
|
---|
| 161 | } catch (FileNotFoundException e) {
|
---|
[655] | 162 | MessageBay.errorMessage("Could not find dictionary: " + e.getMessage());
|
---|
[641] | 163 | } catch (IOException e) {
|
---|
| 164 | e.printStackTrace();
|
---|
| 165 | }
|
---|
[572] | 166 | }
|
---|
[655] | 167 | };
|
---|
| 168 | public static final FrameSetting Spelling = new FrameSetting("Enables the dictionary and adds the items in the child frame to the dictionary") {
|
---|
| 169 | @Override
|
---|
| 170 | public void run(Frame frame) {
|
---|
| 171 | try {
|
---|
| 172 | JSpellChecker.create(frame);
|
---|
| 173 | } catch (Exception e) {
|
---|
| 174 | e.printStackTrace();
|
---|
| 175 | }
|
---|
[641] | 176 | }
|
---|
[655] | 177 | };
|
---|
[572] | 178 |
|
---|
[655] | 179 | public static final FrameSetting GreenstoneSettings = new FrameSetting("Greenstone settings (TODO: What are these for?)") {
|
---|
| 180 | @Override
|
---|
| 181 | public void run(Frame frame) {
|
---|
| 182 | SearchGreenstone.init(frame);
|
---|
| 183 | }
|
---|
| 184 | };
|
---|
[572] | 185 |
|
---|
[655] | 186 | public static final FrameSetting Reminders = new FrameSetting("Reminders (TODO: What are these for?)") {
|
---|
| 187 | @Override
|
---|
| 188 | public void run(Frame frame) {
|
---|
| 189 | org.expeditee.gui.Reminders.init(frame);
|
---|
[642] | 190 | }
|
---|
[655] | 191 | };
|
---|
[572] | 192 |
|
---|
[655] | 193 | public static final FrameSetting MailSettings = new FrameSetting("Mail Settings (TODO: How does this work?)") {
|
---|
| 194 | @Override
|
---|
| 195 | public void run(Frame frame) {
|
---|
| 196 | MailSession.init(frame);
|
---|
[642] | 197 | }
|
---|
[655] | 198 | };
|
---|
[761] | 199 |
|
---|
[4] | 200 | // add default values
|
---|
[355] | 201 | static {
|
---|
[946] | 202 | setupDefaultFolders();
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 | public static void setupDefaultFolders() {
|
---|
[490] | 206 | String expeditee_home = System.getProperty("expeditee.home");
|
---|
| 207 | if (expeditee_home != null) {
|
---|
[761] | 208 | FrameIO.changeParentFolder(expeditee_home + File.separator);
|
---|
| 209 | } else {
|
---|
| 210 | FrameIO.changeParentFolder(getSaveLocation());
|
---|
| 211 | }
|
---|
[504] | 212 |
|
---|
[946] | 213 | FolderSettings.FrameDirs.get().clear();
|
---|
| 214 | FolderSettings.ImageDirs.get().clear();
|
---|
| 215 | appendDefaultFolders();
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | public static void appendDefaultFolders() {
|
---|
[778] | 219 | FolderSettings.FrameDirs.get().add(FrameIO.FRAME_PATH);
|
---|
| 220 | FolderSettings.FrameDirs.get().add(FrameIO.PUBLIC_PATH);
|
---|
| 221 | FolderSettings.FrameDirs.get().add(FrameIO.PROFILE_PATH);
|
---|
| 222 | FolderSettings.FrameDirs.get().add(FrameIO.HELP_PATH);
|
---|
| 223 | FolderSettings.FrameDirs.get().add(FrameIO.MESSAGES_PATH);
|
---|
| 224 | FolderSettings.FrameDirs.setDefault(FolderSettings.FrameDirs.get());
|
---|
| 225 | FolderSettings.ImageDirs.get().add(FrameIO.IMAGES_PATH);
|
---|
| 226 | FolderSettings.ImageDirs.setDefault(FolderSettings.ImageDirs.get());
|
---|
[4] | 227 | }
|
---|
| 228 |
|
---|
| 229 | /**
|
---|
[504] | 230 | * Find the appropriate directory to store application settings in for
|
---|
| 231 | * the current OS.
|
---|
| 232 | * This has only been tested on Linux so far, so if it doesn't work it
|
---|
| 233 | * may need to be modified or reverted. Should return:
|
---|
| 234 | * Linux: ~/.expeditee
|
---|
| 235 | * Windows: %appdata%\.expeditee
|
---|
| 236 | * Mac: ~/Library/Application\ Support/.expeditee
|
---|
| 237 | * @return the path to store expeditee's settings
|
---|
[4] | 238 | */
|
---|
[504] | 239 | public static String getSaveLocation() {
|
---|
| 240 | String OS=System.getProperty("os.name").toLowerCase();
|
---|
[768] | 241 | if(OS.indexOf("win")>=0) { //windoze
|
---|
[504] | 242 | return System.getenv("APPDATA")+File.separator+".expeditee"+File.separator;
|
---|
[768] | 243 | } else if(OS.indexOf("mac")>=0) { //mac
|
---|
[504] | 244 | return System.getProperty("user.home")+File.separator+"Library"+File.separator+"Application Support"+File.separator+".expeditee"+File.separator;
|
---|
| 245 | } else { //linux or other
|
---|
| 246 | return System.getProperty("user.home")+File.separator+".expeditee"+File.separator;
|
---|
[4] | 247 | }
|
---|
| 248 | }
|
---|
| 249 | }
|
---|