001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package com.sun.jsfcl.std;
042:
043: import java.util.HashMap;
044: import com.sun.jsfcl.util.ComponentBundle;
045: import com.sun.rave.designtime.CategoryDescriptor;
046:
047: public class PropCategories {
048:
049: private static final ComponentBundle bundle = ComponentBundle
050: .getBundle(PropCategories.class);
051:
052: protected static HashMap CategoryHash;
053:
054: public static final CategoryDescriptor GENERAL = new CategoryDescriptor(
055: bundle.getMessage("gen"), bundle.getMessage("genCatDesc"),
056: true); //NOI18N
057:
058: public static final CategoryDescriptor APPEARANCE = new CategoryDescriptor(
059: bundle.getMessage("appear"), bundle
060: .getMessage("appearCatDesc"), true); //NOI18N
061:
062: public static final CategoryDescriptor DATA = new CategoryDescriptor(
063: bundle.getMessage("data"),
064: bundle.getMessage("dataCatDesc"), true); //NOI18N
065:
066: public static final CategoryDescriptor EVENTS = new CategoryDescriptor(
067: bundle.getMessage("ev"), bundle.getMessage("evCatDesc"),
068: true); //NOI18N
069:
070: public static final CategoryDescriptor JAVASCRIPT = new CategoryDescriptor(
071: bundle.getMessage("js"), bundle.getMessage("jsCatDesc"),
072: false); //NOI18N
073:
074: public static final CategoryDescriptor ADVANCED = new CategoryDescriptor(
075: bundle.getMessage("adv"), bundle.getMessage("advCatDesc"),
076: false); //NOI18N
077:
078: public static final CategoryDescriptor INTERNAL = new CategoryDescriptor(
079: bundle.getMessage("intern"), bundle
080: .getMessage("internCatDesc"), false); //NOI18N
081:
082: static {
083: /*
084: * EAT: Although this code was more fun to write and provides for easy addition
085: * of constants, I did not feel that losing references to the variables was a good
086: * thing.
087: String[] descriptorFields = {
088: "GENERAL",
089: "APPEARANCE",
090: "DATA",
091: "EVENTS",
092: "JAVASCRIPT",
093: "ADVANCED",
094: "INTERNAL"
095: };
096: CategoryDescriptor category;
097:
098: CategoryHash = new HashMap();
099: for (int i=0; i < descriptorFields.length; i++) {
100: category = null;
101: try {
102: category = (CategoryDescriptor) PropCategories.class.getField(descriptorFields[i]).get(null);
103: } catch (Throwable e) {
104: throw new RuntimeException(e);
105: }
106: CategoryHash.put(category.getName(), new Object[] {descriptorFields[i], category});
107: }
108: */
109:
110: CategoryHash = new HashMap();
111: CategoryHash.put(GENERAL.getName().toLowerCase(), new Object[] {
112: "GENERAL", GENERAL }); //NOI18N
113: CategoryHash.put(APPEARANCE.getName().toLowerCase(),
114: new Object[] { "APPEARANCE", APPEARANCE }); //NOI18N
115: CategoryHash.put(DATA.getName().toLowerCase(), new Object[] {
116: "DATA", DATA }); //NOI18N
117: CategoryHash.put(EVENTS.getName().toLowerCase(), new Object[] {
118: "EVENTS", EVENTS }); //NOI18N
119: CategoryHash.put(JAVASCRIPT.getName().toLowerCase(),
120: new Object[] { "JAVASCRIPT", JAVASCRIPT }); //NOI18N
121: CategoryHash.put(ADVANCED.getName().toLowerCase(),
122: new Object[] { "ADVANCED", ADVANCED }); //NOI18N
123: CategoryHash.put(INTERNAL.getName().toLowerCase(),
124: new Object[] { "INTERNAL", INTERNAL }); //NOI18N
125: }
126:
127: public static CategoryDescriptor getCategoryDescriptor(
128: String categoryName) {
129: Object[] pair;
130:
131: if (categoryName == null) {
132: return null;
133: }
134: pair = (Object[]) CategoryHash.get(categoryName.toLowerCase());
135: if (pair == null) {
136: pair = new Object[] { null,
137: new CategoryDescriptor(categoryName, "") }; //NOI18N
138: CategoryHash.put(categoryName, pair);
139: }
140: return (CategoryDescriptor) pair[1];
141: }
142:
143: public static String getCategoryDescriptorConstantName(
144: String categoryName) {
145: Object[] pair;
146:
147: if (categoryName == null) {
148: return null;
149: }
150: pair = (Object[]) CategoryHash.get(categoryName.toLowerCase());
151: if (pair == null) {
152: return null;
153: }
154: return (String) pair[0];
155: }
156:
157: // craigmcc - Provide a default CategoryDescriptor[] for
158: // beaninfo classes for components that just want the
159: // standard categorization.
160: private static CategoryDescriptor defaultCategoryDescriptors[] = {
161: GENERAL, APPEARANCE, DATA, EVENTS, JAVASCRIPT, ADVANCED,
162: INTERNAL };
163:
164: public static CategoryDescriptor[] getDefaultCategoryDescriptors() {
165: return defaultCategoryDescriptors;
166: }
167:
168: }
|