1   package nl.tudelft.dsol.introspection.beans;
2   
3   import java.beans.EventSetDescriptor;
4   import java.beans.IndexedPropertyDescriptor;
5   import java.beans.IntrospectionException;
6   import java.beans.MethodDescriptor;
7   import java.beans.PropertyDescriptor;
8   import java.beans.SimpleBeanInfo;
9   
10  /***
11   * 
12   * <p>
13   * (c) copyright 2003-2004 <a href="http://www.simulation.tudelft.nl">Delft
14   * University of Technology </a>, the Netherlands. <br>
15   * See for project information <a
16   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
17   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
18   * License (GPL) </a>, no warranty <br>
19   * 
20   * @author <a
21   *         href="http://web.eur.nl/fbk/dep/dep1/Introduction/Staff/People/Lang">Niels
22   *         Lang </a><a
23   *         href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
24   *         Jacobs </a>
25   * @version 1.1 Apr 15, 2004
26   * @since 1.4
27   */
28  public class IndexedPropertyBeanBeanInfo extends SimpleBeanInfo
29  {
30  
31  	/*** Property identifiers //GEN-FIRST:Properties * */
32  	private static final int PROPERTY_beans = 0;
33  
34  	/*** Property identifiers Collection */
35  	private static final int PROPERTY_collection = 1;
36  
37  	/*** Property identifiers Vector */
38  	private static final int PROPERTY_vector = 2;
39  
40  	/*** Property identifiers Double */
41  	private static final int PROPERTY_doubleValue = 3;
42  
43  	/*** Property identifiers SerializableDouble */
44  	private static final int PROPERTY_serializedDoubleValue = 4;
45  
46  	/*** Property identifiers IndexedProperty */
47  	private static final int PROPERTY_indexedProp = 5;
48  
49  	/*** Property array */
50  	private static PropertyDescriptor[] properties = new PropertyDescriptor[6];
51  
52  	static
53  	{
54  		try
55  		{
56  			properties[PROPERTY_beans] = new PropertyDescriptor("beans",
57  					IndexedPropertyBean.class, "getBeans", "setBeans");
58  			properties[PROPERTY_collection] = new PropertyDescriptor(
59  					"collection", IndexedPropertyBean.class, "getCollection",
60  					"setCollection");
61  			properties[PROPERTY_vector] = new PropertyDescriptor("vector",
62  					IndexedPropertyBean.class, "getVector", "setVector");
63  			properties[PROPERTY_doubleValue] = new PropertyDescriptor(
64  					"doubleValue", IndexedPropertyBean.class, "getDoubleValue",
65  					"setDoubleValue");
66  			properties[PROPERTY_serializedDoubleValue] = new PropertyDescriptor(
67  					"serializedDoubleValue", IndexedPropertyBean.class,
68  					"getSerializedDoubleValue", "setSerializedDoubleValue");
69  			properties[PROPERTY_indexedProp] = new IndexedPropertyDescriptor(
70  					"indexedProp", IndexedPropertyBean.class, "getIndexedProp",
71  					"setIndexedProp", "getIndexedProp", "setIndexedProp");
72  		} catch (IntrospectionException e)
73  		{
74  			e.printStackTrace();
75  		} //GEN-HEADEREND:Properties
76  
77  		// Here you can add code for customizing the properties array.
78  
79  	} //GEN-LAST:Properties
80  
81  	// EventSet identifiers//GEN-FIRST:Events
82  
83  	/*** EventSet array */
84  	private static EventSetDescriptor[] eventSets = new EventSetDescriptor[0];
85  
86  	//GEN-HEADEREND:Events
87  
88  	// Here you can add code for customizing the event sets array.
89  
90  	//GEN-LAST:Events
91  
92  	// Method identifiers //GEN-FIRST:Methods
93  
94  	/*** Method array */
95  	private static MethodDescriptor[] methods = new MethodDescriptor[0];
96  
97  	//GEN-HEADEREND:Methods
98  
99  	// Here you can add code for customizing the methods array.
100 
101 	//GEN-LAST:Methods
102 
103 	/*** the iconColor */
104 	private static java.awt.Image iconColor16 = null; //GEN-BEGIN:IconsDef
105 
106 	/*** the iconColor */
107 	private static java.awt.Image iconColor32 = null;
108 
109 	/*** the iconColor */
110 	private static java.awt.Image iconMono16 = null;
111 
112 	/*** the iconColor */
113 	private static java.awt.Image iconMono32 = null; //GEN-END:IconsDef
114 
115 	/*** the iconName */
116 	private static String iconNameC16 = null; //GEN-BEGIN:Icons
117 
118 	/*** the iconName */
119 	private static String iconNameC32 = null;
120 
121 	/*** the iconName */
122 	private static String iconNameM16 = null;
123 
124 	/*** the iconName */
125 	private static String iconNameM32 = null; //GEN-END:Icons
126 
127 	/*** the iconName */
128 	private static int defaultPropertyIndex = -1; //GEN-BEGIN:Idx
129 
130 	/***
131 	 * Gets the bean's <code>PropertyDescriptor</code>s.
132 	 * 
133 	 * @return An array of PropertyDescriptors describing the editable
134 	 *         properties supported by this bean. May return null if the
135 	 *         information should be obtained by automatic analysis.
136 	 *         <p>
137 	 *         If a property is indexed, then its entry in the result array will
138 	 *         belong to the IndexedPropertyDescriptor subclass of
139 	 *         PropertyDescriptor. A client of getPropertyDescriptors can use
140 	 *         "instanceof" to check if a given PropertyDescriptor is an
141 	 *         IndexedPropertyDescriptor.
142 	 */
143 	public PropertyDescriptor[] getPropertyDescriptors()
144 	{
145 		return properties;
146 	}
147 
148 	/***
149 	 * Gets the bean's <code>EventSetDescriptor</code>s.
150 	 * 
151 	 * @return An array of EventSetDescriptors describing the kinds of events
152 	 *         fired by this bean. May return null if the information should be
153 	 *         obtained by automatic analysis.
154 	 */
155 	public EventSetDescriptor[] getEventSetDescriptors()
156 	{
157 		return eventSets;
158 	}
159 
160 	/***
161 	 * Gets the bean's <code>MethodDescriptor</code>s.
162 	 * 
163 	 * @return An array of MethodDescriptors describing the methods implemented
164 	 *         by this bean. May return null if the information should be
165 	 *         obtained by automatic analysis.
166 	 */
167 	public MethodDescriptor[] getMethodDescriptors()
168 	{
169 		return methods;
170 	}
171 
172 	/***
173 	 * A bean may have a "default" property that is the property that will
174 	 * mostly commonly be initially chosen for update by human's who are
175 	 * customizing the bean.
176 	 * 
177 	 * @return Index of default property in the PropertyDescriptor array
178 	 *         returned by getPropertyDescriptors.
179 	 *         <P>
180 	 *         Returns -1 if there is no default property.
181 	 */
182 	public int getDefaultPropertyIndex()
183 	{
184 		return defaultPropertyIndex;
185 	}
186 
187 	/***
188 	 * A bean may have a "default" event that is the event that will mostly
189 	 * commonly be used by human's when using the bean.
190 	 * 
191 	 * @return Index of default event in the EventSetDescriptor array returned
192 	 *         by getEventSetDescriptors.
193 	 *         <P>
194 	 *         Returns -1 if there is no default event.
195 	 */
196 	public int getDefaultEventIndex()
197 	{
198 		return defaultPropertyIndex;
199 	}
200 
201 	/***
202 	 * This method returns an image object that can be used to represent the
203 	 * bean in toolboxes, toolbars, etc. Icon images will typically be GIFs, but
204 	 * may in future include other formats.
205 	 * <p>
206 	 * Beans aren't required to provide icons and may return null from this
207 	 * method.
208 	 * <p>
209 	 * There are four possible flavors of icons (16x16 color, 32x32 color, 16x16
210 	 * mono, 32x32 mono). If a bean choses to only support a single icon we
211 	 * recommend supporting 16x16 color.
212 	 * <p>
213 	 * We recommend that icons have a "transparent" background so they can be
214 	 * rendered onto an existing background.
215 	 * 
216 	 * @param iconKind The kind of icon requested. This should be one of the
217 	 *        constant values ICON_COLOR_16x16, ICON_COLOR_32x32,
218 	 *        ICON_MONO_16x16, or ICON_MONO_32x32.
219 	 * @return An image object representing the requested icon. May return null
220 	 *         if no suitable icon is available.
221 	 */
222 	public java.awt.Image getIcon(final int iconKind)
223 	{
224 		switch (iconKind)
225 		{
226 			case ICON_COLOR_16x16 :
227 				if (iconNameC16 == null)
228 				{
229 					return null;
230 				}
231 				if (iconColor16 == null)
232 				{
233 					iconColor16 = loadImage(iconNameC16);
234 				}
235 				return iconColor16;
236 			case ICON_COLOR_32x32 :
237 				if (iconNameC32 == null)
238 				{
239 					return null;
240 				}
241 				if (iconColor32 == null)
242 				{
243 					iconColor32 = loadImage(iconNameC32);
244 				}
245 				return iconColor32;
246 			case ICON_MONO_16x16 :
247 				if (iconNameM16 == null)
248 				{
249 					return null;
250 				}
251 				if (iconMono16 == null)
252 				{
253 					iconMono16 = loadImage(iconNameM16);
254 				}
255 				return iconMono16;
256 			case ICON_MONO_32x32 :
257 				if (iconNameM32 == null)
258 				{
259 					return null;
260 				}
261 				if (iconNameM32 == null)
262 				{
263 					iconMono32 = loadImage(iconNameM32);
264 				}
265 				return iconMono32;
266 			default :
267 				return null;
268 		}
269 	}
270 }