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