[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[ve-dev] Adding extended JPanel to VE with BeanInfo and problem with location property
|
I am
developing some beans, and I need them to be able for the user to set the
'location' property. Besides, it has to be possible to change the name
displayed in the properties editor in different languages.
I have
created a class MyBeanBeanInfo extending SimpleBeanInfo, and in the method
getPropertyDescriptors() I have tried two options:
1) I have
created my own 'location' property, setting its DisplayName. With this option
the property is shown correctly in the property editor by the visual editor,
and its values are automatically refreshed when the user moves the bean in the
design editor, because they change the setBounds sentence in the code, and the
getLocation method (which calls to getBounds) is called automatically to get
the value of the property after every movement.
But as
soon as I set the value by changing it in the property editor (rather than
moving it with the mouse), a line with the 'setLocation' sentence is written in
the generated code file, and after that the movements of the bean with the
mouse in design editor have no effect. This is because in every movement the
setBounds sentence is changed, but now the visual editor does not call to the
getLocation method to change the values in the property editor, and rather uses
the values written in the sentence within the code. When the bean code is
executed, the sentence setLocation is used after the setBounds, returning the
bean to its original position.
2) I have
observed that when I use a JPanel (without BeanInfo file), it does not happen
the effect described above. When I set location property in the property
editor, visual editor REPLACES the setBound sentence with one setSize sentence
and one setLocation sentence !! After that, changes of position in the design
editor change the setLocation an setSize sentences (instead of setBounds). So I
tried to use the 'location' property from the JPanel as all my beans inherit
from it.
I use the
Introspector to get the PropertyDescriptor from the java.awt.Component class
for the 'location' property, and return it with the rest of my properties. It
worked fine, changing the setBounds sentence by both setSize and setLocation,
but I have a problem: it does not accept changes in the display name, and it is
always shown 'location'.
I use Eclipse 3.1.1 with Visual Editor 1.1.0
Could anyone help me?
Example:
import javax.swing.JPanel;
public class MyBean extends JPanel{
public
MyBean() {
super();
}
}
import java.beans.*;
public class
MyBeanBeanInfo extends SimpleBeanInfo {
public PropertyDescriptor[] getPropertyDescriptors() {
PropertyDescriptor[] props = new PropertyDescriptor[1];
PropertyDescriptor propDesc = new PropertyDescriptor(location,
MyBean.class);
propDesc.setDisplayName("posicion");
props[0]=propDesc;
return props;
}
}