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 SubTestBeanBeanInfo extends SimpleBeanInfo
27 {
28
29
30 private static final int PROPERTY_font = 0;
31
32 private static final int PROPERTY_secondProperty = 1;
33
34 private static final int PROPERTY_firstProperty = 2;
35
36 private static final int PROPERTY_color = 3;
37
38 private static final int PROPERTY_intProp = 4;
39
40
41 private static PropertyDescriptor[] properties = new PropertyDescriptor[5];
42
43 static
44 {
45 try
46 {
47 properties[PROPERTY_font] = new PropertyDescriptor("font",
48 SubTestBean.class, "getFont", "setFont");
49 properties[PROPERTY_secondProperty] = new PropertyDescriptor(
50 "secondProperty", SubTestBean.class, "getSecondProperty",
51 "setSecondProperty");
52 properties[PROPERTY_firstProperty] = new PropertyDescriptor(
53 "firstProperty", SubTestBean.class, "getFirstProperty",
54 "setFirstProperty");
55 properties[PROPERTY_color] = new PropertyDescriptor("color",
56 SubTestBean.class, "getColor", "setColor");
57 properties[PROPERTY_intProp] = new PropertyDescriptor("intProp",
58 SubTestBean.class, "getIntProp", "setIntProp");
59 } catch (IntrospectionException e)
60 {
61 e.printStackTrace();
62 }
63
64
65
66 }
67
68
69
70
71 private static EventSetDescriptor[] eventSets = new EventSetDescriptor[0];
72
73
74
75
76
77
78
79
80
81
82 private static MethodDescriptor[] methods = new MethodDescriptor[0];
83
84
85
86
87
88
89
90 private static java.awt.Image iconColor16 = null;
91
92 private static java.awt.Image iconColor32 = null;
93
94 private static java.awt.Image iconMono16 = null;
95
96 private static java.awt.Image iconMono32 = null;
97
98 private static String iconNameC16 = null;
99
100 private static String iconNameC32 = null;
101
102 private static String iconNameM16 = null;
103
104 private static String iconNameM32 = null;
105
106 private static int defaultPropertyIndex = -1;
107
108
109 /***
110 * Gets the bean's <code>PropertyDescriptor</code>s.
111 *
112 * @return An array of PropertyDescriptors describing the editable
113 * properties supported by this bean. May return null if the
114 * information should be obtained by automatic analysis.
115 * <p>
116 * If a property is indexed, then its entry in the result array will
117 * belong to the IndexedPropertyDescriptor subclass of
118 * PropertyDescriptor. A client of getPropertyDescriptors can use
119 * "instanceof" to check if a given PropertyDescriptor is an
120 * IndexedPropertyDescriptor.
121 */
122 public PropertyDescriptor[] getPropertyDescriptors()
123 {
124 return properties;
125 }
126
127 /***
128 * Gets the bean's <code>EventSetDescriptor</code>s.
129 *
130 * @return An array of EventSetDescriptors describing the kinds of events
131 * fired by this bean. May return null if the information should be
132 * obtained by automatic analysis.
133 */
134 public EventSetDescriptor[] getEventSetDescriptors()
135 {
136 return eventSets;
137 }
138
139 /***
140 * Gets the bean's <code>MethodDescriptor</code>s.
141 *
142 * @return An array of MethodDescriptors describing the methods implemented
143 * by this bean. May return null if the information should be
144 * obtained by automatic analysis.
145 */
146 public MethodDescriptor[] getMethodDescriptors()
147 {
148 return methods;
149 }
150
151 /***
152 * A bean may have a "default" property that is the property that will
153 * mostly commonly be initially chosen for update by human's who are
154 * customizing the bean.
155 *
156 * @return Index of default property in the PropertyDescriptor array
157 * returned by getPropertyDescriptors.
158 * <P>
159 * Returns -1 if there is no default property.
160 */
161 public int getDefaultPropertyIndex()
162 {
163 return defaultPropertyIndex;
164 }
165
166 /***
167 * A bean may have a "default" event that is the event that will mostly
168 * commonly be used by human's when using the bean.
169 *
170 * @return Index of default event in the EventSetDescriptor array returned
171 * by getEventSetDescriptors.
172 * <P>
173 * Returns -1 if there is no default event.
174 */
175 public int getDefaultEventIndex()
176 {
177 return defaultPropertyIndex;
178 }
179
180 /***
181 * This method returns an image object that can be used to represent the
182 * bean in toolboxes, toolbars, etc. Icon images will typically be GIFs, but
183 * may in future include other formats.
184 * <p>
185 * Beans aren't required to provide icons and may return null from this
186 * method.
187 * <p>
188 * There are four possible flavors of icons (16x16 color, 32x32 color, 16x16
189 * mono, 32x32 mono). If a bean choses to only support a single icon we
190 * recommend supporting 16x16 color.
191 * <p>
192 * We recommend that icons have a "transparent" background so they can be
193 * rendered onto an existing background.
194 *
195 * @param iconKind The kind of icon requested. This should be one of the
196 * constant values ICON_COLOR_16x16, ICON_COLOR_32x32,
197 * ICON_MONO_16x16, or ICON_MONO_32x32.
198 * @return An image object representing the requested icon. May return null
199 * if no suitable icon is available.
200 */
201 public java.awt.Image getIcon(int iconKind)
202 {
203 switch (iconKind)
204 {
205 case ICON_COLOR_16x16 :
206 if (iconNameC16 == null)
207 {
208 return null;
209 }
210
211 if (iconColor16 == null)
212 {
213 iconColor16 = loadImage(iconNameC16);
214 }
215 return iconColor16;
216
217 case ICON_COLOR_32x32 :
218 if (iconNameC32 == null)
219 {
220 return null;
221 }
222
223 if (iconColor32 == null)
224 {
225 iconColor32 = loadImage(iconNameC32);
226 }
227 return iconColor32;
228
229 case ICON_MONO_16x16 :
230 if (iconNameM16 == null)
231 {
232 return null;
233 }
234
235 if (iconMono16 == null)
236 {
237 iconMono16 = loadImage(iconNameM16);
238 }
239 return iconMono16;
240
241 case ICON_MONO_32x32 :
242 if (iconNameM32 == null)
243 {
244 return null;
245 }
246
247 if (iconNameM32 == null)
248 {
249 iconMono32 = loadImage(iconNameM32);
250 }
251 return iconMono32;
252 }
253
254 return null;
255 }
256
257 }
258