package com.MyCompany.examplebean;

import java.beans.*;
import java.awt.Image;

/**
 * The MyLineBeanInfo class provides information about the MyLine bean. It
 * extends java.beans.SimpleBeanInfo, which is a convenience class that
 * implements the java.beans.BeanInfo interface with empty methods. We just
 * override the interface methods we need.
 *
 * For this example, we implement two of the methods:
 * we have getIcon() so that builder tools can use the cute icon we created
 * for this class, and we have getPropertyDescriptors() that assigns the
 * PropertyEditor classes we wrote to their two propertie (Color and
 * Transparency).
 */ 
public class MyLineBeanInfo extends SimpleBeanInfo {
    private static PropertyDescriptor[] pdArray = null;

    // A builder tool calls getIcon to get the icon for a bean. It passes one
    // of the constants defined be the java.beans.BeanInfo interface to
    // identify the desired color depth and size for the icon. The MyLine bean
    // only supplies a color, 16 x 16 icon. It loads this image from the file
    // MyLineIconColor16.gif using the SimpleBeanInfo.loadImage() utility
    // method. The argument to loadImage should be a pathname that is
    // relative to the location of the current BeanInfo class.
    public Image getIcon(int iconKind) {
        if (iconKind == BeanInfo.ICON_COLOR_16x16) {
            return loadImage("MyLineIconColor16.gif");            
        }
        return null;
    }
    
    // Note that the PropertyDescriptor constructor used in the 
    // getPropertyDescriptors() method performs introspection on the specified
    // class to verify that the name really is a property, and to find its accessor
    // methods. If any of these PropertyDescriptors cannot be constructed, we
    // punt to the superclass to provide the default.
    public PropertyDescriptor[] getPropertyDescriptors() {
        if ( pdArray == null ) {
            try {
                pdArray = new PropertyDescriptor[] {
                    new PropertyDescriptor( "color", MyLine.class ),
                    new PropertyDescriptor( "transparency", MyLine.class ),
                    new PropertyDescriptor( "point_A", MyLine.class ),
                    new PropertyDescriptor( "point_B", MyLine.class ),
                    new PropertyDescriptor( "clickableDistance", MyLine.class )
                };
                
                // register the editor classes for those properties that have them
                pdArray[0].setPropertyEditorClass( MyLineColorEditor.class );
                pdArray[1].setPropertyEditorClass( MyLineTransparencyEditor.class );

            } catch ( IntrospectionException error ) {
                pdArray = super.getPropertyDescriptors();
            }
        }

        return pdArray;
    }
}
