Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » After changing figure, bounding box of old figure is still drawn
After changing figure, bounding box of old figure is still drawn [message #218069] Mon, 19 June 2006 10:39 Go to next message
Eclipse UserFriend
Originally posted by: robert.moestl.joanneum.at

Hello!

In my application I'm able to change the figure of an editpart from a
rectangle to a circle and vice versa.

I'm achieving this by overriding the method setFigure(IFigure newFigure)
like this:

@Override
protected void setFigure(IFigure newFigure) {
if (figure != null) {
oldGeometryType = getExhibit().getGeometryType();
unregisterVisuals();
IFigure parentFigure = figure.getParent();
int index = parentFigure.getChildren().indexOf(figure);
parentFigure.remove(figure);
figure = newFigure;
parentFigure.add(figure, index);
registerVisuals();
} else {
super.setFigure(newFigure);
}
}



I call setFigure every time the property geometryType in my model
changes. This check is done in refreshVisuals of the editpart. Here is
some code of refreshVisuals():

@Override
protected void refreshVisuals() {
String geometryType = getExhibit().getGeometryType();
....
Rectangle bounds = null;

if(geometryType.equals(VisualExhibit.GEOMETRY_TYPE_BOX)) {
bounds = new
Rectangle(UnitConversion.toPoint(getExhibit().getPosition()) ,
((RectangleFigure)getFigure()).getVirtualBounds().getSize()) ;
} else
if(geometryType.equals(VisualExhibit.GEOMETRY_TYPE_CYLINDER) ) {
bounds = new
Rectangle(UnitConversion.toPoint(getExhibit().getPosition()) ,
(getFigure()).getSize());
}

((GraphicalEditPart) getParent()).setLayoutConstraint(this,
getFigure(), bounds);
getFigure().repaint();
super.refreshVisuals();
}


My problem is, that when the figure changes the bounding box of the old
figure is still drawn once. After that the bounding box for the figure
is correct (for example when I resize the figure or change the position).

So how can I achieve that if the figure of an EditPart changes, the
bounding box appears correct? I also tried to use
getFigure().setBounds(bounds) in refreshVisuals of the EditPart. But
that wasn't successful too...

So may somebody made the same experiences and can provide me with a
solution or somebody has an idea what I'm doing wrong?!

Thanks in advance

Robert
Re: After changing figure, bounding box of old figure is still drawn [message #218083 is a reply to message #218069] Mon, 19 June 2006 17:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

It might be safer to deactivate and unregister the editpart before replacing
the figure.

"Robert M
Re: After changing figure, bounding box of old figure is still drawn [message #218138 is a reply to message #218083] Tue, 20 June 2006 08:07 Go to previous message
Eclipse UserFriend
Originally posted by: robert.moestl.joanneum.at

Thanks Randy. It works fine.

For those who are interested, I call deactivate() before and activate()
after setting the new Figure.

Regards

Robert

Randy Hudson schrieb:
> It might be safer to deactivate and unregister the editpart before replacing
> the figure.
>
> "Robert Möstl" <robert.moestl@joanneum.at> wrote in message
> news:e75uso$rma$1@utils.eclipse.org...
>> Hello!
>>
>> In my application I'm able to change the figure of an editpart from a
>> rectangle to a circle and vice versa.
>>
>> I'm achieving this by overriding the method setFigure(IFigure newFigure)
>> like this:
>>
>> @Override
>> protected void setFigure(IFigure newFigure) {
>> if (figure != null) {
>> oldGeometryType = getExhibit().getGeometryType();
>> unregisterVisuals();
>> IFigure parentFigure = figure.getParent();
>> int index = parentFigure.getChildren().indexOf(figure);
>> parentFigure.remove(figure);
>> figure = newFigure;
>> parentFigure.add(figure, index);
>> registerVisuals();
>> } else {
>> super.setFigure(newFigure);
>> }
>> }
>>
>>
>>
>> I call setFigure every time the property geometryType in my model changes.
>> This check is done in refreshVisuals of the editpart. Here is some code of
>> refreshVisuals():
>>
>> @Override
>> protected void refreshVisuals() {
>> String geometryType = getExhibit().getGeometryType();
>> ... Rectangle bounds = null;
>>
>> if(geometryType.equals(VisualExhibit.GEOMETRY_TYPE_BOX)) {
>> bounds = new
>> Rectangle(UnitConversion.toPoint(getExhibit().getPosition()) ,
>> ((RectangleFigure)getFigure()).getVirtualBounds().getSize()) ;
>> } else if(geometryType.equals(VisualExhibit.GEOMETRY_TYPE_CYLINDER) ) {
>> bounds = new Rectangle(UnitConversion.toPoint(getExhibit().getPosition()) ,
>> (getFigure()).getSize());
>> }
>>
>> ((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(),
>> bounds); getFigure().repaint();
>> super.refreshVisuals();
>> }
>>
>>
>> My problem is, that when the figure changes the bounding box of the old
>> figure is still drawn once. After that the bounding box for the figure is
>> correct (for example when I resize the figure or change the position).
>>
>> So how can I achieve that if the figure of an EditPart changes, the
>> bounding box appears correct? I also tried to use
>> getFigure().setBounds(bounds) in refreshVisuals of the EditPart. But that
>> wasn't successful too...
>>
>> So may somebody made the same experiences and can provide me with a
>> solution or somebody has an idea what I'm doing wrong?!
>>
>> Thanks in advance
>>
>> Robert
>
>
Previous Topic:Best Way To Load GEF Example Source?
Next Topic:Polyline
Goto Forum:
  


Current Time: Fri Apr 19 10:53:29 GMT 2024

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

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

Back to the top