1 package org.catacomb.graph.drawing; 2 3 import org.catacomb.graph.gui.Painter; 4 5 import java.awt.Color; 6 7 8 9 public class Rectangle extends FixedDrawingComponent { 10 11 12 public double x; 13 public double y; 14 public double rx; 15 public double ry; 16 17 18 public Rectangle() { 19 } 20 21 22 23 public Rectangle(double x1, double y1, double rx1, double ry1) { 24 x = x1; 25 y = y1; 26 rx = rx1; 27 ry = ry1; 28 setColor(Color.black); 29 setClosed(); 30 setFillColor(Color.orange); 31 } 32 33 34 public void setSize(double sx, double sy) { 35 rx = sx; 36 ry = sy; 37 } 38 39 public void instruct(Painter p, double offx, double offy, double scale) { 40 if (isFilled()) { 41 p.drawFilledRectangle(offx + scale * x, offy + scale * y, scale * rx, scale * ry, getFillColor(), getColor(), getWidth(), widthIsPixels()); 42 } else { 43 p.drawRectangle(offx + scale * x, offy + scale * y, scale * rx, scale * ry, getColor(), getWidth(), widthIsPixels()); 44 } 45 } 46 47 48 49 public void applyToShape(Shape shp) { 50 shp.setCurviness(0.0); 51 applySymmetryToShape(shp); 52 double[] xpts = { x - rx, x - rx, x + rx, x + rx }; 53 double[] ypts = { y - ry, y + ry, y + ry, y - ry }; 54 shp.setXpts(xpts); 55 shp.setYpts(ypts); 56 } 57 58 59 public void applySymmetryToShape(Shape shp) { 60 shp.setSymmetry(ShapeSymmetry.RECTANGLE); 61 } 62 63 64 }