Customizers for Java bean properties
A customizer is an additional dialog that users can launch to change Java bean properties. You can create customizer classes for editing properties of Java beans that you add to the visual editor.
A customizer class should implement the interface java.beans.Customizer, and should also be a subclass of java.awt.Component. Usually, a customizer is a container such as a java.awt.Panel or javax.swing.JPanel that contains the controls to let you view and manipulate your Java bean's properties. When the customizer is launched from the toolbar button, it is hosted inside a dialog that has OK and Cancel buttons.
When a user opens a customizer, the customizer is given the Java bean it is customizing as part of the method public void setObject(Object bean);. The customizer is then able to make changes directly to the argument.
The java.beans.Customizer interface also has the methods public void addPropertyChangeListener(PropertyChangeListener listener); and public void removePropertyChangeListener(PropertyChangeListener listener). The visual editor will add itself as a listener on the customizer, and if the customizer is to refresh the appearance of the Java bean on the Design view, it should signal a property change by calling its listeners with any of the methods firePropertyChange(... with any set of arguments.
When your user clicks OK, the visual editor will try to determine what changes the customizer has made to the Java bean so it can update the Java source code. To do this, the visual editor takes a copy of all the Java bean's properties before the customizer is launched, and then compares them with the properties when the customizer is closed. If any property is different ( returns false to the equals method), it is determined to have been changed. To determine the argument to the set method for the property, the property editor on the java.beans.PropertyDescriptor is created. Then, it is called with public void setValue(Object) and public String getJavaInitializationString();. Likewise, when you click Cancel, because the customizer has already changed the Java bean, the visual editor queries the set of properties and resets any that are different to their initial state.
If the customizer is a top level shell that does not require a dialog to run within, such as a java.awt.Frame or javax.swing.JFrame, the visual editor will run the customizer as is. Because this type of customizer is responsible for its own set of buttons and the visual editor has no way of knowing whether it was canceled or confirmed, whenever the customizer is closed, the top level properties are queried to see whether they have changed. Thus, if the customizer performs a cancel it must do so, thereby ensuring the Java bean's properties are restored to their initial state.
After you write a customizer, it needs to be set on the bean descriptor for the BeanInfo class for the Java bean:
public class MyClassBeanInfo extends SimpleBeanInfo { public BeanDescriptor getBeanDescriptor() { return new BeanDescriptor(MyClass.class, MyCustomizer.class); } }
Parent topic
Extending the visual editor for Java