01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.client.modules.preferences;
19:
20: import java.util.prefs.BackingStoreException;
21: import java.util.prefs.Preferences;
22:
23: import javax.swing.ImageIcon;
24:
25: public class PreferencesDescription {
26:
27: private String name, description;
28:
29: private Preferences preferences;
30:
31: private ImageIcon smallIcon;
32:
33: public PreferencesDescription(Preferences preferences, String name,
34: String description, ImageIcon smallIcon) {
35: this .preferences = preferences;
36: this .name = name;
37: this .description = description;
38: this .smallIcon = smallIcon;
39: }
40:
41: public String toString() {
42: return name;
43: }
44:
45: public String getName() {
46: return name;
47: }
48:
49: public String getDescription() {
50: return description;
51: }
52:
53: public ImageIcon getSmallIcon() {
54: return smallIcon;
55: }
56:
57: public Preferences getPreferences() {
58: return preferences;
59: }
60:
61: public void defineProperty(String key, String defaultValue) {
62: if (!propertyExists(key)) {
63: preferences.put(key, defaultValue);
64: }
65: }
66:
67: public void defineProperty(String key, int defaultValue) {
68: if (!propertyExists(key)) {
69: preferences.putInt(key, defaultValue);
70: }
71: }
72:
73: public void defineProperty(String key, boolean defaultValue) {
74: if (!propertyExists(key)) {
75: preferences.putBoolean(key, defaultValue);
76: }
77: }
78:
79: private boolean propertyExists(String key) {
80: try {
81: String[] keys = preferences.keys();
82: for (int i = 0; i < keys.length; i++) {
83: if (keys[i].equals(key)) {
84: return true;
85: }
86: }
87: } catch (BackingStoreException bse) {
88: // ignore
89: }
90: return false;
91: }
92: }
|