View Javadoc

1   package org.catacomb.druid.load;
2   
3   
4   import org.catacomb.serial.quickxml.XMLFileElement;
5   
6   import java.io.File;
7   
8   
9   
10  
11  public class Settings {
12  
13  
14      XMLFileElement xrecent;
15      XMLFileElement xpref;
16  
17  
18      public Settings(String appname) {
19  
20          File fuser = new File(System.getProperty("user.home"));
21          File fccmb = new File(fuser, ".catacomb");
22          if (fccmb.exists()) {
23              // OK;
24          } else {
25              fccmb.mkdir();
26          }
27  
28          File fapp = new File(fccmb, appname);
29          if (fapp.exists()) {
30              // OK;
31          } else {
32              fapp.mkdir();
33          }
34  
35  
36          xrecent = new XMLFileElement(fapp, "recent");
37          xpref = new XMLFileElement(fapp, "preferences");
38      }
39  
40  
41      public void addRecentFile(File f) {
42          addRecentPath(f.getAbsolutePath());
43      }
44  
45  
46      public void addRecentPath(String fpath) {
47          xrecent.prependElementUnique("path", fpath);
48          xrecent.limitNumber("path", 10);
49          xrecent.sync();
50      }
51  
52  
53      public String[] getRecentPaths() {
54          return xrecent.getValues("path");
55      }
56  
57  
58  
59      public void addElement(String name, String value) {
60          xpref.prependElementUnique(name, value);
61          xpref.sync();
62      }
63  
64      public boolean hasElement(String name, String value) {
65          return xpref.hasElement(name, value);
66      }
67  
68      public boolean hasElement(String name) {
69          return xpref.hasElement(name);
70      }
71  
72      public String getValue(String eltname) {
73          return xpref.getValue(eltname);
74      }
75  
76      public void setElement(String name, String value) {
77          xpref.setElement(name, value);
78          xpref.sync();
79      }
80  
81  }