|
1
|
|
package abbot.editor;
|
|
2
|
|
|
|
3
|
|
import java.io.*;
|
|
4
|
|
import java.util.Properties;
|
|
5
|
|
|
|
6
|
|
import abbot.Log;
|
|
7
|
|
|
|
8
|
|
public class Preferences extends Properties {
|
|
9
|
|
|
|
10
|
|
public static final String PROPS_FILENAME = ".abbot.properties";
|
|
11
|
|
private File file;
|
|
12
|
|
|
|
13
|
0
|
public Preferences() {
|
|
14
|
0
|
this(PROPS_FILENAME);
|
|
15
|
|
}
|
|
16
|
|
|
|
17
|
4
|
public Preferences(String filename) {
|
|
18
|
4
|
file = new File(new File(System.getProperty("user.home")), filename);
|
|
19
|
4
|
load();
|
|
20
|
|
}
|
|
21
|
|
|
|
22
|
12
|
public int getIntegerProperty(String name, int defaultValue) {
|
|
23
|
12
|
String prop = getProperty(name);
|
|
24
|
12
|
if (prop != null) {
|
|
25
|
6
|
try {
|
|
26
|
6
|
return Integer.parseInt(prop);
|
|
27
|
|
}
|
|
28
|
|
catch(Exception e) {
|
|
29
|
0
|
Log.warn(e);
|
|
30
|
|
}
|
|
31
|
|
}
|
|
32
|
6
|
return defaultValue;
|
|
33
|
|
}
|
|
34
|
|
|
|
35
|
4
|
private void load() {
|
|
36
|
4
|
if (file.exists()) {
|
|
37
|
3
|
try {
|
|
38
|
3
|
load(new BufferedInputStream(new FileInputStream(file)));
|
|
39
|
|
}
|
|
40
|
|
catch(IOException io) {
|
|
41
|
0
|
Log.warn(io);
|
|
42
|
|
}
|
|
43
|
|
}
|
|
44
|
|
}
|
|
45
|
|
|
|
46
|
2
|
public void save() {
|
|
47
|
2
|
try { store(new BufferedOutputStream(new FileOutputStream(file)),
|
|
48
|
|
"Abbot view preferences"); }
|
|
49
|
0
|
catch(IOException io) { Log.warn(io); }
|
|
50
|
|
}
|
|
51
|
|
}
|
|
52
|
|
|