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