// 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 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 Rectangle extends GraphicalPrimitive { private Coordinate start, end; private int[] round; /** * */ public Rectangle(Xaal xaalDoc) { super(xaalDoc); round = new int[] {0, 0}; } public Rectangle(Xaal xaalDoc, String id) { super(xaalDoc, id); round = new int[] {0, 0}; } /** * @param coordinate */ public void setStartCoordinate(Coordinate coordinate) { start = coordinate; } public Coordinate getStartCoordinate() { return start; } /** * @param coordinate */ public void setEndCoordinate(Coordinate coordinate) { end = coordinate; } public Coordinate getEndCoordinate() { return end; } /** * @param x * @param y */ public void setRound(int x, int y) { round = new int[] {x, y}; } public int[] getRound() { return round; } public boolean equalsIgnoreId(GraphicalPrimitive gp) { if (!(gp instanceof Rectangle) || !super.equalsIgnoreId(gp)) return false; Rectangle rect = (Rectangle) gp; if (rect.getStartCoordinate().equalsIgnoreId(getStartCoordinate()) && rect.getEndCoordinate().equalsIgnoreId(getEndCoordinate()) && rect.getRound()[0] == getRound()[0] && rect.getRound()[1] == getRound()[1]) return true; return false; } public void addCoordinate(Coordinate c) { if (start == null) setStartCoordinate(c); else if (end == null) setEndCoordinate(c); } public int getWidth() { return getStartCoordinate().getX() - getEndCoordinate().getX(); } public int getHeight() { return getStartCoordinate().getY() - getEndCoordinate().getY(); } public void setBounds(int x, int y, int width, int height) { setStartCoordinate(new Coordinate(getXaal(), x, y)); setEndCoordinate(new Coordinate(getXaal(), x + width, y + height)); } public java.awt.Rectangle getBounds() { java.awt.Rectangle bounds = new java.awt.Rectangle(); bounds.x = Math.min(start.getAbsoluteX(), end.getAbsoluteX()); bounds.y = Math.min(start.getAbsoluteY(), end.getAbsoluteY()); bounds.width = Math.max(start.getAbsoluteX(), end.getAbsoluteX()) - bounds.x; bounds.height = Math.max(start.getAbsoluteY(), end.getAbsoluteY()) - bounds.y; return bounds; } }