resize Polygon within rectangle [message #86528] |
Wed, 20 December 2006 03:54  |
Eclipse User |
|
|
|
Hi,
I've read in the NG that polygons needs to be contained within a
container to be shown. Thats fine to me. Now I want to resize the
polygon dynamically to fill the rectangle complete. How do I do this?
Can I use a specific layout or do I need to overrride a figure method? I
tried to override the paintFigure( Graphics graphics ) method by setting
the point coordinates based on the bounds of the rectangle, but then it
trims the polygon at the border of the rectangle.
Thanks in advance
Sven
|
|
|
Re: resize Polygon within rectangle [message #86617 is a reply to message #86528] |
Wed, 20 December 2006 08:14  |
Eclipse User |
|
|
|
Ok, I've got it:
just overrride the paintFigure method:
public class RhombusFigure extends org.eclipse.draw2d.Polygon {
private org.eclipse.draw2d.geometry.Point p1 = new
org.eclipse.draw2d.geometry.Point(0, 0);
private org.eclipse.draw2d.geometry.Point p2 = new
org.eclipse.draw2d.geometry.Point(0, 0);
private org.eclipse.draw2d.geometry.Point p3 = new
org.eclipse.draw2d.geometry.Point(0, 0);
private org.eclipse.draw2d.geometry.Point p4 = new
org.eclipse.draw2d.geometry.Point(0, 0);
public RhombusFigure() {
addPoint(p1);
addPoint(p2);
addPoint(p3);
addPoint(p4);
addPoint(p1);
}
private Rectangle lastUsedDimension;
@Override
public void paintFigure( Graphics graphics ) {
Rectangle r = getParent().getBounds();
if( lastUsedDimension == null || !r.equals(lastUsedDimension) ) {
int x = r.x;
int y = r.y;
int w = r.width - Math.max(1, lineWidth);
int h = r.height - Math.max(1, lineWidth);
p1.x = x + (w / 2);
p1.y = y + 0;
p2.x = x + w;
p2.y = y + (h / 2);
p3.x = x + (w / 2);
p3.y = y + h;
p4.x = x + 0;
p4.y = y + (h / 2);
erase();
getPoints().setPoint(p1, 0);
getPoints().setPoint(p2, 1);
getPoints().setPoint(p3, 2);
getPoints().setPoint(p4, 3);
getPoints().setPoint(p1, 4);
bounds = null;
lastUsedDimension = new Rectangle(r);
repaint();
}
super.paintFigure(graphics);
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.07683 seconds