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