// XAAL toolkit // Copyright (C) 2009 Ville Karavirta // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . package xaal.objects.graphical; import java.awt.Rectangle; import java.util.Iterator; import xaal.objects.Xaal; public class Shape extends GraphicalPrimitive { private ShapeDefinition shapeDef; private double scale = 1.0; private Coordinate coord; public Shape(Xaal xaalDoc) { super(xaalDoc); } public void addCoordinate(Coordinate c) { coord = c; } public Coordinate getCoordinate() { if (coord == null) { coord = new Coordinate(getXaal(), 0,0); } return coord; } public void setCoordinate(Coordinate c) { coord = c; } public double getScale() { return scale; } public void setScale(double scale) { this.scale = scale; } public ShapeDefinition getShapeDefinition() { return shapeDef; } public void setShapeDefinition(ShapeDefinition shapeDef) { this.shapeDef = shapeDef; } public Rectangle getBounds() { Iterator iter = getShapeDefinition().getGraphicals(); Rectangle bounds = null; while (iter.hasNext()) { GraphicalPrimitive gp = (GraphicalPrimitive) iter.next(); if (bounds == null) { bounds = new java.awt.Rectangle(gp.getBounds()); } else { bounds.add(gp.getBounds()); } } if (bounds == null) { return new Rectangle(0,0,0,0); } Rectangle myBounds = new Rectangle(bounds.x + getCoordinate().getAbsoluteX(), bounds.y + getCoordinate().getAbsoluteY(), (int)(bounds.width*getScale()), (int)(bounds.height*getScale())); return myBounds; } }