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