KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > ui > nodes > elements > SourceOptions


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.ui.nodes.elements;
21
22 import org.openide.util.NbBundle;
23
24 /**
25 * These options determine the display name format
26 * of each kind of element.
27 * <p>Also included are read-only properties for the "long formats",
28 * which are in practice used for {@link ElementNode#getHintElementFormat}.
29 *
30 * @author Petr Hamernik
31 */

32 public final class SourceOptions {
33     /** Kinds of the format. */
34     private static final byte T_INITIALIZER = 0;
35     private static final byte T_FIELD = 1;
36     private static final byte T_CONSTRUCTOR = 2;
37     private static final byte T_METHOD = 3;
38     private static final byte T_CLASS = 4;
39     private static final byte T_INTERFACE = 5;
40     private static final byte T_ENUM = 6;
41     private static final byte T_CONSTANT = 7;
42     private static final byte T_ANNOTATION_TYPE = 8;
43     private static final byte T_ANNOTATION_TYPE_METHOD = 9;
44
45     /** Names of all properties. */
46     static final String JavaDoc[] PROP_NAMES = {
47         "initializerElementFormat", "fieldElementFormat", // NOI18N
48
"constructorElementFormat", "methodElementFormat", // NOI18N
49
"classElementFormat", "interfaceElementFormat", // NOI18N
50
"enumElementFormat", "constantElementFormat", // NOI18N
51
"annTypeElementFormat", "annTypeMethodElementFormat", // NOI18N
52
};
53     
54     /** default values for the formats - short form. */
55     private static final ElementFormat[] DEFAULT_FORMATS_SHORT = new ElementFormat[PROP_NAMES.length];
56
57     /** default values for the formats - long form. */
58     private static final ElementFormat[] DEFAULT_FORMATS_LONG = new ElementFormat[PROP_NAMES.length];
59     private static final SourceOptions INSTANCE = new SourceOptions();
60
61     private static void loadDefaultFormats() {
62         synchronized (SourceOptions.class) {
63             if (DEFAULT_FORMATS_SHORT[0] != null)
64                 return;
65             for (int i = 0; i < PROP_NAMES.length; i++) {
66                 DEFAULT_FORMATS_SHORT[i] = new ElementFormat(getString("SHORT_" + PROP_NAMES[i])); // NOI18N
67
DEFAULT_FORMATS_LONG[i] = new ElementFormat(getString("LONG_" + PROP_NAMES[i])); // NOI18N
68
}
69         }
70     }
71     
72     /** Property name of the initializer display format. */
73     public static final String JavaDoc PROP_INITIALIZER_FORMAT = PROP_NAMES[T_INITIALIZER];
74
75     /** Property name of the field display format. */
76     public static final String JavaDoc PROP_FIELD_FORMAT = PROP_NAMES[T_FIELD];
77
78     /** Property name of the constructor display format. */
79     public static final String JavaDoc PROP_CONSTRUCTOR_FORMAT = PROP_NAMES[T_CONSTRUCTOR];
80
81     /** Property name of the method display format. */
82     public static final String JavaDoc PROP_METHOD_FORMAT = PROP_NAMES[T_METHOD];
83
84     /** Property name of the class display format. */
85     public static final String JavaDoc PROP_CLASS_FORMAT = PROP_NAMES[T_CLASS];
86
87     /** Property name of the interface display format. */
88     public static final String JavaDoc PROP_INTERFACE_FORMAT = PROP_NAMES[T_INTERFACE];
89
90     /** Property name of the enum display format. */
91     public static final String JavaDoc PROP_ENUM_FORMAT = PROP_NAMES[T_ENUM];
92
93     /** Property name of the enum constant display format. */
94     public static final String JavaDoc PROP_CONSTANT_FORMAT = PROP_NAMES[T_CONSTANT];
95
96     /** Property name of the annotation type display format. */
97     public static final String JavaDoc PROP_ANNOTATION_TYPE_FORMAT = PROP_NAMES[T_ANNOTATION_TYPE];
98
99     /** Property name of the annotation type display format. */
100     public static final String JavaDoc PROP_ANNOTATION_TYPE_METHOD_FORMAT = PROP_NAMES[T_ANNOTATION_TYPE_METHOD];
101
102     /** Property name of the 'categories usage' property. */
103     public static final String JavaDoc PROP_CATEGORIES_USAGE = "categoriesUsage"; // NOI18N
104

105     /** CategoriesUsage property current value */
106     private static boolean categories = true;
107
108     static final long serialVersionUID = 1;
109     
110     private SourceOptions() {
111     }
112     
113     // ============= public methods ===================
114

115     public static SourceOptions getInstance() {
116         return INSTANCE;
117     }
118
119     /** Get the initializer format.
120     * @return the current format
121     */

122     public ElementFormat getInitializerElementFormat() {
123         return getElementFormat(T_INITIALIZER);
124     }
125
126     private ElementFormat getElementFormat(int type) {
127         loadDefaultFormats();
128         return DEFAULT_FORMATS_SHORT[type];
129     }
130
131     /** Get the field format.
132     * @return the current format
133     */

134     public ElementFormat getFieldElementFormat() {
135         return getElementFormat(T_FIELD);
136     }
137
138     /** Get the constructor format.
139     * @return the current format
140     */

141     public ElementFormat getConstructorElementFormat() {
142         return getElementFormat(T_CONSTRUCTOR);
143     }
144
145     /** Get the method format.
146     * @return the current format
147     */

148     public ElementFormat getMethodElementFormat() {
149         return getElementFormat(T_METHOD);
150     }
151
152     /** Get the class format.
153     * @return the current format
154     */

155     public ElementFormat getClassElementFormat() {
156         return getElementFormat(T_CLASS);
157     }
158
159     /** Get the interface format.
160     * @return the current format
161     */

162     public ElementFormat getInterfaceElementFormat() {
163         return getElementFormat(T_INTERFACE);
164     }
165
166     /** Get the enum format.
167     * @return the current format
168     */

169     public ElementFormat getEnumElementFormat() {
170         return getElementFormat(T_ENUM);
171     }
172
173     /** Get the enum constant format.
174     * @return the current format
175     */

176     public ElementFormat getConstantElementFormat() {
177         return getElementFormat(T_CONSTANT);
178     }
179
180     /** Get the annotation type format.
181     * @return the current format
182     */

183     public ElementFormat getAnnTypeElementFormat() {
184         return getElementFormat(T_ANNOTATION_TYPE);
185     }
186
187     /** Get the annotation type method format.
188     * @return the current format
189     */

190     public ElementFormat getAnnTypeMethodElementFormat() {
191         return getElementFormat(T_ANNOTATION_TYPE_METHOD);
192     }
193
194     // ============= getters for long form of formats =================
195

196     /** Get the initializer format for longer hints.
197     * @return the current format
198     */

199     public ElementFormat getInitializerElementLongFormat() {
200         loadDefaultFormats();
201         return DEFAULT_FORMATS_LONG[T_INITIALIZER];
202     }
203
204     /** Get the field format for longer hints.
205     * @return the current format
206     */

207     public ElementFormat getFieldElementLongFormat() {
208         loadDefaultFormats();
209         return DEFAULT_FORMATS_LONG[T_FIELD];
210     }
211
212     /** Get the constructor format for longer hints.
213     * @return the current format
214     */

215     public ElementFormat getConstructorElementLongFormat() {
216         loadDefaultFormats();
217         return DEFAULT_FORMATS_LONG[T_CONSTRUCTOR];
218     }
219
220     /** Get the method format for longer hints.
221     * @return the current format
222     */

223     public ElementFormat getMethodElementLongFormat() {
224         loadDefaultFormats();
225         return DEFAULT_FORMATS_LONG[T_METHOD];
226     }
227
228     /** Get the class format for longer hints.
229     * @return the current format
230     */

231     public ElementFormat getClassElementLongFormat() {
232         loadDefaultFormats();
233         return DEFAULT_FORMATS_LONG[T_CLASS];
234     }
235
236     /** Get the interface format for longer hints.
237     * @return the current format
238     */

239     public ElementFormat getInterfaceElementLongFormat() {
240         loadDefaultFormats();
241         return DEFAULT_FORMATS_LONG[T_INTERFACE];
242     }
243
244     /** Get the enum format for longer hints.
245     * @return the current format
246     */

247     public ElementFormat getEnumElementLongFormat() {
248         loadDefaultFormats();
249         return DEFAULT_FORMATS_LONG[T_ENUM];
250     }
251
252     /** Get the enum constant format for longer hints.
253     * @return the current format
254     */

255     public ElementFormat getConstantElementLongFormat() {
256         loadDefaultFormats();
257         return DEFAULT_FORMATS_LONG[T_CONSTANT];
258     }
259
260     /** Get the annotation type format for longer hints.
261     * @return the current format
262     */

263     public ElementFormat getAnnTypeElementLongFormat() {
264         loadDefaultFormats();
265         return DEFAULT_FORMATS_LONG[T_ANNOTATION_TYPE];
266     }
267
268     /** Get the annotation type method format for longer hints.
269     * @return the current format
270     */

271     public ElementFormat getAnnTypeMethodElementLongFormat() {
272         loadDefaultFormats();
273         return DEFAULT_FORMATS_LONG[T_ANNOTATION_TYPE_METHOD];
274     }
275     // ============= categories of elements usage ===================
276

277     /** Set the property whether categories under class elements should be used or not.
278     * @param cat if <CODE>true</CODE> the elements under class elements are divided into
279     * categories: fields, constructors, methods. Otherwise (<CODE>false</CODE>) all elements
280     * are placed directly under class element.
281     */

282     public void setCategoriesUsage(boolean cat) {
283         categories = cat;
284     }
285
286     /** Test whether categiries under class elements are used or not.
287     * @return <CODE>true</CODE> if the elements under class elements are divided into
288     * categories: fields, constructors, methods. Otherwise <CODE>false</CODE> (all elements
289     * are placed directly under class element).
290     */

291     public boolean getCategoriesUsage() {
292         return categories;
293     }
294
295     // ============= private methods ===================
296

297     private static String JavaDoc getString(String JavaDoc key) {
298         return NbBundle.getMessage(SourceOptions.class, key);
299     }
300 }
301
Popular Tags