1 21 22 package swingwt.awt; 23 24 import swingwt.awt.geom.*; 25 26 public class Rectangle extends Rectangle2D implements Shape { 27 28 public int x; 29 public int y; 30 public int width; 31 public int height; 32 33 public Rectangle() { 34 this(0, 0, 0, 0); 35 } 36 public Rectangle(Rectangle r) { 37 this(r.x, r.y, r.width, r.height); 38 } 39 public Rectangle(int x, int y, int width, int height) { 40 this.x = x; 41 this.y = y; 42 this.width = width; 43 this.height = height; 44 } 45 public Rectangle(int width, int height) { 46 this(0, 0, width, height); 47 } 48 public Rectangle(Point p, Dimension d) { 49 this(p.x, p.y, d.width, d.height); 50 } 51 public Rectangle(Point p) { 52 this(p.x, p.y, 0, 0); 53 } 54 public Rectangle(Dimension d) { 55 this(0, 0, d.width, d.height); 56 } 57 public double getX() { 58 return x; 59 } 60 public double getY() { 61 return y; 62 } 63 public double getWidth() { 64 return width; 65 } 66 public double getHeight() { 67 return height; 68 } 69 public Rectangle getBounds() { 70 return new Rectangle(x, y, width, height); 71 } 72 public Rectangle2D getBounds2D() { 73 return new Rectangle(x, y, width, height); 74 } 75 public void setBounds(Rectangle r) { 76 setBounds(r.x, r.y, r.width, r.height); 77 } 78 public void setBounds(int x, int y, int width, int height) { 79 reshape(x, y, width, height); 80 } 81 public void setRect(double x, double y, double width, double height) { 82 int x0 = (int) Math.floor(x); 83 int y0 = (int) Math.floor(y); 84 int x1 = (int) Math.ceil(x+width); 85 int y1 = (int) Math.ceil(y+height); 86 setBounds(x0, y0, x1-x0, y1-y0); 87 } 88 public void reshape(int x, int y, int width, int height) { 89 this.x = x; 90 this.y = y; 91 this.width = width; 92 this.height = height; 93 } 94 public Point getLocation() { 95 return new Point(x, y); 96 } 97 public void setLocation(Point p) { 98 setLocation(p.x, p.y); 99 } 100 public void setLocation(int x, int y) { 101 move(x, y); 102 } 103 public void move(int x, int y) { 104 this.x = x; 105 this.y = y; 106 } 107 public void translate(int x, int y) { 108 this.x += x; 109 this.y += y; 110 } 111 public Dimension getSize() { 112 return new Dimension(width, height); 113 } 114 public void setSize(Dimension d) { 115 setSize(d.width, d.height); 116 } 117 public void setSize(int width, int height) { 118 resize(width, height); 119 } 120 public void resize(int width, int height) { 121 this.width = width; 122 this.height = height; 123 } 124 public boolean contains(Point p) { 125 return contains(p.x, p.y); 126 } 127 public boolean contains(int x, int y) { 128 return inside(x, y); 129 } 130 public boolean contains(Rectangle r) { 131 return contains(r.x, r.y, r.width, r.height); 132 } 133 public boolean contains(int X, int Y, int W, int H) { 134 return false; 136 } 137 public boolean inside(int X, int Y) { 138 return false; 140 } 141 142 public boolean intersects(Rectangle r) { 143 return false; 145 } 146 147 public Rectangle intersection(Rectangle r) { 148 return null; 150 } 151 public boolean isEmpty() { 152 return (width <= 0) || (height <= 0); 153 } 154 155 public boolean equals(Object obj) { 156 if (obj instanceof Rectangle) { 157 Rectangle r = (Rectangle)obj; 158 return ((x == r.x) && 159 (y == r.y) && 160 (width == r.width) && 161 (height == r.height)); 162 } 163 return super.equals(obj); 164 } 165 public String toString() { 166 return getClass().getName() + "[x=" + x + ",y=" + y + ",width=" + width + ",height=" + height + "]"; 167 } 168 169 public boolean contains(Rectangle2D r) { 170 return contains((Rectangle) r); 171 } 172 173 public boolean contains(Point2D p) { 174 return contains((Point) p); 175 } 176 177 public boolean contains(double x, double y) { 178 return contains((int) x, (int) y); 179 } 180 181 public boolean contains(double x, double y, double w, double h) { 182 return contains((int) x, (int) y, (int) w, (int) h); 183 } 184 185 public boolean intersects(Rectangle2D r) { 186 return intersects((Rectangle) r); 187 } 188 189 public boolean intersects(double x, double y, double w, double h) { 190 return intersects((int) x, (int) y, (int) w, (int) h); 191 } 192 193 public Rectangle2D createIntersection(Rectangle2D r) { 194 return null; 196 } 197 198 199 public Rectangle2D createUnion(Rectangle2D r) { 200 return null; 202 } 203 204 public int outcode(double x, double y) { 205 return 0; 207 } 208 209 } 210 | Popular Tags |