2 * Copyright © 2012 Mike Beattie <mike@ethernal.org>
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.
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.
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.
18 package org.altusmetrum.altosuilib_3;
21 import java.util.prefs.*;
22 import org.altusmetrum.altoslib_5.*;
23 import javax.swing.filechooser.FileSystemView;
25 public class AltosUIPreferencesBackend implements AltosPreferencesBackend {
27 private Preferences _preferences = null;
29 public AltosUIPreferencesBackend() {
30 _preferences = Preferences.userRoot().node("/org/altusmetrum/altosui");
33 public AltosUIPreferencesBackend(Preferences in_preferences) {
34 _preferences = in_preferences;
37 public String getString(String key, String def) {
38 return _preferences.get(key, def);
40 public void putString(String key, String value) {
41 _preferences.put(key, value);
44 public int getInt(String key, int def) {
45 return _preferences.getInt(key, def);
47 public void putInt(String key, int value) {
48 _preferences.putInt(key, value);
51 public double getDouble(String key, double def) {
52 return _preferences.getDouble(key, def);
54 public void putDouble(String key, double value) {
55 _preferences.putDouble(key, value);
58 public boolean getBoolean(String key, boolean def) {
59 return _preferences.getBoolean(key, def);
61 public void putBoolean(String key, boolean value) {
62 _preferences.putBoolean(key, value);
65 public boolean nodeExists(String key) {
67 return _preferences.nodeExists(key);
68 } catch (BackingStoreException be) {
73 public AltosPreferencesBackend node(String key) {
74 return new AltosUIPreferencesBackend(_preferences.node(key));
77 public String[] keys() {
79 return _preferences.keys();
80 } catch (BackingStoreException be) {
85 public void remove(String key) {
86 _preferences.remove(key);
92 } catch (BackingStoreException ee) {
93 System.err.printf("Cannot save preferences\n");
97 public File homeDirectory() {
98 /* Use the file system view default directory */
99 return FileSystemView.getFileSystemView().getDefaultDirectory();