Changing Figure at runtime [message #217704] |
Mon, 12 June 2006 07:49 |
Eclipse User |
|
|
|
Originally posted by: robert.moestl.joanneum.at
Hello!
I spent a lot of time trying to change the figure of an editpart from a
rectangle to an ellipse at runtime. So if my model changes its
geometryType from 'box' to 'cylinder' a circle should be drawn instead
of a rectangle. I'm trying this in the Editpart method refreshVisuals()
like this:
protected void refreshVisuals() {
String geometryType = getExhibit().getGeometryType();
Rectangle bounds = null;
if(geometryType.equals(VisualExhibit.GEOMETRY_TYPE_BOX)) {
setFigure(new VisualExhibitFigure(getExhibit()));
bounds = new
Rectangle(UnitConversion.toPoint(getExhibit().getPosition()) ,
((VisualExhibitFigure)getFigure()).getVirtualBounds().getSiz e());
} else if(geometryType.equals(VisualExhibit.GEOMETRY_TYPE_CYLINDER) ) {
setFigure(new Ellipse());
bounds = new
Rectangle(UnitConversion.toPoint(getExhibit().getPosition()) ,
(getFigure()).getSize());
}
GefUtilities.addOffset(bounds);
ensureMinimumBounds(bounds);
((GraphicalEditPart) getParent()).setLayoutConstraint(this,
getFigure(), bounds);
getFigure().repaint();
super.refreshVisuals();
}
But it doesn't work. I always got an NullPointerException in
setLayoutConstraint, because the figure has no parent. I also tried to
set the parent of the new figure via setParent, but it still didn't worked.
Did anybody know a standard way changing figures at runtime?
Thanks in advance,
Robert
|
|
|
Powered by
FUDForum. Page generated in 0.02188 seconds