Property Editor Code geneartion problem [message #605622] |
Mon, 28 February 2005 12:12 |
Eclipse User |
|
|
|
Originally posted by: marc.brugger.mimacom.ch
hi
I wrote a Property Editor for my Bean to change a state. When I drop
this bean into VE I can start my PropertyEditor and set the new value
for the property. But when I close the editor. the property isn't set
correctly. instead of the selected value I alwasy get '???'
(chartBean.setInverse(???);).
Can someone tell me how to solve this problem?
tank you very much.
marc
------------------------------------------------------------ ---------------
package a;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyEditorSupport;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
/**
* The panel for setting the inverse property. It contains radio buttons to
* toggle between normal and inverse coloring.
*/
public class InverseEditorPanel extends JPanel
{
public InverseEditorPanel(PropertyEditorSupport ed)
{
editor = ed;
ButtonGroup g = new ButtonGroup();
boolean isInverse = ((Boolean) editor.getValue()).booleanValue();
normal = new JRadioButton("Normal", !isInverse);
inverse = new JRadioButton("Inverse", isInverse);
g.add(normal);
g.add(inverse);
add(normal);
add(inverse);
ActionListener buttonListener = new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
editor.setValue(new Boolean(inverse.isSelected()));
}
};
normal.addActionListener(buttonListener);
inverse.addActionListener(buttonListener);
}
private JRadioButton normal;
private JRadioButton inverse;
private PropertyEditorSupport editor;
}
------------------------------------------------------------ ---------------
package a;
import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.beans.*;
/**
* The property editor for the inverse property of the ChartBean. The
inverse
* property toggles between colored graph bars and colored background.
*/
public class InverseEditor extends PropertyEditorSupport
{
public Component getCustomEditor()
{
return new InverseEditorPanel(this);
}
public boolean supportsCustomEditor()
{
return true;
}
public boolean isPaintable()
{
return true;
}
public void paintValue(Graphics g, Rectangle box)
{
Graphics2D g2 = (Graphics2D) g;
boolean isInverse = ((Boolean) getValue()).booleanValue();
String s = isInverse ? "Inverse" : "Normal";
g2.setColor(isInverse ? Color.black : Color.white);
g2.fill(box);
g2.setColor(isInverse ? Color.white : Color.black);
FontRenderContext context = g2.getFontRenderContext();
Rectangle2D stringBounds = g2.getFont().getStringBounds(s,
context);
double w = stringBounds.getWidth();
double x = box.x;
if (w < box.width)
x += (box.width - w) / 2;
double ascent = -stringBounds.getY();
double y = box.y + (box.height - stringBounds.getHeight()) / 2
+ ascent;
g2.drawString(s, (float) x, (float) y);
}
public String getAsText()
{
return null;
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.02485 seconds