Java Reference
In-Depth Information
This BeanInfo class specifies a number of pieces of information for our bean:
An icon that represents the bean.
•A BeanDescriptor object, which includes a reference to a Customizer class
for the bean. We'll see an implementation of this class later in the chapter.
A list of the supported properties of the bean, along with a short description
of each one. Some beanbox tools (but not Sun's beanbox ) display these
strings to the user in some useful way.
A method that returns the most commonly customized property of the bean;
this is called the “default” property.
A reference to a PropertyEditor class for one of the properties. We'll see the
implementation of this property editor class later in the chapter.
Besides specifying this information, a BeanInfo class can also provide information
about the methods it defines and the events it generates. The various Feature-
Descriptor objects that provide information about such things as properties and
methods can also include other information not provided by YesNoPanelBeanInfo ,
such as a localized display name that is distinct from the programmatic name.
Example 14−6: YesNoPanelBeanInfo.java
package com.davidflanagan.examples.beans;
import java.beans.*;
import java.lang.reflect.*;
import java.awt.*;
/**
* This BeanInfo class provides additional information about the YesNoPanel
* bean in addition to what can be obtained through introspection alone.
**/
public class YesNoPanelBeanInfo extends SimpleBeanInfo {
/**
* Return an icon for the bean. We should really check the kind argument
* to see what size icon the beanbox wants, but since we only have one
* icon to offer, we just return it and let the beanbox deal with it
**/
public Image getIcon(int kind) { return loadImage("YesNoPanelIcon.gif"); }
/**
* Return a descriptor for the bean itself. It specifies a customizer
* for the bean class. We could also add a description string here
**/
public BeanDescriptor getBeanDescriptor() {
return new BeanDescriptor(YesNoPanel.class,
YesNoPanelCustomizer.class);
}
/** This is a convenience method for creating PropertyDescriptor objects */
static PropertyDescriptor prop(String name, String description) {
try {
PropertyDescriptor p =
new PropertyDescriptor(name, YesNoPanel.class);
p.setShortDescription(description);
return p;
}
Search WWH ::




Custom Search