altosui: remove un-used import
[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.util.prefs.*;
21 import org.altusmetrum.AltosLib.*;
22
23 public class AltosUIPreferencesBackend implements AltosPreferencesBackend {
24
25         private Preferences _preferences = null;
26         
27         public AltosUIPreferencesBackend() {
28                 _preferences = Preferences.userRoot().node("/org/altusmetrum/altosui");
29         }
30
31         public AltosUIPreferencesBackend(Preferences in_preferences) {
32                 _preferences = in_preferences;
33         }
34
35         public String  getString(String key, String def) {
36                 return _preferences.get(key, def);
37         }
38         public void    putString(String key, String value) {
39                 _preferences.put(key, value);
40         }
41
42         public int     getInt(String key, int def) {
43                 return _preferences.getInt(key, def);
44         }
45         public void    putInt(String key, int value) {
46                 _preferences.putInt(key, value);
47         }
48
49         public double  getDouble(String key, double def) {
50                 return _preferences.getDouble(key, def);
51         }
52         public void    putDouble(String key, double value) {
53                 _preferences.putDouble(key, value);
54         }
55
56         public boolean getBoolean(String key, boolean def) {
57                 return _preferences.getBoolean(key, def);
58         }
59         public void    putBoolean(String key, boolean value) {
60                 _preferences.putBoolean(key, value);
61         }
62
63         public boolean nodeExists(String key) {
64                 try {
65                         return _preferences.nodeExists(key);
66                 } catch (BackingStoreException be) {
67                         return false;
68                 }
69         }
70
71         public AltosPreferencesBackend node(String key) {
72                 return new AltosUIPreferencesBackend(_preferences.node(key));
73         }
74
75         public String[] keys() {
76                 try {
77                         return _preferences.keys();
78                 } catch (BackingStoreException be) {
79                         return null;
80                 }
81         }
82
83         public void remove(String key) {
84                 _preferences.remove(key);
85         }
86
87         public void    flush() {
88                 try {
89                         _preferences.flush();
90                 } catch (BackingStoreException ee) {
91                         System.err.printf("Cannot save preferences\n");
92                 }
93         }
94
95 }