The following beans are all present in the default ToolBox palette for the BeanBox. Their sources are in the "demo" directory.
In addition, color-annotated source code for ExplicitButton, JellyBean, Juggler, Molecule, and OurButton is used to illustrate various Beans topics.
Try connecting up the PropertyChange event from (say) an OurButton to the reportChange method of a ChangeReporter bean. Then when you change a bound property on the OurButton, the ChangeReporter will report the change.
This provides a simple way of checking that your bean is correctly firing PropertyChange events from its bound properties.
When you compare an ExplicitButton with an OurButton, you will see that the ExplicitButton has a smaller set of properties and a smaller set of better named events in the Edit/Events sub-menu. The ExplicitButton also has an icon in the ToolBox; the monochrome icon shown is returned by ExplicitButtonBeanInfo when the ToolBox requests a color icon.
The ExplicitButton also comes with a trivial customizer, the ExplicitButtonCustomizer that simply lets you change the label for the button. (This is not a particularly good use of a customizer!)
The ExplicitButton also indicates that it has some hidden-state (which in this case is a lie!) by using the FeatureDescriptor's attribute/value mechanism to specify in the bean's BeanDescriptor an attribute named "hidden-state" to be Boolean true. Following the JavaBeans 1.01 API specification, code generation cannot be done in this case and serialization must be used instead.
The EventMonitor sources provide an example of how a sophisticated bean, such as a bean container, can dynamically generate code to handle arbitrary kinds of events from other beans.
To use the EventMonitor bean you must:
As soon as that first event is delivered from the source bean to
the EventMonitor, the EventMonitor will leap like a Tasmanian Devil on
the source bean, analyze it, discover all the different events it fires,
and create and register an event listener for each type of event. It will
then report whenever any of these events are fired.
You may want to resize the EventMonitor bean to see all the different event output.
Because the JDBC SELECT bean is fairly complex to configure, it comes with its own customizer that helps you to configure the bean.
After dropping the JDBC SELECT bean onto the middle composition window, select the Edit/Customize... menu item to bring up the bean customizer.
This prompts you initially for a target database URL and a login name and password. Then you can use the customizer to view the available database tables (push either "User tables" or "All Tables") and select a target table. The customizer then shows the various columns in that target table and lets you chose which columns you want displayed in the bean. As you chose columns, the bean is updated to show the current output of the corresponding SQL SELECT statement.
You can connect up an OurButton Action event to call the SELECT bean's "update" method, so that you can cause the bean to re-execute its SELECT.
Initially you will be able to edit the JellyBean's priceInCents field without difficulty. However if you connect up the JellyBean's vetoableChange event to a Voter bean's vetoableChange handler method, then when you try to change the JellyBean's price, the constrained property change will be rejected. Color-annotated source code describes how to implement constrained and bound properties.
It is interesting because it's implemented as a serialized object, which was formed by taking a regular ExplicitButton, changing its background color and serializing it to a file. See the creating program in OrangeButtonWriter.java
You can start and stop the animation by connecting the button push events on two ExplicitButtons to the startJuggling and stopJuggling methods on a Juggler.
Color-annotated source code for Juggler illustrates Serialization/Persistence.
The Juggler has a very simple JugglerBeanInfo class that defines a 16x16 color icon for the Juggler, that gets displayed in the ToolBox.
You can perform method tracing by setting the debug property to true, illustrating the use of a service provided by Juggler's nesting BeanContext, the beanbox.
You can also rotate the molecule by connecting up buttons to the rotateX and rotateY methods of the Molecule.
The Molecule comes with its own MoleculeNameEditor custom Property Editor for the "moleculeName" property. This Property Editor lets you chose from one of 6 different simple molecules to display in the Molecule bean. The molecule descriptions are read from descriptor files that the Molecule bean load as class-name relative resources. Color-annotated source code illustrates how to implement this Property Editor.
OurButton exposes the standard java.awt.Component properties (foreground, background, font, and name) and adds four of its own (label, fontSize, largeFont, and debug). Notice how the font related properties interact, so that if you change fontSize from 12 to 24, then the font and largeFont properties are also updated.
OurButton will dynamically resize itself whenever its label or font is changed, so that the text exactly fits in the bean.
Color-annotated source code for OurButton.java illustrates how to implement an event listener and an event source.
To start a local RMI quote server that generates imaginary values for the QuoteMonitor to display, cd to the demo directory and if you are on Windows type "start nmake -f quote.mk run" or if you are on Unix type "gnumake -f quote.mk run &".
You can click on the sorter bean to start it sorting. You can change the sort algorithm in the PropertySheet to be any of "BubbleSort", "QSort", or "BidirBubbleSort".
If you're feeling like a little hacking, try changing the SortItem to have a custom property editor for its sort algorithm, like the Molecule does for its molecule name.
TickTock fires a PropertyChange event at regular intervals. You can change the interval using the property sheet. Try connecting up the TickTock's PropertyChange event to a ChangeReporter to watch the events being fired.
If you connect up the vetoableChange events from a bean which supports constrained properties (such as the JellyBean with its priceInCents property) to a Voter bean then you can reject any proposed changes to constrained properties.
This allows you to test your bean's use of constrained properties.
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.