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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.altosuilib_11;
22 import java.util.prefs.*;
23 import org.altusmetrum.altoslib_11.*;
24 import javax.swing.filechooser.FileSystemView;
26 public class AltosUIPreferencesBackend extends AltosPreferencesBackend {
28 private Preferences _preferences = null;
30 public AltosUIPreferencesBackend() {
31 _preferences = Preferences.userRoot().node("/org/altusmetrum/altosui");
34 public AltosUIPreferencesBackend(Preferences in_preferences) {
35 _preferences = in_preferences;
38 public String getString(String key, String def) {
39 return _preferences.get(key, def);
41 public void putString(String key, String value) {
42 _preferences.put(key, value);
45 public int getInt(String key, int def) {
46 return _preferences.getInt(key, def);
48 public void putInt(String key, int value) {
49 _preferences.putInt(key, value);
52 public double getDouble(String key, double def) {
53 return _preferences.getDouble(key, def);
55 public void putDouble(String key, double value) {
56 _preferences.putDouble(key, value);
59 public boolean getBoolean(String key, boolean def) {
60 return _preferences.getBoolean(key, def);
62 public void putBoolean(String key, boolean value) {
63 _preferences.putBoolean(key, value);
66 public byte[] getBytes(String key, byte[] def) {
67 return _preferences.getByteArray(key, def);
70 public void putBytes(String key, byte[] value) {
71 _preferences.putByteArray(key, value);
74 public boolean nodeExists(String key) {
76 return _preferences.nodeExists(key);
77 } catch (BackingStoreException be) {
82 public AltosPreferencesBackend node(String key) {
83 return new AltosUIPreferencesBackend(_preferences.node(key));
86 public String[] keys() {
88 return _preferences.keys();
89 } catch (BackingStoreException be) {
94 public void remove(String key) {
95 _preferences.remove(key);
100 _preferences.flush();
101 } catch (BackingStoreException ee) {
102 System.err.printf("Cannot save preferences\n");
106 public File homeDirectory() {
107 /* Use the file system view default directory */
108 return FileSystemView.getFileSystemView().getDefaultDirectory();
111 public void debug(String format, Object ... arguments) {
112 System.out.printf(format, arguments);