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

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

Renamed Frame.getItems() to Frame.getSortedItems() to better represent its functionality.

-> org.apollo.ApolloGestureActions
-> org.apollo.ApolloSystem
-> org.expeditee.actions.Actions
-> org.expeditee.actions.Debug
-> org.expeditee.actions.ExploratorySearchActions
-> org.expeditee.actions.JfxBrowserActions
-> org.expeditee.actions.Misc
-> org.expeditee.actions.Navigation
-> org.expeditee.actions.ScriptBase
-> org.expeditee.actions.Simple
-> org.expeditee.agents.ComputeTree
-> org.expeditee.agents.CopyTree
-> org.expeditee.agents.DisplayComet
-> org.expeditee.agents.DisplayTree
-> org.expeditee.agents.DisplayTreeLeaves
-> org.expeditee.agents.GraphFramesetLinks
-> org.expeditee.agents.TreeProcessor
-> org.expeditee.gio.gesture.StandardGestureActions
-> org.expeditee.gui.DisplayController
-> org.expeditee.gui.FrameCreator
-> org.expeditee.gui.FrameIO
-> org.expeditee.io.DefaultTreeWriter
-> org.expeditee.io.JavaWriter
-> org.expeditee.io.PDF2Writer
-> org.expeditee.io.TXTWriter
-> org.expeditee.io.WebParser
-> org.expeditee.io.flowlayout.XGroupItem
-> org.expeditee.items.Dot
-> org.expeditee.items.Item
-> org.expeditee.items.ItemUtils
-> org.expeditee.network.FrameShare
-> org.expeditee.stats.TreeStats


Created ItemsList class to wrap ArrayList<Item>. Frames now use this new class to store its body list (used for display) as well as its primaryBody and surrogateBody.

-> org.expeditee.agents.Format
-> org.expeditee.agents.HFormat
-> org.expeditee.gio.gesture.StandardGestureActions
-> org.expeditee.gui.Frame
-> org.expeditee.gui.FrameUtils


Refactorted Frame.setResort(bool) to Frame.invalidateSorted() to better function how it is intended to with a more accurate name.

-> org.expeditee.agents.Sort


When writing out .exp files and getting attributes to respond to LEFT + RIGHT click, boolean items are by default true. This has always been the case. An ammendment to this is that defaults can now be established.
Also added 'EnterClick' functionality. If cursored over a item with this property and you press enter, it acts as if you have clicked on it instead.

-> org.expeditee.assets.resources-public.framesets.authentication.1.exp to 6.exp
-> org.expeditee.gio.gesture.StandardGestureActions
-> org.expeditee.gio.input.KBMInputEvent
-> org.expeditee.gio.javafx.JavaFXConversions
-> org.expeditee.gio.swing.SwingConversions
-> org.expeditee.gui.AttributeUtils
-> org.expeditee.io.Conversion
-> org.expeditee.io.DefaultFrameWriter
-> org.expeditee.items.Item


Fixed a bug caused by calling Math.abs on Integer.MIN_VALUE returning unexpected result. Due to zero being a thing, you cannot represent Math.abs(Integer.MIN_VALUE) in a Integer object. The solution is to use Integer.MIN_VALUE + 1 instead of Integer.MIN_VALUE.

-> org.expeditee.core.bounds.CombinationBounds
-> org.expeditee.io.flowlayout.DimensionExtent


Recoded the contains function in EllipticalBounds so that intersection tests containing circles work correctly.

-> org.expeditee.core.bounds.EllipticalBounds


Added toString() to PolygonBounds to allow for useful printing during debugging.

-> org.expeditee.core.bounds.PolygonBounds

Implemented Surrogate Mode!

-> org.expeditee.encryption.io.EncryptedExpReader
-> org.expeditee.encryption.io.EncryptedExpWriter
-> org.expeditee.encryption.items.surrogates.EncryptionDetail
-> org.expeditee.encryption.items.surrogates.Label
-> org.expeditee.gui.FrameUtils
-> org.expeditee.gui.ItemsList
-> org.expeditee.items.Item
-> org.expeditee.items.Text


???? Use Integer.MAX_VALUE cast to a float instead of Float.MAX_VALUE. This fixed some bug which I cannot remember.

-> org.expeditee.gio.TextLayoutManager
-> org.expeditee.gio.swing.SwingTextLayoutManager


Improved solution for dealing with the F10 key taking focus away from Expeditee due to it being a assessibility key.

-> org.expeditee.gio.swing.SwingInputManager


Renamed variable visibleItems in FrameGraphics.paintFrame to itemsToPaintCanditates to better represent functional intent.

-> org.expeditee.gui.FrameGraphics


Improved checking for if personal resources exist before recreating them

-> org.expeditee.gui.FrameIO


Repeated messages to message bay now have a visual feedback instead of just a beep. This visual feedback is in the form of a count of the amount of times it has repeated.

-> org.expeditee.gui.MessageBay


Updated comment on the Vector class to explain what vectors are.

-> org.expeditee.gui.Vector


Added constants to represent all of the property keys in DefaultFrameReader and DefaultFrameWriter.

-> org.expeditee.io.DefaultFrameReader
-> org.expeditee.io.DefaultFrameWriter


Updated the KeyList setting to be more heirarcial with how users will store their Secrets.

-> org.expeditee.settings.identity.secrets.KeyList

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