KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > ui > basic > SchemaSettings


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.schema.ui.basic;
21
22 import java.io.IOException JavaDoc;
23 import java.io.ObjectInput JavaDoc;
24 import org.openide.util.HelpCtx;
25 import org.openide.util.NbBundle;
26 import org.openide.util.NbPreferences;
27
28 /**
29  * Manages the schema editor options.
30  *
31  * @author Nathan Fiedler
32  */

33 public class SchemaSettings {
34     /** Singleton instance of SchemaSettings */
35     private static SchemaSettings INSTANCE = new SchemaSettings();
36     /** Name of the connection timeout setting. */
37     public static final String JavaDoc PROP_VIEW_MODE = "viewMode";
38     /** Name of the user language selection setting. */
39     public static final String JavaDoc PROP_LANGUAGE = "language";
40
41     /**
42      * The view mode of the editor (e.g. tree, column).
43      */

44     public static enum ViewMode {
45         TREE, COLUMN
46     };
47
48     private SchemaSettings() {
49         setDefaults();
50     }
51     
52     public String JavaDoc displayName() {
53         return NbBundle.getMessage(SchemaSettings.class,
54                 "CTL_SchemaSettings_name");
55     }
56
57     /**
58      * Returns the single instance of this class.
59      *
60      * @return the instance.
61      */

62     public static SchemaSettings getDefault() {
63         return INSTANCE;
64     }
65
66     public HelpCtx getHelpCtx() {
67         return HelpCtx.DEFAULT_HELP;
68     }
69
70     /**
71      * Retrieves the view mode value.
72      *
73      * @return view mode.
74      */

75     public ViewMode getViewMode() {
76         String JavaDoc mode = (String JavaDoc) getProperty(PROP_VIEW_MODE);
77         if(mode == null)
78             return ViewMode.COLUMN;
79         
80         return ViewMode.valueOf(mode);
81     }
82
83     public void readExternal(ObjectInput JavaDoc in) throws
84             IOException JavaDoc, ClassNotFoundException JavaDoc {
85         //super.readExternal(in);
86
// Upgrade the restored instance to include the latest settings.
87
setDefaults();
88     }
89
90     /**
91      * For those properties that have null values, set them to the default.
92      */

93     private void setDefaults() {
94         if (getProperty(PROP_VIEW_MODE) == null) {
95             putProperty(PROP_VIEW_MODE, ViewMode.COLUMN.toString());
96         }
97     }
98
99     /**
100      * Sets the view mode value.
101      *
102      * @param mode new view mode value.
103      */

104     public void setViewMode(ViewMode mode) {
105         // Store the enum as a String.
106
putProperty(PROP_VIEW_MODE, mode.toString());
107     }
108
109     /**
110      * Retrieves the language.
111      *
112      * @return language as string.
113      */

114     public String JavaDoc getLanguage() {
115         return (String JavaDoc) getProperty(PROP_LANGUAGE);
116     }
117
118     /**
119      * Sets the language value.
120      *
121      * @param language new language value.
122      */

123     public void setLanguage(String JavaDoc language) {
124         // Store the enum as a String.
125
putProperty(PROP_LANGUAGE, language);
126     }
127     
128     protected final String JavaDoc putProperty(String JavaDoc key, String JavaDoc value) {
129         String JavaDoc retval = NbPreferences.forModule(SchemaSettings.class).get(key, null);
130         if (value != null) {
131             NbPreferences.forModule(SchemaSettings.class).put(key, value);
132         } else {
133             NbPreferences.forModule(SchemaSettings.class).remove(key);
134         }
135         return retval;
136     }
137     
138     protected final String JavaDoc getProperty(String JavaDoc key) {
139         return NbPreferences.forModule(SchemaSettings.class).get(key, ViewMode.COLUMN.toString());
140     }
141 }
142
Popular Tags