1 | package org.expeditee.gui;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.net.URL;
|
---|
5 | import java.util.LinkedList;
|
---|
6 | import java.util.List;
|
---|
7 |
|
---|
8 | import org.expeditee.items.Text;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * Central class to contain all values that can be set by the user on their
|
---|
12 | * profile frame. These values should be updated only by
|
---|
13 | * FrameUtils.ParseProfile.
|
---|
14 | */
|
---|
15 | public abstract class UserSettings {
|
---|
16 |
|
---|
17 | public static int Gravity = 3;
|
---|
18 |
|
---|
19 | public static int LineStraightenThreshold = 15;
|
---|
20 |
|
---|
21 | public static int NoOpThreshold = 60;
|
---|
22 |
|
---|
23 | public static int InitialWidth = 1024;
|
---|
24 |
|
---|
25 | public static int InitialHeight = 768;
|
---|
26 |
|
---|
27 | public static String Username;
|
---|
28 |
|
---|
29 | public static String DefaultFrame = null;
|
---|
30 |
|
---|
31 | public static String MenuFrame = null;
|
---|
32 |
|
---|
33 | public static String FirstFrame = null;
|
---|
34 |
|
---|
35 | public static List<String> FrameDirs = new LinkedList<String>();
|
---|
36 |
|
---|
37 | public static List<String> ImageDirs = new LinkedList<String>();
|
---|
38 |
|
---|
39 | public static boolean AntiAlias = false;
|
---|
40 |
|
---|
41 | public static boolean LineHighlight = false;
|
---|
42 |
|
---|
43 | public static boolean Logging = false;
|
---|
44 |
|
---|
45 | public static boolean LogStats = true;
|
---|
46 |
|
---|
47 | public static boolean Threading = true;
|
---|
48 |
|
---|
49 | public static Text ItemTemplate = new Text(-1, "@ItemTemplate");
|
---|
50 |
|
---|
51 | public static Text AnnotationTemplate = null;
|
---|
52 |
|
---|
53 | public static Text CodeCommentTemplate = null;
|
---|
54 |
|
---|
55 | public static Text TitleTemplate = null;
|
---|
56 |
|
---|
57 | // add default values
|
---|
58 | public static void Init() {
|
---|
59 | String jarPath = getJarLocation();
|
---|
60 | if (jarPath != null)
|
---|
61 | FrameIO.changeParentFolder(jarPath);
|
---|
62 | else
|
---|
63 | FrameIO.changeParentFolder("." + File.separator + "expeditee"
|
---|
64 | + File.separator);
|
---|
65 |
|
---|
66 | UserSettings.FrameDirs.add(FrameIO.FRAME_PATH);
|
---|
67 | UserSettings.FrameDirs.add(FrameIO.PROFILE_PATH);
|
---|
68 | UserSettings.FrameDirs.add(FrameIO.HELP_PATH);
|
---|
69 | UserSettings.ImageDirs.add(FrameIO.IMAGES_PATH);
|
---|
70 | }
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Find where abouts the Jar is located that is running expeditee. The
|
---|
74 | * reason for this was so that the framesets could be stored in the same
|
---|
75 | * location as the jar file for now. Using the current directory fails to
|
---|
76 | * achieve this as the current directory not the same as the directory the
|
---|
77 | * jar is stored in if the user double clicks on the jar file in Linux or
|
---|
78 | * runs the jar from the command line from another directory.
|
---|
79 | *
|
---|
80 | * @return
|
---|
81 | */
|
---|
82 | public static String getJarLocation() {
|
---|
83 | // Get a File object for the package
|
---|
84 | File directory = null;
|
---|
85 |
|
---|
86 | ClassLoader cld = Thread.currentThread().getContextClassLoader();
|
---|
87 | URL resource = cld.getResource("org");
|
---|
88 | directory = new File(resource.getFile());
|
---|
89 |
|
---|
90 | int splitPoint = directory.getPath().indexOf('!');
|
---|
91 | if (splitPoint > 0) {
|
---|
92 | String jarName = directory.getPath().substring("file:".length(),
|
---|
93 | splitPoint);
|
---|
94 | // Windows HACK
|
---|
95 | if (jarName.indexOf(":") >= 0)
|
---|
96 | jarName = jarName.substring(1);
|
---|
97 |
|
---|
98 | if (jarName.indexOf("%20") > 0) {
|
---|
99 | jarName = jarName.replace("%20", " ");
|
---|
100 | }
|
---|
101 |
|
---|
102 | int lastFileSeparator = jarName.lastIndexOf(File.separator);
|
---|
103 | return jarName.substring(0, lastFileSeparator + 1);
|
---|
104 | }
|
---|
105 | return null;
|
---|
106 | }
|
---|
107 | }
|
---|