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

Last change on this file since 571 was 571, checked in by jts21, 11 years ago

Add the capability to use setter functions that will be called to set a setting.
Moved some stuff over to use this already (colorwheel and homeframe) to test that it works.
This means it should now be possible to add new user configurable settings by simply defining a function or a field in a settings class (the class structure corresponds to the page structure).

File size: 4.0 KB
Line 
1package org.expeditee.settings;
2
3import java.awt.Color;
4import java.io.File;
5import java.util.LinkedList;
6import java.util.List;
7
8import org.expeditee.gui.Frame;
9import org.expeditee.gui.FrameIO;
10import org.expeditee.gui.FrameUtils;
11import org.expeditee.items.Item;
12import org.expeditee.items.Text;
13
14/**
15 * Central class to contain all values that can be set by the user on their
16 * profile frame. These values should be updated only by
17 * FrameUtils.ParseProfile.
18 */
19public abstract class UserSettings {
20
21 public final static String DEFAULT_PROFILE_NAME = "default";
22
23 public static List<Text> Style = new LinkedList<Text>();;
24
25 public static int Gravity = 3;
26
27 public static float ScaleFactor = 1F;
28
29 public static int LineStraightenThreshold = 15;
30
31 public static int NoOpThreshold = 60;
32
33 public static int TitlePosition = 150;
34
35 public static int InitialWidth = 1024;
36
37 public static int InitialHeight = 768;
38
39 public static String ProfileName;
40
41 public static String UserName;
42
43 public static String DefaultFrame = null;
44
45 public static String StatisticsFrameset = null;
46
47 public static String MenuFrame = null;
48
49 public static String HomeFrame = null;
50 public static void setHomeFrame(Text t) {
51 String first = FrameUtils.getLink(t, UserSettings.HomeFrame);
52 // do not use non-existant frames as the first frame
53 if (FrameIO.isValidFrameName(first)) {
54 UserSettings.HomeFrame = first;
55 }
56 // warn the user
57 else {
58 // MessageBay.warningMessage("Home frame: " + first
59 // + " is not a valid frame.");
60 UserSettings.HomeFrame = FrameIO.LoadProfile(UserSettings.ProfileName).getName();
61 }
62 }
63
64 public static List<String> FrameDirs = new LinkedList<String>();
65
66 public static List<String> ImageDirs = new LinkedList<String>();
67
68 public static boolean AntiAlias = false;
69
70 public static boolean LineHighlight = false;
71
72 public static boolean Logging = false;
73
74 public static boolean LogStats = true;
75
76 public static boolean Threading = true;
77
78 public static Text ItemTemplate = new Text("@ItemTemplate");
79
80 public static Text DotTemplate = new Text("@DotTemplate");
81
82 public static Text AnnotationTemplate = null;
83
84 public static Text CodeCommentTemplate = null;
85
86 public static Text TitleTemplate = null;
87
88 public static Text StatTemplate = null;
89
90 public static void setColorWheel(Text t) {
91 Item.COLOR_WHEEL = FrameUtils.getColorWheel(t);
92 }
93
94 public static void setFillColorWheel(Text t) {
95 Item.FILL_COLOR_WHEEL = FrameUtils.getColorWheel(t);
96 }
97
98 public static void setBackgroundColorWheel(Text t) {
99 Frame.COLOR_WHEEL = FrameUtils.getColorWheel(t);
100 }
101
102 // add default values
103 static {
104 String expeditee_home = System.getProperty("expeditee.home");
105 if (expeditee_home != null) {
106 FrameIO.changeParentFolder(expeditee_home + File.separator);
107 } else {
108 FrameIO.changeParentFolder(getSaveLocation());
109 }
110
111 UserSettings.FrameDirs.add(FrameIO.FRAME_PATH);
112 UserSettings.FrameDirs.add(FrameIO.PUBLIC_PATH);
113 UserSettings.FrameDirs.add(FrameIO.PROFILE_PATH);
114 UserSettings.FrameDirs.add(FrameIO.HELP_PATH);
115 UserSettings.ImageDirs.add(FrameIO.IMAGES_PATH);
116 UserSettings.FrameDirs.add(FrameIO.MESSAGES_PATH);
117 }
118
119 /**
120 * Find the appropriate directory to store application settings in for
121 * the current OS.
122 * This has only been tested on Linux so far, so if it doesn't work it
123 * may need to be modified or reverted. Should return:
124 * Linux: ~/.expeditee
125 * Windows: %appdata%\.expeditee
126 * Mac: ~/Library/Application\ Support/.expeditee
127 * @return the path to store expeditee's settings
128 */
129 public static String getSaveLocation() {
130 String OS=System.getProperty("os.name").toLowerCase();
131 if(OS.indexOf("win")>0) { //windoze
132 return System.getenv("APPDATA")+File.separator+".expeditee"+File.separator;
133 } else if(OS.indexOf("mac")>0) { //mac
134 return System.getProperty("user.home")+File.separator+"Library"+File.separator+"Application Support"+File.separator+".expeditee"+File.separator;
135 } else { //linux or other
136 return System.getProperty("user.home")+File.separator+".expeditee"+File.separator;
137 }
138 }
139}
Note: See TracBrowser for help on using the repository browser.