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