View Javadoc
1 package org.johndavidtaylor.beans.beanpeeler; 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 public class TestBeanBeanInfo extends SimpleBeanInfo { 10 11 // Property identifiers //GEN-FIRST:Properties 12 private static final int PROPERTY_background = 0; 13 private static final int PROPERTY_text = 1; 14 private static final int PROPERTY_foreground = 2; 15 private static final int PROPERTY_font = 3; 16 17 // Property array 18 private static PropertyDescriptor[] properties = new PropertyDescriptor[4]; 19 20 static { 21 try { 22 properties[PROPERTY_background] = new PropertyDescriptor ( "background", TestBean.class, "getBackground", "setBackground" ); 23 properties[PROPERTY_text] = new PropertyDescriptor ( "text", TestBean.class, "getText", "setText" ); 24 properties[PROPERTY_foreground] = new PropertyDescriptor ( "foreground", TestBean.class, "getForeground", "setForeground" ); 25 properties[PROPERTY_font] = new PropertyDescriptor ( "font", TestBean.class, "getFont", "setFont" ); 26 } 27 catch( IntrospectionException e) {}//GEN-HEADEREND:Properties 28 29 // Here you can add code for customizing the properties array. 30 31 }//GEN-LAST:Properties 32 33 // EventSet identifiers//GEN-FIRST:Events 34 35 // EventSet array 36 private static EventSetDescriptor[] eventSets = new EventSetDescriptor[0]; 37 //GEN-HEADEREND:Events 38 39 // Here you can add code for customizing the event sets array. 40 41 //GEN-LAST:Events 42 43 // Method identifiers //GEN-FIRST:Methods 44 45 // Method array 46 private static MethodDescriptor[] methods = new MethodDescriptor[0]; 47 //GEN-HEADEREND:Methods 48 49 // Here you can add code for customizing the methods array. 50 51 //GEN-LAST:Methods 52 53 private static java.awt.Image iconColor16 = null; //GEN-BEGIN:IconsDef 54 private static java.awt.Image iconColor32 = null; 55 private static java.awt.Image iconMono16 = null; 56 private static java.awt.Image iconMono32 = null; //GEN-END:IconsDef 57 private static String iconNameC16 = null;//GEN-BEGIN:Icons 58 private static String iconNameC32 = null; 59 private static String iconNameM16 = null; 60 private static String iconNameM32 = null;//GEN-END:Icons 61 62 private static int defaultPropertyIndex = -1;//GEN-BEGIN:Idx 63 private static int defaultEventIndex = -1;//GEN-END:Idx 64 65 66 /*** 67 * Gets the bean's <code>PropertyDescriptor</code>s. 68 * 69 * @return An array of PropertyDescriptors describing the editable 70 * properties supported by this bean. May return null if the 71 * information should be obtained by automatic analysis. 72 * <p> 73 * If a property is indexed, then its entry in the result array will 74 * belong to the IndexedPropertyDescriptor subclass of PropertyDescriptor. 75 * A client of getPropertyDescriptors can use "instanceof" to check 76 * if a given PropertyDescriptor is an IndexedPropertyDescriptor. 77 */ 78 public PropertyDescriptor[] getPropertyDescriptors() { 79 return properties; 80 } 81 82 /*** 83 * Gets the bean's <code>EventSetDescriptor</code>s. 84 * 85 * @return An array of EventSetDescriptors describing the kinds of 86 * events fired by this bean. May return null if the information 87 * should be obtained by automatic analysis. 88 */ 89 public EventSetDescriptor[] getEventSetDescriptors() { 90 return eventSets; 91 } 92 93 /*** 94 * Gets the bean's <code>MethodDescriptor</code>s. 95 * 96 * @return An array of MethodDescriptors describing the methods 97 * implemented by this bean. May return null if the information 98 * should be obtained by automatic analysis. 99 */ 100 public MethodDescriptor[] getMethodDescriptors() { 101 return methods; 102 } 103 104 /*** 105 * A bean may have a "default" property that is the property that will 106 * mostly commonly be initially chosen for update by human's who are 107 * customizing the bean. 108 * @return Index of default property in the PropertyDescriptor array 109 * returned by getPropertyDescriptors. 110 * <P> Returns -1 if there is no default property. 111 */ 112 public int getDefaultPropertyIndex() { 113 return defaultPropertyIndex; 114 } 115 116 /*** 117 * A bean may have a "default" event that is the event that will 118 * mostly commonly be used by human's when using the bean. 119 * @return Index of default event in the EventSetDescriptor array 120 * returned by getEventSetDescriptors. 121 * <P> Returns -1 if there is no default event. 122 */ 123 public int getDefaultEventIndex() { 124 return defaultPropertyIndex; 125 } 126 127 /*** 128 * This method returns an image object that can be used to 129 * represent the bean in toolboxes, toolbars, etc. Icon images 130 * will typically be GIFs, but may in future include other formats. 131 * <p> 132 * Beans aren't required to provide icons and may return null from 133 * this method. 134 * <p> 135 * There are four possible flavors of icons (16x16 color, 136 * 32x32 color, 16x16 mono, 32x32 mono). If a bean choses to only 137 * support a single icon we recommend supporting 16x16 color. 138 * <p> 139 * We recommend that icons have a "transparent" background 140 * so they can be rendered onto an existing background. 141 * 142 * @param iconKind The kind of icon requested. This should be 143 * one of the constant values ICON_COLOR_16x16, ICON_COLOR_32x32, 144 * ICON_MONO_16x16, or ICON_MONO_32x32. 145 * @return An image object representing the requested icon. May 146 * return null if no suitable icon is available. 147 */ 148 public java.awt.Image getIcon(int iconKind) { 149 switch ( iconKind ) { 150 case ICON_COLOR_16x16: 151 if ( iconNameC16 == null ) 152 return null; 153 else { 154 if( iconColor16 == null ) 155 iconColor16 = loadImage( iconNameC16 ); 156 return iconColor16; 157 } 158 case ICON_COLOR_32x32: 159 if ( iconNameC32 == null ) 160 return null; 161 else { 162 if( iconColor32 == null ) 163 iconColor32 = loadImage( iconNameC32 ); 164 return iconColor32; 165 } 166 case ICON_MONO_16x16: 167 if ( iconNameM16 == null ) 168 return null; 169 else { 170 if( iconMono16 == null ) 171 iconMono16 = loadImage( iconNameM16 ); 172 return iconMono16; 173 } 174 case ICON_MONO_32x32: 175 if ( iconNameM32 == null ) 176 return null; 177 else { 178 if( iconNameM32 == null ) 179 iconMono32 = loadImage( iconNameM32 ); 180 return iconMono32; 181 } 182 } 183 return null; 184 } 185 186 } 187

This page was automatically generated by Maven