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.util.ArrayList;
|
---|
25 | import java.util.LinkedList;
|
---|
26 | import java.util.List;
|
---|
27 |
|
---|
28 | import org.expeditee.agents.SearchGreenstone;
|
---|
29 | import org.expeditee.agents.mail.MailSession;
|
---|
30 | import org.expeditee.agents.wordprocessing.JSpellChecker;
|
---|
31 | import org.expeditee.gui.Frame;
|
---|
32 | import org.expeditee.gui.FrameIO;
|
---|
33 | import org.expeditee.gui.FrameUtils;
|
---|
34 | import org.expeditee.gui.MessageBay;
|
---|
35 | import org.expeditee.items.Text;
|
---|
36 | import org.expeditee.setting.BooleanSetting;
|
---|
37 | import org.expeditee.setting.FloatSetting;
|
---|
38 | import org.expeditee.setting.FrameSetting;
|
---|
39 | import org.expeditee.setting.FunctionSetting;
|
---|
40 | import org.expeditee.setting.IntegerSetting;
|
---|
41 | import org.expeditee.setting.ListSetting;
|
---|
42 | import org.expeditee.setting.StringSetting;
|
---|
43 | import org.expeditee.settings.folders.FolderSettings;
|
---|
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 {
|
---|
51 |
|
---|
52 | public final static String DEFAULT_PROFILE_NAME = "default";
|
---|
53 |
|
---|
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 |
|
---|
56 | public static final StringSetting StartFrame = new StringSetting("The frame to go to when Expeditee is started (defaults to the profile frame)", null);
|
---|
57 |
|
---|
58 | /*
|
---|
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 | /*
|
---|
86 | * General settings (no setter functions)
|
---|
87 | */
|
---|
88 |
|
---|
89 | public static final FloatSetting ScaleFactor = new FloatSetting("Scale Factor for drawing (TODO: does this even do anything?)", 1F);
|
---|
90 |
|
---|
91 | public static final FloatSetting FormatSpacingMin = new FloatSetting("Minimum spacing ratio", null);
|
---|
92 |
|
---|
93 | public static final FloatSetting FormatSpacingMax = new FloatSetting("Maximum spacing ratio", null);
|
---|
94 |
|
---|
95 | public static final IntegerSetting LineStraightenThreshold = new IntegerSetting("Threshold for straightening a line (TODO: does this even do anything?)", 15);
|
---|
96 |
|
---|
97 | public static final IntegerSetting NoOpThreshold = new IntegerSetting("Distance the cursor may be dragged while clicking before the operation is cancelled", 60);
|
---|
98 |
|
---|
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);
|
---|
100 |
|
---|
101 | public static final StringSetting ProfileName = new StringSetting("Profile name", FrameIO.ConvertToValidFramesetName(System.getProperty("user.name")));
|
---|
102 |
|
---|
103 | public static final StringSetting UserName = new StringSetting("User name", ProfileName.get());
|
---|
104 |
|
---|
105 | public static final BooleanSetting AntiAlias = new BooleanSetting("Whether anti-aliasing should be enabled", false);
|
---|
106 |
|
---|
107 | public static final BooleanSetting LineHighlight = new BooleanSetting("Whether lines should be highlighted", false);
|
---|
108 |
|
---|
109 | public static final BooleanSetting Logging = new BooleanSetting("Whether logging should be enabled", false);
|
---|
110 |
|
---|
111 | public static final BooleanSetting LogStats = new BooleanSetting("Whether stats should be logged", true);
|
---|
112 |
|
---|
113 | public static final BooleanSetting Threading = new BooleanSetting("Whether threading should be enabled", true);
|
---|
114 |
|
---|
115 |
|
---|
116 | /*
|
---|
117 | * Frames
|
---|
118 | */
|
---|
119 |
|
---|
120 | public static final StringSetting StatisticsFrameset = new StringSetting("The statistics frameset", null);
|
---|
121 |
|
---|
122 | public static final StringSetting MenuFrame = new StringSetting("The menu frame", null);
|
---|
123 |
|
---|
124 | /*
|
---|
125 | * Other
|
---|
126 | */
|
---|
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;
|
---|
153 | }
|
---|
154 | };
|
---|
155 |
|
---|
156 | public static final FunctionSetting SpellChecker = new FunctionSetting("Enables the dictionary with the default dictionary") {
|
---|
157 | @Override
|
---|
158 | public void run() {
|
---|
159 | try {
|
---|
160 | JSpellChecker.create();
|
---|
161 | } catch (FileNotFoundException e) {
|
---|
162 | MessageBay.errorMessage("Could not find dictionary: " + e.getMessage());
|
---|
163 | } catch (IOException e) {
|
---|
164 | e.printStackTrace();
|
---|
165 | }
|
---|
166 | }
|
---|
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 | }
|
---|
176 | }
|
---|
177 | };
|
---|
178 |
|
---|
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 | };
|
---|
185 |
|
---|
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);
|
---|
190 | }
|
---|
191 | };
|
---|
192 |
|
---|
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);
|
---|
197 | }
|
---|
198 | };
|
---|
199 |
|
---|
200 | // add default values
|
---|
201 | static {
|
---|
202 | setupDefaultFolders();
|
---|
203 | }
|
---|
204 |
|
---|
205 | public static void setupDefaultFolders() {
|
---|
206 | String expeditee_home = System.getProperty("expeditee.home");
|
---|
207 | if (expeditee_home != null) {
|
---|
208 | FrameIO.changeParentFolder(expeditee_home + File.separator);
|
---|
209 | } else {
|
---|
210 | FrameIO.changeParentFolder(getSaveLocation());
|
---|
211 | }
|
---|
212 |
|
---|
213 | FolderSettings.FrameDirs.get().clear();
|
---|
214 | FolderSettings.ImageDirs.get().clear();
|
---|
215 | appendDefaultFolders();
|
---|
216 | }
|
---|
217 |
|
---|
218 | public static void appendDefaultFolders() {
|
---|
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());
|
---|
227 | }
|
---|
228 |
|
---|
229 | /**
|
---|
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
|
---|
238 | */
|
---|
239 | public static String getSaveLocation() {
|
---|
240 | String OS=System.getProperty("os.name").toLowerCase();
|
---|
241 | if(OS.indexOf("win")>=0) { //windoze
|
---|
242 | return System.getenv("APPDATA")+File.separator+".expeditee"+File.separator;
|
---|
243 | } else if(OS.indexOf("mac")>=0) { //mac
|
---|
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;
|
---|
247 | }
|
---|
248 | }
|
---|
249 | }
|
---|