1 22 23 package swingwt.awt.geom; 24 25 26 public abstract class Rectangle2D extends RectangularShape { 27 28 public static final int OUT_LEFT = 1; 29 public static final int OUT_TOP = 2; 30 public static final int OUT_RIGHT = 4; 31 public static final int OUT_BOTTOM = 8; 32 33 protected Rectangle2D() { 34 } 35 public abstract void setRect(double x, double y, double w, double h); 36 public void setRect(Rectangle2D r) { 37 setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight()); 38 } 39 public boolean intersectsLine(double x1, double y1, double x2, double y2) { 40 return false; 42 } 43 public boolean intersectsLine(Line2D l) { 44 return false; 46 } 47 public abstract int outcode(double x, double y); 48 49 public int outcode(Point2D p) { 50 return 0; 52 } 53 54 public void setFrame(double x, double y, double w, double h) { 55 setRect(x, y, w, h); 56 } 57 public Rectangle2D getBounds2D() { 58 return (Rectangle2D) clone(); 59 } 60 public boolean contains(double x, double y) { 61 double x0 = getX(); 62 double y0 = getY(); 63 return (x >= x0 && y >= y0 && x < x0 + getWidth() && y < y0 + getHeight()); 64 } 65 public boolean intersects(double x, double y, double w, double h) { 66 return false; 68 } 69 public boolean contains(double x, double y, double w, double h) { 70 return false; 72 } 73 public abstract Rectangle2D createIntersection(Rectangle2D r); 74 75 public static void intersect(Rectangle2D src1, 76 Rectangle2D src2, 77 Rectangle2D dest) { 78 79 } 80 public abstract Rectangle2D createUnion(Rectangle2D r); 81 public static void union(Rectangle2D src1, 82 Rectangle2D src2, 83 Rectangle2D dest) { 84 85 } 86 public void add(double newx, double newy) { 87 88 } 89 public void add(Point2D pt) { 90 } 91 public void add(Rectangle2D r) { 92 93 } 94 public PathIterator getPathIterator(AffineTransform at) { 95 return null; 97 } 98 public PathIterator getPathIterator(AffineTransform at, double flatness) { 99 return null; 101 } 102 public boolean equals(Object obj) { 103 if (obj == this) { 104 return true; 105 } 106 if (obj instanceof Rectangle2D) { 107 Rectangle2D r2d = (Rectangle2D) obj; 108 return ((getX() == r2d.getX()) && 109 (getY() == r2d.getY()) && 110 (getWidth() == r2d.getWidth()) && 111 (getHeight() == r2d.getHeight())); 112 } 113 return false; 114 } 115 116 public abstract double getHeight(); 117 public abstract double getWidth(); 118 public abstract double getX(); 119 public abstract double getY(); 120 public abstract boolean isEmpty(); 121 122 public static class Double extends Rectangle2D { 123 public double x; 124 public double y; 125 public double width; 126 public double height; 127 public Double() { 128 } 129 public Double(double x, double y, double w, double h) { 130 setRect(x, y, w, h); 131 } 132 public double getX() { 133 return x; 134 } 135 public double getY() { 136 return y; 137 } 138 public double getWidth() { 139 return width; 140 } 141 public double getHeight() { 142 return height; 143 } 144 public boolean isEmpty() { 145 return (width <= 0.0) || (height <= 0.0); 146 } 147 public void setRect(double x, double y, double w, double h) { 148 this.x = x; this.y = y; this.width = w; this.height = h; 149 } 150 public void setRect(Rectangle2D r) { 151 this.x = r.getX(); 152 this.y = r.getY(); 153 this.width = r.getWidth(); 154 this.height = r.getHeight(); 155 } 156 public int outcode(double x, double y) { 157 return 0; 159 } 160 public Rectangle2D getBounds2D() { 161 return new Double (x, y, width, height); 162 } 163 public Rectangle2D createIntersection(Rectangle2D r) { 164 return null; 166 } 167 public Rectangle2D createUnion(Rectangle2D r) { 168 return null; 170 } 171 public String toString() { 172 return getClass().getName() 173 + "[x=" + x + 174 ",y=" + y + 175 ",w=" + width + 176 ",h=" + height + "]"; 177 } 178 } 179 180 public static class Float extends Rectangle2D { 181 public float x; 182 public float y; 183 public float width; 184 public float height; 185 public Float() { 186 } 187 public Float(float x, float y, float w, float h) { 188 setRect(x, y, w, h); 189 } 190 public double getX() { 191 return (double) x; 192 } 193 public double getY() { 194 return (double) y; 195 } 196 public double getWidth() { 197 return (double) width; 198 } 199 public double getHeight() { 200 return (double) height; 201 } 202 public boolean isEmpty() { 203 return (width <= 0.0f) || (height <= 0.0f); 204 } 205 public void setRect(float x, float y, float w, float h) { 206 this.x = x; 207 this.y = y; 208 this.width = w; 209 this.height = h; 210 } 211 public void setRect(double x, double y, double w, double h) { 212 this.x = (float) x; 213 this.y = (float) y; 214 this.width = (float) w; 215 this.height = (float) h; 216 } 217 public void setRect(Rectangle2D r) { 218 this.x = (float) r.getX(); 219 this.y = (float) r.getY(); 220 this.width = (float) r.getWidth(); 221 this.height = (float) r.getHeight(); 222 } 223 public int outcode(double x, double y) { 224 return 0; 226 } 227 public Rectangle2D getBounds2D() { 228 return null; 230 } 231 public Rectangle2D createIntersection(Rectangle2D r) { 232 return null; 234 } 235 public Rectangle2D createUnion(Rectangle2D r) { 236 return null; 238 } 239 public String toString() { 240 return getClass().getName() 241 + "[x=" + x + 242 ",y=" + y + 243 ",w=" + width + 244 ",h=" + height + "]"; 245 } 246 } 247 248 } 249 | Popular Tags |