/** * SunSphereBeanInfo provides introspection support for JavaBeans and AppleScript. * * Copyright &copy; 1996-1998 Martin Minow. All Rights Reserved.<p> * * Permission to use, copy, modify, and redistribute this software and its * documentation for personal, non-commercial use is hereby granted provided that * this copyright notice and appropriate documentation appears in all copies. This * software may not be distributed for fee or as part of commercial, "shareware," * and/or not-for-profit endevors including, but not limited to, CD-ROM collections, * online databases, and subscription services without specific license.<p> * * @author <a href="mailto:minow@pobox.com">Martin Minow</a> * @version 1.0 * Set tabs every 8 characters. */package org.minow.applets.sunsphere;import java.beans.*;import java.lang.reflect.*;public class SunSphereBeanInfo extends SimpleBeanInfo{    /**     * Gets the BeanDescriptor for this bean.     * @return an object of type BeanDescriptor     */    public BeanDescriptor getBeanDescriptor() {	BeanDescriptor bd = new BeanDescriptor(SunSphere.class, null);	/*	 * Add a better description of the applet than just "it's an applet."	 */	bd.setShortDescription(SunSphere.aboutSunSphere);	return bd;    }    /**     * Specify specific methods to the Java Bean user.     */    public MethodDescriptor[] getMethodDescriptors()    {	try {	    /*	     * Provide a rotation method. Note that the strings are taken	     * from SunSphere.java to isolate text that will eventually	     * be localized.	     */	    MethodDescriptor[] methodDescs = new MethodDescriptor[1];	    ParameterDescriptor parm = new ParameterDescriptor();	    parm.setName(SunSphere.nRotate);	    parm.setShortDescription(SunSphere.dRotate);	    ParameterDescriptor[] parms = {parm};	    Class[] types = {Double.TYPE};	    methodDescs[0] = new MethodDescriptor(	    	    SunSphere.class.getMethod("rotate", types),		    parms		);							;	    return (methodDescs);	} catch (Exception ex) {	    return (super.getMethodDescriptors());	}    }    /**     * Return a BeanInfo for the superclass of this bean.     * @return BeanInfo[] containing this bean's superclass BeanInfo     */    public BeanInfo[] getAdditionalBeanInfo() {	try {	    BeanInfo[] bi = new BeanInfo[1];	    bi[0] = Introspector.getBeanInfo(SunSphere.class.getSuperclass());	    return bi;	}	catch (IntrospectionException e) {	    throw new Error(e.toString());	}    }    /**    * Return an image that may be used to visually represent this bean    * (in the toolbar, on a form, etc).    * @param iconKind the type of icon desired, one of: BeanInfo.ICON_MONO_16x16,    * BeanInfo.ICON_COLOR_16x16, BeanInfo.ICON_MONO_32x32, or BeanInfo.ICON_COLOR_32x32.    * @return an image for this bean    * @see BeanInfo#ICON_MONO_16x16    * @see BeanInfo#ICON_COLOR_16x16    * @see BeanInfo#ICON_MONO_32x32    * @see BeanInfo#ICON_COLOR_32x32    */    public java.awt.Image getIcon(int iconKind) {	java.awt.Image image	= null;	if (iconKind == BeanInfo.ICON_COLOR_16x16) {	    image		= loadImage("SunSphereC16.gif");	}	if (iconKind == BeanInfo.ICON_COLOR_32x32) {	    image		= loadImage("SunSphereC32.gif");	}	return (image);    };    /**     * Return descriptions of this bean's properties.     */    private PropertyDescriptor makePropertyDescriptor(	    String	propertyName,	    String	displayName,	    String	shortDescription	)	    throws IntrospectionException    {    	PropertyDescriptor	desc = new PropertyDescriptor(    		propertyName,    		SunSphere.class    	    );    	desc.setDisplayName(displayName);    	desc.setShortDescription(shortDescription);    	return (desc);    }    public PropertyDescriptor[] getPropertyDescriptors() {	try{	    PropertyDescriptor descBackgroundColor = makePropertyDescriptor(	    		SunSphere.pBackgroundColor,	    		SunSphere.nBackgroundColor,	    		SunSphere.dBackgroundColor	    	   );	    PropertyDescriptor descTextColor = makePropertyDescriptor(	    		SunSphere.pTextColor,	    		SunSphere.nTextColor,	    		SunSphere.dTextColor	    	   );	    PropertyDescriptor descAutostart = makePropertyDescriptor(	    		SunSphere.pAutostart,	    		SunSphere.nAutostart,	    		SunSphere.dAutostart	    	   );	    PropertyDescriptor descSpinInterval = makePropertyDescriptor(	    		SunSphere.pSpinInterval,	    		SunSphere.nSpinInterval,	    		SunSphere.dSpinInterval	    	   );	    PropertyDescriptor descDate = makePropertyDescriptor(	    		SunSphere.pDate,	    		SunSphere.nDate,	    		SunSphere.dDate	    	   );	    PropertyDescriptor descLocation = makePropertyDescriptor(	    		SunSphere.pLocation,	    		SunSphere.nLocation,	    		SunSphere.dLocation	    	   );	    /* */	    PropertyDescriptor descLongitude = makePropertyDescriptor(	    		SunSphere.pLongitude,	    		SunSphere.nLongitude,	    		SunSphere.dLongitude	    	   );	    PropertyDescriptor descLongitudeDelta = makePropertyDescriptor(	    		SunSphere.pLongitudeDelta,	    		SunSphere.nLongitudeDelta,	    		SunSphere.dLongitudeDelta	    	   );	    PropertyDescriptor descLongitudeSpin = makePropertyDescriptor(	    		SunSphere.pLongitudeSpin,	    		SunSphere.nLongitudeSpin,	    		SunSphere.dLongitudeSpin	    	   );	    PropertyDescriptor descLatitude = makePropertyDescriptor(	    		SunSphere.pLatitude,	    		SunSphere.nLatitude,	    		SunSphere.dLatitude	    	   );	    PropertyDescriptor descLatitudeDelta = makePropertyDescriptor(	    		SunSphere.pLatitudeDelta,	    		SunSphere.nLatitudeDelta,	    		SunSphere.dLatitudeDelta	    	   );	    PropertyDescriptor descLatitudeSpin = makePropertyDescriptor(	    		SunSphere.pLatitudeSpin,	    		SunSphere.nLatitudeSpin,	    		SunSphere.dLatitudeSpin	    	   );	    /*	     * These are boolean parameters. We need a different	     * constructor to avoid an exception. Umm, my reading of	     * the PropertyDescriptor constructor suggests that this	     * shouldn't be necessary, but you never can tell.	     */	    PropertyDescriptor	descSpinning = new PropertyDescriptor(	    	    SunSphere.pSpinning,    		    SunSphere.class,    		    "isSpinning",    		    "setSpinning"		);	    descSpinning.setDisplayName(SunSphere.nSpinning);	    descSpinning.setDisplayName(SunSphere.dSpinning);	    PropertyDescriptor	descLatitudeGrab = new PropertyDescriptor(	    	    SunSphere.pLatitudeGrab,    		    SunSphere.class,    		    "isLatitudeGrabOK",    		    "setLatitudeGrabOK"		);	    descSpinning.setDisplayName(SunSphere.nLatitudeGrab);	    descSpinning.setDisplayName(SunSphere.dLatitudeGrab);	    /* */	    PropertyDescriptor[] result = {		descBackgroundColor,		descTextColor,		descAutostart,		descSpinInterval,		descSpinning,		descDate,		descLocation,		descLongitude, descLongitudeDelta, descLongitudeSpin,		descLatitude,  descLatitudeDelta,  descLatitudeSpin,		descLatitudeGrab,	    };	    return (result);	}	catch (IntrospectionException e) {	    return (super.getPropertyDescriptors());	}    }}