FileDocCategorySizeDatePackage
YesNoPanelBeanInfo.javaAPI DocExample3162Sat Jan 24 10:44:38 GMT 2004je3.beans

YesNoPanelBeanInfo.java

/*
 * Copyright (c) 2004 David Flanagan.  All rights reserved.
 * This code is from the book Java Examples in a Nutshell, 3nd Edition.
 * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied.
 * You may study, use, and modify it for any non-commercial purpose,
 * including teaching and use in open-source projects.
 * You may distribute it non-commercially as long as you retain this notice.
 * For a commercial use license, or to purchase the book, 
 * please visit http://www.davidflanagan.com/javaexamples3.
 */
package je3.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;
	}
	catch(IntrospectionException e) { return null; } 
    }

    // Initialize a static array of PropertyDescriptor objects that provide
    // additional information about the properties supported by the bean.
    // By explicitly specifying property descriptors, we are able to provide
    // simple help strings for each property; these would not be available to
    // the beanbox through simple introspection.  We are also able to register
    // a special property editors for the messageText property
    static PropertyDescriptor[] props = {
	prop("messageText", "The message text that appears in the bean body"),
	prop("alignment", "The alignment of the message text"),
	prop("yesLabel", "The label for the Yes button"),
	prop("noLabel", "The label for the No button"),
	prop("cancelLabel","The label for the Cancel button"),
	prop("messageFont", "The font for the message"),
	prop("messageColor", "The color of the message text"),
	prop("buttonFont", "The font for the buttons"),
	prop("background", "The background color"),
    };
    static {
	props[0].setPropertyEditorClass(YesNoPanelMessageEditor.class);
    }
    
    /** Return the property descriptors for this bean */
    public PropertyDescriptor[] getPropertyDescriptors() { return props; }
    
    /** The message property is most often customized; make it the default */
    public int getDefaultPropertyIndex() { return 0; }
}