Rotating problem [message #203698] |
Thu, 24 November 2005 10:19 |
Eclipse User |
|
|
|
Originally posted by: kiril.disy-bg.com
Hello,
I have a problem with rotating a figure and I hope someone will be able to
help me.
Here is the situation:
In my application I have a source of data - lets call it server.This is
the model.
My edit parts are listeners to the model.
When an event from the model comes I should rotate the figure of the edit
part to
a specified angle.
I should mention here that I dont want to rotate the whole figure.
The figure has a bounding box which is not rotated. But in the figure I
draw a rectangle and this rectangle must be rotated.
This is the source of the propertyChange method in the edit part:
public void propertyChange(PropertyChangeEvent arg0) {
getRoot().getViewer().getControl().getDisplay().asyncExec(ne w Runnable() {
public void run() {
refreshVisuals();
}
});
}
}
This is the source of the refreshVisuals method:
protected void refreshVisuals() {
Rectangle r = new Rectangle(getFigureModel().getBounds().getCopy());
((GEDFigure) getFigure()).rotate(getFigureModel().getAngle());
((GraphicalEditPart) getParent()).setLayoutConstraint(this,
getFigure(), r);
}
The class GEDFigure has a method rotate(float degrees) that just sets the
value of the angle. Here it is:
public void rotate(float degrees) {
fAngle = degrees;
}
Now this is the way I draw the rotated figure - this is the paintFigure
method of my figure:
protected void paintFigure(Graphics graphics) {
super.paintFigure(graphics);
graphics.drawRectangle(getBounds());
paintInnerRect(graphics);
}
private void paintInnerRect(Graphics g) {
Rectangle inner = getBounds().getCopy().crop(new Insets(20,20,20,20));
inner.setLocation(20,20);
g.pushState();
g.setLineWidth(3);
g.translate(getBounds().getLocation().x, getBounds().getLocation().y);
g.rotate(getAngle());
g.drawRectangle(inner);
g.popState();
}
The problem is that when an event comes from the model(server) and I
refresh the figure, the inner rect is not drawn where it should be(the
location is not the one I have specified - 20,20).But when I click on the
figure (I select or deselect the editPart) the inner rect is drawn where
it should be.
Then another event comes from the server and the inner rect is again not
drawn
where it should be. Then I (select or deselect) and so on.
I am using eclise3.2 -M3 with GEF3.1.1
I have also tried eclipse3.1 with GEF3.1.1 - but the result is the same
I will be very thankful if someone can help me in this situation.
Thanks in advance.
|
|
|
Powered by
FUDForum. Page generated in 0.06301 seconds