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 org.netbeans.modules.visualweb.faces.dt;
042:
043: import java.awt.Image;
044: import java.beans.BeanDescriptor;
045: import java.beans.EventSetDescriptor;
046: import java.beans.MethodDescriptor;
047: import java.beans.PropertyDescriptor;
048: import java.beans.SimpleBeanInfo;
049:
050: public abstract class HtmlBeanInfoBase extends SimpleBeanInfo {
051:
052: // The bean class
053: protected Class beanClass;
054: // The default property name
055: protected String defaultPropertyName;
056: // The 16x16 color icon
057: protected String iconFileName_C16;
058: // The 32x32 color icon
059: protected String iconFileName_C32;
060: // The 16x16 monochrome icon
061: protected String iconFileName_M16;
062: // The 32x32 monochrome icon
063: protected String iconFileName_M32;
064:
065: private PropertyDescriptor[] propertyDescriptors = new PropertyDescriptor[0];
066:
067: public PropertyDescriptor[] getPropertyDescriptors() {
068: return this .propertyDescriptors;
069: }
070:
071: private EventSetDescriptor[] eventSetDescriptors = new EventSetDescriptor[0];
072:
073: public EventSetDescriptor[] getEventSetDescriptors() {
074: return this .eventSetDescriptors;
075: }
076:
077: private int defaultPropertyIndex = -2;
078:
079: public int getDefaultPropertyIndex() {
080: if (defaultPropertyIndex == -2) {
081: if (defaultPropertyName == null) {
082: defaultPropertyIndex = -1;
083: } else {
084: PropertyDescriptor[] propertyDescriptors = this
085: .getPropertyDescriptors();
086: for (int i = 0; i < propertyDescriptors.length
087: && defaultPropertyIndex == -2; i++) {
088: if (defaultPropertyName
089: .equals(propertyDescriptors[i].getName()))
090: defaultPropertyIndex = i;
091: }
092: }
093: }
094: return defaultPropertyIndex;
095: }
096:
097: public Image getIcon(int iconKind) {
098: String name;
099: switch (iconKind) {
100: case ICON_COLOR_16x16:
101: name = iconFileName_C16;
102: break;
103: case ICON_COLOR_32x32:
104: name = iconFileName_C32;
105: break;
106: case ICON_MONO_16x16:
107: name = iconFileName_M16;
108: break;
109: case ICON_MONO_32x32:
110: name = iconFileName_M32;
111: break;
112: default:
113: name = null;
114: }
115: if (name != null) {
116: Image im = loadImage(name + ".png"); //NOI18N
117: if (im == null) {
118: im = loadImage(name + ".gif"); //NOI18N
119: }
120: return im;
121: }
122: return null;
123: }
124:
125: /**
126: * Returns the property descriptor for the property name specified, or null
127: * if this bean has no such property.
128: */
129: protected PropertyDescriptor getPropertyDescriptor(String propName) {
130: PropertyDescriptor[] propertyDescriptors = this
131: .getPropertyDescriptors();
132: if (propertyDescriptors != null) {
133: for (int i = 0; i < propertyDescriptors.length; i++) {
134: if (propertyDescriptors[i].getName().equals(propName)) {
135: return propertyDescriptors[i];
136: }
137: }
138: }
139: return null;
140: }
141:
142: /**
143: * Loads and returns a class instance corresponding to the fully-qualified
144: * name specified, using the class loader used to load this class.
145: */
146: protected Class loadClass(String name) {
147: try {
148: return Class.forName(name);
149: } catch (ClassNotFoundException e) {
150: throw new RuntimeException(e);
151: }
152: }
153:
154: }
|