altosui/altoslib: bug fixes, update Makefile.am
[fw/altos] / altosui / AltosUIPreferencesBackend.java
1 /*
2  * Copyright © 2012 Mike Beattie <mike@ethernal.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 package altosui;
19
20 import java.text.*;
21 import java.util.prefs.*;
22 import org.altusmetrum.AltosLib.*;
23
24 public class AltosUIPreferencesBackend implements AltosPreferencesBackend {
25
26         private Preferences _preferences = null;
27         
28         public AltosUIPreferencesBackend() {
29                 _preferences = Preferences.userRoot().node("/org/altusmetrum/altosui");
30         }
31
32         public AltosUIPreferencesBackend(Preferences in_preferences) {
33                 _preferences = in_preferences;
34         }
35
36         public String  getString(String key, String def) {
37                 return _preferences.get(key, def);
38         }
39         public void    putString(String key, String value) {
40                 _preferences.put(key, value);
41         }
42
43         public int     getInt(String key, int def) {
44                 return _preferences.getInt(key, def);
45         }
46         public void    putInt(String key, int value) {
47                 _preferences.putInt(key, value);
48         }
49
50         public double  getDouble(String key, double def) {
51                 return _preferences.getDouble(key, def);
52         }
53         public void    putDouble(String key, double value) {
54                 _preferences.putDouble(key, value);
55         }
56
57         public boolean getBoolean(String key, boolean def) {
58                 return _preferences.getBoolean(key, def);
59         }
60         public void    putBoolean(String key, boolean value) {
61                 _preferences.putBoolean(key, value);
62         }
63
64         public boolean nodeExists(String key) {
65                 try {
66                         return _preferences.nodeExists(key);
67                 } catch (BackingStoreException be) {
68                         return false;
69                 }
70         }
71
72         public AltosPreferencesBackend node(String key) {
73                 return new AltosUIPreferencesBackend(_preferences.node(key));
74         }
75
76         public String[] keys() {
77                 return _preferences.keys();
78         }
79
80         public void remove(String key) {
81                 _preferences.remove(key);
82         }
83
84         public void    flush() {
85                 try {
86                         _preferences.flush();
87                 } catch (BackingStoreException ee) {
88                         System.err.printf("Cannot save preferences\n");
89                 }
90         }
91
92 }