Creating a property editor
This is a feature of JBuilder Professional and Enterprise.
A property editor is an editor for changing property values at design time. You can see several different types of property editors in JBuilder's Inspector. For example, for some properties, you simply type in a value in the Inspector, and by so doing, change the value of the property. This is the simplest type of property editor. For other properties, you use a choice menu (drop-down list) to display all the possible values and you select the value you want from that list. Colors and fonts have property editors that are actually dialog boxes you can use to set their values.
When you create your own JavaBeans, you might create new property classes and want to have editors capable of editing their values. BeansExpress can help you create property editors that display a list of choices.
To begin creating a property editor for a property,
- Click the Property Editors tab in BeansExpress.
- Click the Create Custom Editor button.
The New Property Editor dialog box appears.
- Specify the name of your property editor in the Editor Name box.
Give the property editor the same name as the property it will edit with the word Editor appended. For example, if the property name is
favoriteFoods
, name the editor FavoriteFoodsEditor
.
- Select the type of editor you want from the Editor Type drop-down list.
The appearance of the New Property dialog box changes depending on which type of editor you selected. The next four sections describe how to create a property editor of the four different types.
Creating a String List editor
A String List is a simple list of Strings. It appears in the Inspector as a drop-down list containing the strings you specify. When the user uses the list to select an entry, the property being edited is set to the selected value.
To add items to a String List editor,
- Choose Add Entry for each item you want to appear in the list.
- In each entry, enter the string you want to appear.
This is how the resulting New Property Editor dialog box might look:
- Choose OK, and a new property editor class is created.
To see the generated code,
- Select your property editor class in the project pane.
- Click the Source tab.
Creating a String Tag List editor
A property editor that is a String Tag List also presents a list of strings to the user in the Inspector. When the user selects one of the items, the specified Java initialization string is used to set the property. A Java initialization string is the string JBuilder uses in the source code it generates for the property.
To add items to a String Tag List editor,
- Choose Add Entry for each item you want to appear in the list.
- In each entry, enter the string you want to appear and its associated Java initialization string.
If you want to include a string in your list of Java initialization strings, put quotation marks (") before and after the string, as if you were entering it in source code.
Here is an example of how the dialog box might look:
- Choose OK, and a new property editor class is created.
To see the generated code,
- Select your property editor class in the project pane.
- Click the Source tab.
Creating an Integer Tag List editor
An Integer Tag List property editor can be used to edit integer properties. It presents a list of strings to
the user in the Inspector, and when the user selects one of the items, the specified Java initialization
string is used to set the property.
To add items to an Integer Tag List editor,
- Choose Add Entry for each item you want to appear in the list.
- In each entry, enter the string you want to appear and its associated integer value and Java initialization
string.
If you want to include a string in your list of Java initialization strings, put quotation marks (") before
and after the string, as if you were entering it in source code.
Here is an example of how the dialog box might look:
- Choose OK, and a new property editor class is created.
To see the generated code,
- Select your property editor class in the project pane.
- Click the Source tab.
Creating a custom component property editor
You can also use your own custom component to edit the value of a property. Selecting this choice generates a skeleton property editor that uses the custom editor you specify to actually edit the property.
To specify a custom component property editor,
- Enter the name of your custom component in the Custom Editor Name box.
- Check the Support paintValue() option if your custom editor paints itself.
To see the generated code,
- Select your property editor class in the project pane.
- Click the Source tab.
Adding support for serialization
Serializing a bean saves its state as a sequence of bytes that can be sent over a network or saved to a file. BeansExpress can add the support for serialization to your class.
To add support for serialization,
- Select your bean in the project pane.
- Click the Bean tab to display the BeansExpress designers.
- Click the General tab to display the General page.
- Check the Support Serialization option.
BeansExpress modifies the class so that it implements the Serializable
interface. Two methods are added to the class: readObject()
and writeObject()
:
void writeObject(ObjectOutputStream oos) throws IOException {
oos.defaultWriteObject();
}
void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
ois.defaultReadObject();
}
}
You must fill in these two methods to serialize and deserialize your bean.
Checking the validity of a JavaBean
When you're finished with your bean, you can use BeanInsight to verify that the component you created is a valid JavaBean component. If your class fails as a JavaBean, BeanInsight reports why it failed. It identifies all the properties, customizers, and property editors it finds for the class. It also reports whether the property information is obtained through a BeanInfo class or through introspection.
To verify that your Java class is a JavaBean,
- Choose Tools|BeanInsight to display BeanInsight:
- Type in the name of the component you want examined or use the Select Bean button to specify the component. If the bean is already selected in the project pane when BeanInsight appears, its name is displayed in BeanInsight.
- Click the Examine Bean button to begin the examination process.
BeanInsight reports a summary of its findings in the BeanInsight Results section of the wizard.
- To see complete details on BeanInsight's findings, click the View Details button.
- Click the various tabs to see the full report.
Installing a bean on the component palette
Once you have built a valid JavaBean component, you are ready to install it on the component palette. The class files for your new component must be on your classpath.
To install a completed component,
To install a completed component,
- Choose Tools|Configure Palette or right-click the component palette and choose Properties.
The Palette Properties dialog box appears.
- Select the Add Components tab.
- Click the Select Library button to display the Select a Different Library dialog box and use it to specify the library that contains the JavaBeans you want to install.
- Click the Select Palette Page drop-down arrow and choose the page on the component palette on which you want the component to appear.
- Choose Install and select the class you want to install in the Browser For Class dialog box.
- Choose OK to close the dialog box and add the component to the selected page.
Specifying a component image
Each component on the component palette has an image to represent it. If you don't specify an image for the component, the default JBuilder component icon appears. If you want to specify a unique image for your component, you can use the Palette Properties dialog box. The image that represents a component on the component palette must
- Be 16 or 32 pixels square.
- Have a file type of .GIF.
- Reside in the same directory (package) as the component.
To specify an image for your component on the component palette with the Palette Properties dialog box,
- Choose Tools|Configure Palette or right-click the component palette and choose Properties.
- Select the Pages tab.
- Select the page your component is on and select the component.
- Click the Properties button to display the Item Properties dialog box.
- Choose Select Image and specify the .GIF file you want for your component.
- Click OK to close the Item Properties dialog box.
- Click OK when you are finished.
Specifying a component palette page
If none of the existing pages on the component palette are appropriate for your new component, you can specify a new page for it.
To specify a new page in the component palette,
- In the Palette Properties dialog box, choose the Add button.
- Enter the name of the new page.
When you are through using the Palette Properties dialog box, the new page appears on the component palette.
Deploying beans
When you are ready to distribute your JavaBean, the Archive Builder can put all the necessary files for your bean into a JAR file.
To access the Archive Builder, choose Wizards|Archive Builder.
For information on using the Archive Builder, click the Help button of the Archive Builder itself. For more complete information about deploying Java programs and applets, including JavaBeans, see "Deploying Java programs."