ExplicitButton Color-Annotated Source


ExplicitButton is the same code as OurButton:

public class ExplicitButton extends OurButton{
}

ExplicitButton, however, has a BeanInfo class associated with it which is used to explicitly tell the BeanBox (or other visual environment) which properties to expose in the editor and which events ExplicitButton supports.



import java.beans.*;


/**
 * BeanInfo for an ExplicitButton.
 * 
 * @see sunw.demo.buttons.ExplicitButton
 */
public class ExplicitButtonBeanInfo extends SimpleBeanInfo {

// each property descriptor returned in the array will show in the
// property editor.
    public PropertyDescriptor[] getPropertyDescriptors() {
        try {
	//construct a property descriptor for each property. This constructor
	//works for properties that follow the standard get/set property
	//convention. The first argument is the programmatic name of the 
	//property. Always use lower case for this name; it will be changed to
	//uppercase: i.e."background" becomes "getBackground".
            PropertyDescriptor background =
			new PropertyDescriptor("background", beanClass);
	    PropertyDescriptor foreground =
			new PropertyDescriptor("foreground", beanClass);
	    PropertyDescriptor font =
			new PropertyDescriptor("font", beanClass);
            PropertyDescriptor label =
			new PropertyDescriptor("label", beanClass);

	//indicate that updates to these properties will fire a PropertyChangeEvent
            background.setBound(true);
            foreground.setBound(true);
            font.setBound(true);
            label.setBound(true);

            PropertyDescriptor rv[] = {background, foreground, font, label};
            return rv;
        } catch (IntrospectionException e) {
            throw new Error(e.toString());
        }
    }

    public int getDefaultPropertyIndex() {
	// the index for the "label" property
        return 3; 
    }


// each event set descriptor returned in the array will display as a 
// supported event.
    public EventSetDescriptor[] getEventSetDescriptors() {
        try {
            EventSetDescriptor push = new EventSetDescriptor(beanClass, 
	                "actionPerformed",
			java.awt.event.ActionListener.class,
			"actionPerformed");

            EventSetDescriptor changed = new EventSetDescriptor(beanClass,
			"propertyChange",
			java.beans.PropertyChangeListener.class,
			"propertyChange");

            push.setDisplayName("button push");
            changed.setDisplayName("bound property change");
	
            EventSetDescriptor[] rv = { push, changed};
            return rv;
        } catch (IntrospectionException e) {
            throw new Error(e.toString());
        }
    }

    public BeanDescriptor getBeanDescriptor() {
        return new BeanDescriptor(beanClass, customizerClass);
    }

    public java.awt.Image getIcon(int iconKind) {
	if (iconKind == BeanInfo.ICON_MONO_16x16 ||
	    iconKind == BeanInfo.ICON_COLOR_16x16 ) {
	    java.awt.Image img = loadImage("ExplicitButtonIcon16.gif");
	    return img;
	}
	if (iconKind == BeanInfo.ICON_MONO_32x32 ||
	    iconKind == BeanInfo.ICON_COLOR_32x32 ) {
	    java.awt.Image img = loadImage("ExplicitButtonIcon32.gif");
	    return img;
	}
	return null;
    }

    private final static Class beanClass = ExplicitButton.class;
    private final static Class customizerClass = OurButtonCustomizer.class;
}

Java, JavaBeans, and JavaSoft are trademarks of Sun Microsystems Inc.

Copyright © 1996 Sun Microsystems, Inc., 2550 Garcia Ave., Mtn. View, CA 94043-1100 USA.
All rights reserved.