// 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.ArrayList; import java.util.Iterator; import java.util.List; import xaal.objects.Xaal; /** * @author vkaravir * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class Polygon extends GraphicalPrimitive implements Cloneable{ protected List points; /** * */ public Polygon(Xaal xaalDoc) { super(xaalDoc); points = new ArrayList(); } public Polygon(Xaal xaalDoc, String id) { super(xaalDoc, id); } public Object clone() throws CloneNotSupportedException { Polygon copy = (Polygon) super.clone(); ArrayList cpoints = new ArrayList(); if (points != null) { Iterator iter = points.iterator(); while (iter.hasNext()) { cpoints.add(((Coordinate)iter.next()).clone()); } copy.points = cpoints; } return copy; } /** * @param coordinate */ public void addCoordinate(Coordinate coordinate) { points.add(coordinate); } public Iterator getPoints() { return points.iterator(); } public int getPointCount() { return points.size(); } public Rectangle getBounds() { int maxX = -1, maxY = -1, minX = Integer.MAX_VALUE, minY = Integer.MAX_VALUE; Iterator iter = getPoints(); while (iter.hasNext()) { Coordinate c = iter.next(); maxX = Math.max(maxX, c.getAbsoluteX()); maxY = Math.max(maxY, c.getAbsoluteY()); minX = Math.min(minX, c.getAbsoluteX()); minY = Math.min(minY, c.getAbsoluteY()); } return new Rectangle(minX, minY, maxX - minX, maxY - minY); } }