Java Reference
In-Depth Information
techniques for allowing the user to edit the value of a property. The value of a
property can be displayed:
As a string
If you define the
getAsText()
method, a beanbox can convert a property to a
string and display that string to the user.
As an enumerated value
If a property can take only on values from a fixed set of values, you can
define the
getTags()
method to allow a beanbox to display a dropdown
menu of allowed values for the property.
In a graphical display
If you define
paintValue()
, a beanbox can ask the property editor to display
the value using some natural graphical format, such as a color swatch for col-
ors. You also need to define
isPaintable()
to specify that a graphical format
is supported.
The two editing techniques are:
String editing
If you define the
setAsText()
method, a beanbox knows it can simply have
the user type a value into a text field and pass that value to
setAsText()
.If
your property editor defines
getTags()
, it should also define
setAsText()
,so
that a beanbox can set the property value using the individual tag values.
Custom editing
If your property editor defines
getCustomEditor()
, a beanbox can call it to
obtain some kind of GUI component that can be displayed in a dialog box
and serve as a custom editor for the property. You also need to define
sup-
portsCustomEditor()
to specify that custom editing is supported.
The
setValue()
method of a
PropertyEditor
is called to specify the current value
of the property. It is this value that should be converted to a string or graphical
representation by
getAsText()
or
paintValue()
.
A property editor must maintain a list of event listeners that are interested in
changes to the value of the property. The
addPropertyChangeListener()
and
removePropertyChangeListener()
methods are standard event listener registration
and removal methods. When a property editor changes the value of a property,
either through
setAsText()
or through a custom editor, it must send a
Property-
ChangeEvent
to all registered listeners.
PropertyEditor
defines the
getJavaInitializationString()
for use by beanbox
tools that generate Java code. This method should return a fragment of Java code
that can initialize a variable to the current property value.
Finally, a class that implements the
PropertyEditor
interface must have a no-argu-
ment constructor, so it can be dynamically loaded and instantiated by a beanbox.
Most property editors can be much simpler than this detailed description suggests.
In many cases, you can subclass
PropertyEditorSupport
instead of implementing
the
PropertyEditor
interface directly. This useful class provides no-op implemen-