Help is available for each task.
Task 1
The first step is to start up an IDE or the BDK's BeanBox
to explore FlexLabel
.
FlexLabel
is very dynamic in its reevaluation of image size, text size, and the relationship between the two based on changing property values. FlexLabel
issues resize requests as appropriate for changing property values. Note, however, that not all IDEs support dynamic resizing of Bean instances within their worksheet, which is an incredibly short-sighted approach to IDE design. If you experience problems with dynamic resizing, consider choosing another IDE. In the short term, use the BeanBox
, which does support dynamic resize requests properly on most platforms (apparently, with occasional redisplay errors on certain platforms).
Task 2
Next, save FlexLabel
's solution files to a working directory and build FlexLabel
, being careful not to omit any of the files. (There are no skeleton files--everything is on the solution page.)
There are script files for building the JAR file from the compiled class files and related files (for example, the GIF files for the Bean's icon). Note that in many environments, you may be able to use the existing JAR file as is. Also, there are two JPEG files, for experimenting with the Bean's image-displaying facility.
Task 3
Next, load the FlexLabel
Bean, instantiate the Bean, and experiment with its properties.
See the expected-output page for an overview of the configuration capabilities.
Task 4
Next, explore the editing facility for the label
property. Recall that the StickFigure
-related Magercises use the JavaBeans framework to register discrete-valued properties for display in a drop-down list, as does FlexLabel
for alignment
and imagePosition
.
FlexLabel
, however, also illustrates a custom property editor; that is, an editor that's implemented in a custom panel. Note that FlexLabel
provides the mechanics for painting the "Edit Label..."
prompt, much like the prompt that's painted for the font
property. If you haven't already done so, activate the custom label
editor.
Investigate the JavaTM source files that implement and register the custom editor: FlexLabelBeanInfo.java
, LabelEditor.java
, and LabelTextAreaPanel.java
. Note that LabelEditor
specializes java.beans.PropertyEditorSupport
. Investigate the methods for this class that were not used in the StickFigure
Magercises, but that are required for implementing a custom editor, in particular,
-
isPaintable()
-
paintValue()
-
supportsCustomEditor()
-
getCustomEditor()
Note that getCustomEditor()
provides the link/connection between the JavaBeans framework and LabelTextAreaPanel
, which implements the graphical panel for the editor. (Recall that FlexLabelBeanInfo
associates a property editor class, in this case, LabelEditor
, with the label
property.)
To activate the custom editor, simply click on the "Edit Label..."
graphic.
Task 5
FlexLabel
supports an image via a file specification. Investigate the image processing-related methods in FlexLabel.java
, as well as the image-related properties and the customization dialog. How might you support images differently (perhaps, without using a file specification)? Do you think that a file specification/association is even appropriate? If not, how would you handle an Image
instance directly, considering issues such as the need for FlexLabel
to be serializable?
Programmatically, one approach to associating an image with a FlexLabel
instance would be to create an Image
object and pass it as an argument to a FlexLabel
constructor, or dynamically specify the image via an access method. FlexLabel
supports these operations. But, is it appropriate to design an image-related property that manipulates Image
instances at design time? If an Image
instance is created as an instance variable in FlexLabel
, is FlexLabel
serializable?
There are no simple answers to these design issues, but the current implementation should help clarify some of the problems that must be addressed.
Copyright © 1998-1999
MageLang Institute.
All Rights Reserved.