TextScrollBean.java

The source code for TextScrollBean and TextScrollBean2 are completely the same. So why would I even bother with both? Because TextScrollBean2 is known to the beanbox by introspection of its java byte code. TextScrollBean, on the other hand, is packaged along with a class called TextScrollBeanBeanInfo. This BeanInfo class tells the beanbox what it needs to know about the associated bean - properties, events, and methods.

When no BeanInfo class is available, introspection analyses the class by its java byte code, determines the superclass, and repeats the process on the superclass. Only when a BeanInfo class is found does the beanbox stop analysing the superclass chain. In this way, one can trivially extend beans without concern for masking specified details. Of course, one can extend a BeanInfo class if desired. I do not presume to address the details of a BeanInfo class, just the basic idea. Here is the source code for TextScrollBeanBeanInfo.java:


import java.beans.*;
import java.lang.reflect.*;
import java.awt.*;

public class TextScrollBeanBeanInfo extends SimpleBeanInfo {
	// Define our beanClass that we are working with
	private final static Class beanClass = TextScrollBean.class;

	// This method returns standard information about our Bean
	// Currently it is changing the name to Text Scroller
	public BeanDescriptor getBeanDescriptor() {
		//BeanDescriptor bd = new BeanDescriptor(beanClass, customizerClass);
		BeanDescriptor bd = new BeanDescriptor(beanClass);
		bd.setDisplayName("Text Scroller");
    		return bd;
  	}

	// This method returns the icon to be used in the BeanBox.
	// Normally we would check for which size of the Image we're
	// looking for, but we only have one icon

	public Image getIcon(int iconKind) {
		return loadImage("TextScroll.gif");
	}
	

	// This method changes the Propety Editor to only display 
	// the properties we want it to.
	public PropertyDescriptor[] getPropertyDescriptors() {
		try {
			PropertyDescriptor speedPD = 
			  new PropertyDescriptor("speed", beanClass);
			PropertyDescriptor textStringPD = 
			  new PropertyDescriptor("textString", beanClass);
			PropertyDescriptor fontStringPD = 
			  new PropertyDescriptor("font", beanClass);
			PropertyDescriptor pdArray[] = {
				speedPD,textStringPD, fontStringPD };

      			return pdArray;
    		} catch (IntrospectionException ex) {
      			throw new Error(ex.toString());
    		}
  	}

}



The fact that the BeanInfo class does not define but a few properties is evident when loaded into the beanbox as shown below. Also, the name that the bean uses in the beanbox has been specified as Text Scroller. Look at the toolbox. Even an image has been specified.

TextScroll.gif
You should be able to package TextScrollBean with TextScrollBeanBeanInfo.class and ScrollText.gif into a bean. Make sure TextScrollBeanBeanInfo and the ScrollText.gif file are in the same directory, and in the jar. You could include "Name: TextScrollBeanBeanInfo.class" in the manifest, but don't call it a bean. And a jar file may specify more than one bean. This is how I jar-ed:


C:\Users\beanbox\jars\banner>jar cmfv manifest.txt banner.jar *.class *.gif
added manifest
adding: Howard_Kosel.class (in=2044) (out=1171) (deflated 42%)
adding: TextScrollBean.class (in=3982) (out=1915) (deflated 51%)
adding: TextScrollBean1.class (in=3430) (out=1738) (deflated 49%)
adding: TextScrollBean2.class (in=3984) (out=1919) (deflated 51%)
adding: TextScrollBeanBeanInfo.class (in=1656) (out=866) (deflated 47%)
adding: TextScroll.gif (in=599) (out=491) (deflated 18%)

C:\Users\beanbox\jars\banner>

The End