Java BeanBox

 


 

Overview

The BeanBox is a simple tool for testing Beans. To start, execute run.sh.

When started, the BeanBox displays three windows:

  1. ToolBox
  2. BeanBox window
  3. Properties

Here are brief descriptions of each window.

  • The ToolBox contains the Beans available for use by the BeanBox. To work on a Bean, you choose it from the ToolBox and drop it on the BeanBox window.

  • The BeanBox window is the area where you visually wire Beans together, defining how Beans appear, and interact with other Beans. The BeanBox window is itself an instance of a BeanBox Bean. The above screenshot shows the BeanBox window with a Juggler Bean instance dropped in it. Later you'll see how to wire the Juggler to two button Beans that start and stop him juggling.

    You select among Beans in the BeanBox window simply by clicking on the Bean. The selected Bean will have a hatced border, as the Juggler Bean does in the above screenshot. Which Bean is selected has significance for the Properties sheet.

  • The Properties sheet displays the properties for the Bean currently selected within the BeanBox window.

    In the above screenshot, the Properties sheet displays the Juggler Bean's properties. If you drop another Bean in the BeanBox window, the properties sheet will display that Bean's properties.

 

 

Adding a Bean to the ToolBox

When the BeanBox is started, it automatically loads the ToolBox with all the Beans it finds within the JAR files contained in the beans/jars directory. Move your JAR files into that directory to have them automatically loaded at BeanBox startup. You can load Beans from JAR files located elsewhere by using the File|LoadJar... BeanBox menu item.

 

 

Dropping a Bean on the BeanBox

Clicking on a Bean name within the ToolBox chooses that Bean for placement within the BeanBox. To drop a JellyBean instance onto the BeanBox

  1. Click on the word JellyBean in the ToolBox. The cursor will change to a crosshair when flying over the BeanBox windows.
  2. Click within the BeanBox. The JellyBean instance will appear, and will be selected.

Note the change in the Properties sheet when you put the JellyBean in the BeanBox. Before you placed the JellyBean in the BeanBox, the BeanBox's properties were displayed. After placing the JellyBean in the BeanBox, the JellyBean properties are displayed. If you missed the change, click within the BeanBox, away from the JellyBean. This will select the BeanBox rather than the JellyBean. The Properties sheet will then display the BeanBox's properties.

After dropping a JellyBean instance on the BeanBox, the Properties sheet displays the JellyBean properties: color, foreground, priceInCents, background, and font.

 

 

Editing Bean Properties

The Properties sheet displays each property's name and its current value. Values are displayed in an editable text field (strings and numbers), a choice menu (booleans), or as painted values (colors and fonts). Each property has an associated property editor. Clicking on a property within the Properties sheet activates the property's editor. Properties displayed in text fields or choice menus are edited within the Properties sheet.

Because editing their values requires a more sophisticated user interface, Color and Font property types use a custom property editor. When you click on a color or font property a separate panel will pop up to do the editing. Try clicking on each of the JellyBean properties.

 

 

Saving and Restoring Beans

You can save the state of a Bean that your are customizing, and restore the Bean and its saved state at a later time. The BeanBox uses Java Object Serialization to save and restore Beans and their state. The following steps demonstrate how to save and restore a Bean:

  1. Drop a JellyBean on the BeanBox.
  2. Change the color property to anything you want.
  3. Select the File|Save menu item. A file browser will pop up; use it to save the Bean to a file.
  4. Select the File|Clear menu item.
  5. Select the File|Load menu item. The file browser will again pop up; use it to retrieve the serialized Bean. The JellyBean will be the color you chose.

 


 

The BeanBox Menus

 

Menu Item Action
Save Saves the Beans currently in the BeanBox, including each Bean's size, position, and internal state. The saved file can be loaded via File|Load.
SerializeComponent Saves the Beans in the BeanBox to a serialized (.ser) file. This file must be put in a .jar file to be useable by the BeanBox.
MakeApplet Generates an applet from the BeanBox contents.
Load Loads saved files into the BeanBox. This command will not load .ser files.
LoadJar Loads a JAR file's contents into the ToolBox.
Print Prints an image of the BeanBox contents.
Clear Removes the BeanBox contents.
Exit Quits the BeanBox without offering to save.
Cut Removes the Bean selected in the BeanBox. The cut Bean is serialized, and can then be pasted.
Copy Copies the Bean selected in the BeanBox. The copied Bean is serialized, and can then be pasted.
Paste Drops the last cut or copied Bean into the BeanBox.
Report Generates an introspection report for the selected Bean.
Events Lists the selected Bean's event-firing methods, grouped by the Java interface that declares the methods.
Bind property Lists all the selected Bean's methods, if any.
Disable Design Mode/Enable Design Mode Removes the ToolBox and the Properties sheet from the screen. Eliminates all BeanBox design and test behavior (selected Bean, etc.), and makes the BeanBox behave like an application.
Hide Invisible Beans/Show Invisible Beans Hides or shows Beans with no GUI.

 


 

Using the BeanBox to Generate Applets

You can use the BeanBox's File|MakeApplet... menu item to generate an applet from the BeanBox contents. Making an applet from the BeanBox creates:

  • A JAR file containing class files and serialized data
  • A test HTML file that uses the JAR file (and any other JAR files needed)
  • A subdirectory with Java sources and makefile
  • A readme file with complete information about the generated applet and all files involved

Take the following steps to generate an applet from the BeanBox:

  1. Use the Juggler example that you made in the events section. If you saved that example to a file, load it into the BeanBox using the File|Load menu item. If you didn't save it, follow the steps in the events section to build the example. The generated applet will have the same size as the BeanBox frame, so you might want to adjust the BeanBox size to the size of the applet you want.

  2. Choose File|Make Applet to bring up the MakeApplet dialog:


    Use the default JAR file and applet name for this example. Press the OK button.

That's it. The generated files were placed in the beanbox/tmp/myApplet directory. You can inspect your handiwork by bringing up appletviewer in the following way:

appletviewer <BDKInstallation>/beanbox/tmp/myApplet.html

Here is what you will see:

Don't forget to look at the generated myApplet_readme file, and the other files generated.

Generated applets can be used in any JDK 1.1-compliant browser. The appletviewer is a good test platform. Another fully compliant browser is the HotJava browser. See the generated readme file for more information.

 


 

Home