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-2006 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 org.netbeans.modules.vmd.api.model.common;
042:
043: import org.netbeans.modules.vmd.api.model.TypeID;
044: import org.netbeans.modules.vmd.api.model.PropertyValue;
045: import org.openide.util.Utilities;
046:
047: import java.awt.*;
048: import java.util.HashMap;
049:
050: /**
051: * @author David Kaspar
052: */
053:
054: public final class TypesSupport {
055:
056: public static final TypeID TYPEID_INT = new TypeID(
057: TypeID.Kind.PRIMITIVE, "int"); // NOI18N
058: public static final TypeID TYPEID_LONG = new TypeID(
059: TypeID.Kind.PRIMITIVE, "long"); // NOI18N
060: public static final TypeID TYPEID_JAVA_LANG_STRING = new TypeID(
061: TypeID.Kind.PRIMITIVE, "java.lang.String"); // NOI18N
062: public static final TypeID TYPEID_BOOLEAN = new TypeID(
063: TypeID.Kind.PRIMITIVE, "boolean"); // NOI18N
064: public static final TypeID TYPEID_JAVA_CODE = new TypeID(
065: TypeID.Kind.PRIMITIVE, "#javacode"); // NOI18N
066: public static final TypeID TYPEID_ALERT_TYPE = new TypeID(
067: TypeID.Kind.ENUM, "javax.microedition.lcdui.AlertType"); // NOI18N
068:
069: public static enum AlertType {
070: ALARM, CONFIRMATION, ERROR, INFO, WARNING
071: }
072:
073: private static final HashMap<TypeID, Image> iconsRegister = new HashMap<TypeID, Image>();
074:
075: public static PropertyValue createBooleanValue(boolean value) {
076: return PropertyValue.createValue(
077: PrimitiveDescriptorSupport.booleanPD, TYPEID_BOOLEAN,
078: value);
079: }
080:
081: public static PropertyValue createStringValue(String stringValue) {
082: return PropertyValue.createValue(
083: PrimitiveDescriptorSupport.stringPD,
084: TYPEID_JAVA_LANG_STRING, stringValue);
085: }
086:
087: public static PropertyValue createIntegerValue(int intValue) {
088: return PropertyValue.createValue(
089: PrimitiveDescriptorSupport.intPD, TYPEID_INT, intValue);
090: }
091:
092: public static PropertyValue createLongValue(long longValue) {
093: return PropertyValue.createValue(
094: PrimitiveDescriptorSupport.longPD, TYPEID_LONG,
095: longValue);
096: }
097:
098: public static PropertyValue createJavaCodeValue(String javaCode) {
099: return PropertyValue.createValue(
100: PrimitiveDescriptorSupport.stringPD, TYPEID_JAVA_CODE,
101: javaCode);
102: }
103:
104: public static String getString(PropertyValue propertyValue) {
105: return (String) propertyValue.getPrimitiveValue();
106: }
107:
108: public static boolean getBoolean(PropertyValue propertyValue) {
109: return (Boolean) propertyValue.getPrimitiveValue();
110: }
111:
112: public static int getInteger(PropertyValue propertyValue) {
113: return (Integer) propertyValue.getPrimitiveValue();
114: }
115:
116: public static long getLong(PropertyValue propertyValue) {
117: return (Long) propertyValue.getPrimitiveValue();
118: }
119:
120: public static String getJavaCode(PropertyValue propertyValue) {
121: return (String) propertyValue.getPrimitiveValue();
122: }
123:
124: public static String getSimpleClassName(TypeID type) {
125: assert TypeID.Kind.COMPONENT.equals(type.getKind());
126: String string = type.getString();
127: int i = string.lastIndexOf('.');
128: return i >= 0 ? string.substring(i + 1) : string;
129: }
130:
131: public static void registerIconResource(TypeID typeID,
132: String iconResource) {
133: if (iconResource == null)
134: return;
135: iconsRegister.put(typeID, Utilities.loadImage(iconResource));
136: }
137:
138: public static void registerIcon(TypeID typeID, Image icon) {
139: iconsRegister.put(typeID, icon);
140: }
141:
142: public static Image getRegisteredIcon(TypeID typeID) {
143: return iconsRegister.get(typeID);
144: }
145:
146: }
|