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

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

Move some settings into subpackages to tidy up the main settings page a bit, and make settings parser look for settings in subpages of the current settings page if it finds a setting it doesn't know what to do with

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