OSDN Git Service

Merge remote-tracking branch 'origin/develop'
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / config / StartupConfig.java
1 package cx.fbn.nevernote.config;
2
3 import java.io.File;
4
5
6
7 /**
8  * Things that can only be changed at startup
9  *
10  * @author Nick Clarke
11  */
12 public class StartupConfig {
13
14     // Init to default values
15     private String name = "NeighborNote";
16     private String homeDirPath;
17     private String programDirPath;
18     private boolean disableViewing = false;
19     private boolean syncOnly = false;
20
21
22     public String getName() {
23         return name;
24     }
25
26     public void setName(String n) {
27         if (isNonEmpty(n)) {
28             name = "NeighborNote-" + n;
29         }
30     }
31
32     public String getProgramDirPath() {
33         if (programDirPath == null) {
34            programDirPath = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
35            if (programDirPath.endsWith(".jar")) {
36                    programDirPath = programDirPath.substring(0,programDirPath.lastIndexOf("/"));
37            } else {
38                    if (programDirPath.endsWith("/")) {
39                            programDirPath = programDirPath.substring(0,programDirPath.length()-1);
40                    }
41                            programDirPath = programDirPath.substring(0,programDirPath.lastIndexOf("/"));
42            }
43         }
44         return programDirPath;
45     }
46     
47     public String getHomeDirPath() {
48         if (homeDirPath == null) {
49                 homeDirPath = System.getProperty("user.home") + File.separator 
50                                 + "." +name.toLowerCase() + File.separator;
51         }
52         return homeDirPath;
53     }
54
55     public void setHomeDirPath(String path) {
56         if (isNonEmpty(path)) {
57             homeDirPath = path;
58         }
59     }
60     
61     public void setProgramDirPath(String path) {
62         if (isNonEmpty(path)) {
63             programDirPath = path;
64         }
65     }
66
67     
68     public boolean getDisableViewing() {
69         return disableViewing;
70     }
71
72     public void setDisableViewing(boolean disableViewing) {
73         this.disableViewing = disableViewing;
74     }
75
76     private static boolean isNonEmpty(String n) {
77         return n != null && !n.trim().equals("");
78     }
79
80     public boolean isSyncOnly() {
81         return syncOnly;
82     }
83     
84     public void setSyncOnly(boolean val) {
85         syncOnly = val;
86     }
87 }