java.beans
public interface PropertyEditor
A PropertyEditor must be able to display its contents when asked to and be able to allow the user to change its underlying field value. However, it is not the PropertyEditor's responsibility to make the change to the underlying Object; in fact, the PropertyEditor does not even know about the Object it is actually editing--only about the property it is currently editing. When a change is made to the property, the PropertyEditor must simply fire a PropertyChangeEvent and allow the RAD tool to actually set the property in the underlying Bean.
PropertyEditors should not change the Objects they are given by setValue(). These Objects may or may not be the actual Objects which are properties of the Bean being edited. Instead, PropertyEditors should create a new Object and fire a PropertyChangeEvent with the old and new values.
PropertyEditors also must support the ability to return a Java initialization string. See the getJavaInitializationString() method for details.
There are several different ways a PropertyEditor may display and control editing of its value. When multiple types of input and display are given by a single PropertyEditor, the RAD tool may decide which of the call to support. Some RAD tools may even be text-only, so even if you support a graphical set and get, it may choose the text set and get whenever it can.
A PropertyChangeEvent should be thrown from the PropertyEditor whenever a bound property (a property PropertyDescriptor.isBound() set to true) changes. When this happens, the editor itself should *not* change the value itself, but rather allow the RAD tool to call setValue() or setAsText().
PropertyEditorManager
,
PropertyEditorSupport
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(PropertyChangeListener listener)
Adds a property change listener to this PropertyEditor.
|
String |
getAsText()
Get the value of this property in String format.
|
Component |
getCustomEditor()
The RAD tool calls this to grab the component that can edit this type.
|
String |
getJavaInitializationString()
Get a Java language-specific String which could be used to create an Object
of the specified type.
|
String[] |
getTags()
Get a list of possible Strings which this property type can have.
|
Object |
getValue()
Accessor method to get the current value the PropertyEditor is working with.
|
boolean |
isPaintable()
The RAD tool calls this to find out whether the PropertyEditor can paint itself.
|
void |
paintValue(Graphics g,
Rectangle bounds)
The RAD tool calls this to paint the actual value of the property.
|
void |
removePropertyChangeListener(PropertyChangeListener listener)
Removes a property change listener from this PropertyEditor.
|
void |
setAsText(String text)
Set the value of this property using a String.
|
void |
setValue(Object value)
Called by the RAD tool to set the value of this property for the PropertyEditor.
|
boolean |
supportsCustomEditor()
The RAD tool calls this to find out whether the PropertyEditor supports a custom component to edit and display itself.
|
void setValue(Object value)
value
- the value to set this property to.Object getValue()
void setAsText(String text) throws IllegalArgumentException
text
- the text to set it to.IllegalArgumentException
- if the String is in the wrong format or setAsText() is not supported.String getAsText()
Return null if you do not support getAsText()/setAsText().
setAsText(getAsText())
should be valid; i.e. the stuff you spit out in
getAsText() should be able to go into setAsText().
String[] getTags()
boolean isPaintable()
void paintValue(Graphics g, Rectangle bounds)
This method should do a silent no-op if isPaintable() is false.
g
- the Graphics context to paint onbounds
- the rectangle you have reserved to work inboolean supportsCustomEditor()
Component getCustomEditor()
The component must hook up with the PropertyEditor and, whenever a change to the value is made, fire a PropertyChangeEvent to the source.
void addPropertyChangeListener(PropertyChangeListener listener)
listener
- the listener to addvoid removePropertyChangeListener(PropertyChangeListener listener)
listener
- the listener to removeString getJavaInitializationString()
The reason for this is that while most RAD tools will serialize the Beans and deserialize them at runtime, some RAD tools will generate code that creates the Beans. Examples of Java initialization strings would be:
2
"I am a String"
new MyObject(2, "String", new StringBuffer())