anusri
anusri

Reputation: 21

Draw ellipse and rounded rectangle in GEF eclipse editor

I want to draw an ellipse and a rounded rectangle in GEF editor. I am not using Canvas and am using XY layout.I am able to draw rectangle in this layout but not the other two.

Please guide

Upvotes: 0

Views: 321

Answers (1)

vainolo
vainolo

Reputation: 6987

To draw a rounded rectangle you need to extend Figure and inside this figure draw a rectangle with rounded borders

(Disclaimer - This is a reduced version of the code I use for a rounded rectangle here. Pretty sure it will work but I didn't test it)

public class RoundedRectangle extends Figure {
    private final RoundedRectangle rectangle;

    public RoundedRectangle() {
        super();
        setLayoutManager(new XYLayout());
        rectangle = new RoundedRectangle();
        rectangle.setCornerDimensions(new Dimension(20, 20)); // This is where the rounding happens
        // Anything else you want to customize
        add(rectangle);
    }

    @Override
    protected void paintFigure(Graphics graphics) {
        Rectangle r = getBounds().getCopy();
        setConstraint(rectangle, new Rectangle(0, 0, r.width, r.height));
    }
}

Upvotes: 1

Related Questions