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