OSDN Git Service

Update changelog to correct change date.
[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 = "NeverNote";
16     private String homeDirPath;
17     private String programDirPath;
18     private boolean disableViewing = false;
19
20
21     public String getName() {
22         return name;
23     }
24
25     public void setName(String n) {
26         if (isNonEmpty(n)) {
27             name = "NeverNote-" + n;
28         }
29     }
30
31     public String getProgramDirPath() {
32         if (programDirPath == null) {
33            programDirPath = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
34            if (programDirPath.endsWith(".jar")) {
35                    programDirPath = programDirPath.substring(0,programDirPath.lastIndexOf("/"));
36            } else {
37                    if (programDirPath.endsWith("/")) {
38                            programDirPath = programDirPath.substring(0,programDirPath.length()-1);
39                    }
40                            programDirPath = programDirPath.substring(0,programDirPath.lastIndexOf("/"));
41            }
42         }
43         return programDirPath;
44     }
45     
46     public String getHomeDirPath() {
47         if (homeDirPath == null) {
48                 homeDirPath = System.getProperty("user.home") + File.separator 
49                                 + "." +name.toLowerCase() + File.separator;
50         }
51         return homeDirPath;
52     }
53
54     public void setHomeDirPath(String path) {
55         if (isNonEmpty(path)) {
56             homeDirPath = path;
57         }
58     }
59     
60     public void setProgramDirPath(String path) {
61         if (isNonEmpty(path)) {
62             programDirPath = path;
63         }
64     }
65
66     
67     public boolean getDisableViewing() {
68         return disableViewing;
69     }
70
71     public void setDisableViewing(boolean disableViewing) {
72         this.disableViewing = disableViewing;
73     }
74
75     private static boolean isNonEmpty(String n) {
76         return n != null && !n.trim().equals("");
77     }
78
79 }