01: /*
02: * Created on Mar 24, 2003
03: *
04: * Dbmjui is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU General Public License version 2 as
06: * published by the Free Software Foundation.
07: *
08: * Dbmjui 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: * General Public License for more details.
12: *
13: * You should have received a copy of the GNU General Public
14: * License along with dbmjui; see the file COPYING. If not,
15: * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16: * Boston, MA 02111-1307, USA.
17: *
18: */
19: package fr.aliacom.dbmjui.beans;
20:
21: import java.io.Serializable;
22: import java.util.prefs.BackingStoreException;
23: import java.util.prefs.Preferences;
24:
25: /**
26: * @author tom
27: *
28: * (c) 2001, 2003 Thomas Cataldo
29: */
30: public final class BooleanPreference implements Serializable {
31:
32: private Preferences prefs;
33: private String displayName;
34: private String preferenceName;
35: private boolean curval;
36:
37: public BooleanPreference() {
38: }
39:
40: public BooleanPreference(Preferences prefs, String displayName,
41: String preferenceName) {
42: this .prefs = prefs;
43: this .displayName = displayName;
44: this .preferenceName = preferenceName;
45: curval = prefs.getBoolean(preferenceName, true);
46: }
47:
48: public boolean getValue() {
49: return curval;
50: }
51:
52: public void setValue(boolean b) {
53: System.out.println("Preference set to " + b);
54: curval = b;
55: }
56:
57: public void sync() throws BackingStoreException {
58: prefs.putBoolean(preferenceName, curval);
59: prefs.sync();
60: }
61:
62: public void reset() {
63: curval = prefs.getBoolean(preferenceName, true);
64: }
65:
66: /**
67: * @return the name that should be displayed for this preference
68: */
69: public String getDisplayName() {
70: return displayName;
71: }
72:
73: /**
74: * @param string
75: */
76: public void setDisplayName(String string) {
77: displayName = string;
78: }
79:
80: }
|