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

Last change on this file since 1434 was 1434, checked in by bln4, 5 years ago

Implementation of ProfileManager. Refactor + additional content for how new profiles are created. The refactoring split out the creation of the default profile from user profiles. Refactoring revealed a long term bug that was causing user profiles to generate with incorrect information. The additional content fixed this bug by introducing the ${USER.NAME} variable, so that the default profile frameset can specify resource locations located in the users resource directory.

org.expeditee.auth.AuthenticatorBrowser
org.expeditee.auth.account.Create
org.expeditee.gui.Browser
org.expeditee.gui.management.ProfileManager
org.expeditee.setting.DirectoryListSetting
org.expeditee.setting.ListSetting
org.expeditee.settings.UserSettings

Implementation of ResourceManager as a core location to get resources from the file system. Also the additional variable ${CURRENT_FRAMESET} to represent the current frameset, so that images can be stored in the directory of the current frameset. This increases portability of framesets.

org.expeditee.gui.FrameIO
org.expeditee.gui.management.ResourceManager
org.expeditee.gui.management.ResourceUtil
Audio:

#NB: Audio used to only operate on a single directory. This has been updated to work in a same way as images. That is: when you ask for a specific resouce, it looks to the user settings to find a sequence of directories to look at in order until it manages to find the desired resource.


There is still need however for a single(ish) source of truth for the .banks and .mastermix file. Therefore these files are now always located in resource-<username>\audio.
org.apollo.agents.MelodySearch
org.apollo.audio.structure.AudioStructureModel
org.apollo.audio.util.MultiTrackPlaybackController
org.apollo.audio.util.SoundDesk
org.apollo.gui.FrameLayoutDaemon
org.apollo.io.AudioPathManager
org.apollo.util.AudioPurger
org.apollo.widgets.FramePlayer
org.apollo.widgets.SampledTrack

Images:

org.expeditee.items.ItemUtils

Frames:

org.expeditee.gui.FrameIO

Fixed a error in the FramePlayer class caused by an incorrect use of toArray().

org.apollo.widgets.FramePlayer


Added several short cut keys to allow for the Play/Pause (Ctrl + P), mute (Ctrl + M) and volume up/down (Ctrl + +/-) when hovering over SampledTrack widgets.

org.apollo.widgets.SampledTrack


Changed the way that Authenticate.login parses the new users profile to be more consistance with other similar places in code.

org.expeditee.auth.account.Authenticate


Encapsulated _body, _surrogateItemsBody and _primaryItemsBody in Frame class. Also changed getBody function to take a boolean flag as to if it should respect the current surrogate mode. If it should then it makes sure that labels have not changed since last time getBody was called.

org.expeditee.gui.Frame

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