01: /*
02: * NbPrefs.java
03: *
04: * Created on September 26, 2006, 10:04 PM
05: *
06: * To change this template, choose Tools | Template Manager
07: * and open the template in the editor.
08: */
09:
10: package org.jvnet.substance.netbeans.ui;
11:
12: import java.io.IOException;
13: import org.openide.ErrorManager;
14: import org.openide.filesystems.FileObject;
15: import org.openide.filesystems.Repository;
16:
17: /**
18: * Quick'n'dirty key/value storage; pending an implementation of Preferences
19: * in NB.
20: *
21: * @author Tim Boudreau
22: */
23: public class NbPrefs {
24: public void put(String key, String value) {
25: try {
26: getStore().setAttribute(key, value);
27: } catch (IOException ex) {
28: ErrorManager.getDefault().notify(ex);
29: }
30: }
31:
32: public String get(String key, String defaultValue) {
33: String result = (String) getStore().getAttribute(key);
34: return result == null ? defaultValue : result;
35: }
36:
37: private static FileObject store;
38: private static final String FILE_NAME = "SubstanceLFPrefs";
39:
40: private static FileObject getStore() {
41: if (store == null) {
42: FileObject ob = Repository.getDefault()
43: .getDefaultFileSystem().getRoot();
44: store = ob.getFileObject("SubstanceLFPrefs");
45: if (store == null) {
46: try {
47: store = ob.createData(FILE_NAME);
48: } catch (IOException ex) {
49: //if this happens, whole app is broken - don't try to
50: //be graceful. Should never occur.
51: throw new IllegalStateException(ex);
52: }
53: }
54: }
55: return store;
56: }
57: }
|