1 19 20 package swingwt.awt.geom; 21 22 import swingwt.awt.*; 23 24 public abstract class RectangularShape implements Shape, Cloneable { 25 26 protected RectangularShape() { } 27 28 public abstract double getX(); 29 public abstract double getY(); 30 public abstract double getWidth(); 31 public abstract double getHeight(); 32 public double getMinX() { return getX(); } 33 public double getMinY() { return getY(); } 34 public double getMaxX() { return getX() + getWidth(); } 35 public double getMaxY() { return getY() + getHeight(); } 36 public double getCenterX() { return getX() + getWidth() / 2.0; } 37 public double getCenterY() { return getY() + getHeight() / 2.0; } 38 public Rectangle2D getFrame() { return new Rectangle2D.Double(getX(), getY(), getWidth(), getHeight()); } 39 public abstract boolean isEmpty(); 40 public abstract void setFrame(double x, double y, double w, double h); 41 public void setFrame(Point2D loc, Dimension2D size) { } 42 public void setFrame(Rectangle2D r) { } 43 public void setFrameFromDiagonal(double x1, double y1, 44 double x2, double y2) { 45 46 } 47 public void setFrameFromDiagonal(Point2D p1, Point2D p2) { 48 } 49 public void setFrameFromCenter(double centerX, double centerY, 50 double cornerX, double cornerY) { 51 52 } 53 public void setFrameFromCenter(Point2D center, Point2D corner) { 54 } 55 public boolean contains(Point2D p) { 56 return false; 58 } 59 public boolean intersects(Rectangle2D r) { 60 return false; 62 } 63 public boolean contains(Rectangle2D r) { 64 return false; 66 } 67 public Rectangle getBounds() { 68 double width = getWidth(); 69 double height = getHeight(); 70 if (width < 0 || height < 0) { 71 return new Rectangle(); 72 } 73 double x = getX(); 74 double y = getY(); 75 double x1 = Math.floor(x); 76 double y1 = Math.floor(y); 77 double x2 = Math.ceil(x + width); 78 double y2 = Math.ceil(y + height); 79 return new Rectangle((int) x1, (int) y1, (int) (x2 - x1), (int) (y2 - y1)); 80 } 81 public PathIterator getPathIterator(AffineTransform at, double flatness) { 82 return null; 84 } 85 public Object clone() { 86 try { 87 return super.clone(); 88 } 89 catch (CloneNotSupportedException e) { 90 throw new InternalError (); 91 } 92 } 93 94 public abstract Rectangle2D getBounds2D(); 95 public abstract PathIterator getPathIterator(AffineTransform at); 96 97 } 98 | Popular Tags |