Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Visual Editor (VE) » Property Editor Code geneartion problem
Property Editor Code geneartion problem [message #605622] Mon, 28 February 2005 12:12
Eclipse UserFriend
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;
}
}
Previous Topic:VE on linux ... no image of the controls ?!
Next Topic:Property Editor Code geneartion problem
Goto Forum:
  


Current Time: Thu Mar 28 08:13:49 GMT 2024

Powered by FUDForum. Page generated in 0.02485 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top