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

Last change on this file since 919 was 919, checked in by jts21, 10 years ago

Added license headers to all files, added full GPL3 license file, moved license header generator script to dev/bin/scripts

File size: 8.8 KB
Line 
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
19package org.expeditee.settings;
20
21import java.io.File;
22import java.io.FileNotFoundException;
23import java.io.IOException;
24import java.util.ArrayList;
25import java.util.LinkedList;
26import java.util.List;
27
28import org.expeditee.agents.SearchGreenstone;
29import org.expeditee.agents.mail.MailSession;
30import org.expeditee.agents.wordprocessing.JSpellChecker;
31import org.expeditee.gui.Frame;
32import org.expeditee.gui.FrameIO;
33import org.expeditee.gui.FrameUtils;
34import org.expeditee.gui.MessageBay;
35import org.expeditee.items.Text;
36import org.expeditee.setting.BooleanSetting;
37import org.expeditee.setting.FloatSetting;
38import org.expeditee.setting.FrameSetting;
39import org.expeditee.setting.FunctionSetting;
40import org.expeditee.setting.IntegerSetting;
41import org.expeditee.setting.ListSetting;
42import org.expeditee.setting.StringSetting;
43import 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 */
50public 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 String expeditee_home = System.getProperty("expeditee.home");
203 if (expeditee_home != null) {
204 FrameIO.changeParentFolder(expeditee_home + File.separator);
205 } else {
206 FrameIO.changeParentFolder(getSaveLocation());
207 }
208
209 FolderSettings.FrameDirs.get().add(FrameIO.FRAME_PATH);
210 FolderSettings.FrameDirs.get().add(FrameIO.PUBLIC_PATH);
211 FolderSettings.FrameDirs.get().add(FrameIO.PROFILE_PATH);
212 FolderSettings.FrameDirs.get().add(FrameIO.HELP_PATH);
213 FolderSettings.FrameDirs.get().add(FrameIO.MESSAGES_PATH);
214 FolderSettings.FrameDirs.setDefault(FolderSettings.FrameDirs.get());
215 FolderSettings.ImageDirs.get().add(FrameIO.IMAGES_PATH);
216 FolderSettings.ImageDirs.setDefault(FolderSettings.ImageDirs.get());
217 }
218
219 /**
220 * Find the appropriate directory to store application settings in for
221 * the current OS.
222 * This has only been tested on Linux so far, so if it doesn't work it
223 * may need to be modified or reverted. Should return:
224 * Linux: ~/.expeditee
225 * Windows: %appdata%\.expeditee
226 * Mac: ~/Library/Application\ Support/.expeditee
227 * @return the path to store expeditee's settings
228 */
229 public static String getSaveLocation() {
230 String OS=System.getProperty("os.name").toLowerCase();
231 if(OS.indexOf("win")>=0) { //windoze
232 return System.getenv("APPDATA")+File.separator+".expeditee"+File.separator;
233 } else if(OS.indexOf("mac")>=0) { //mac
234 return System.getProperty("user.home")+File.separator+"Library"+File.separator+"Application Support"+File.separator+".expeditee"+File.separator;
235 } else { //linux or other
236 return System.getProperty("user.home")+File.separator+".expeditee"+File.separator;
237 }
238 }
239}
Note: See TracBrowser for help on using the repository browser.