KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwt > awt > geom > Rectangle2D


1 /*
2    SwingWT
3    Copyright(c)2003-2004, R. Rawson-Tetley
4
5    For more information on distributing and using this program, please
6    see the accompanying "COPYING" file.
7
8    Contact me by electronic mail: bobintetley@users.sourceforge.net
9
10    $Log: Rectangle2D.java,v $
11    Revision 1.3 2004/04/21 10:44:31 bobintetley
12    Code cleanup and native build script fix
13
14    Revision 1.2 2004/04/20 16:36:14 bobintetley
15    Code cleanup
16
17    Revision 1.1 2004/01/15 15:20:29 bobintetley
18    Java2D work
19
20
21 */

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         // FIXME: Implement
41
return false;
42     }
43     public boolean intersectsLine(Line2D l) {
44     // FIXME: Implement
45
return false;
46     }
47     public abstract int outcode(double x, double y);
48     
49     public int outcode(Point2D p) {
50         // FIXME: Implement
51
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         //FIXME: Implement
67
return false;
68     }
69     public boolean contains(double x, double y, double w, double h) {
70     //FIXME: Implement
71
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     // FIXME: Implement
96
return null;
97     }
98     public PathIterator getPathIterator(AffineTransform at, double flatness) {
99     // FIXME: Implement
100
return null;
101     }
102     public boolean equals(Object JavaDoc 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             // FIXME: Implement
158
return 0;
159     }
160     public Rectangle2D getBounds2D() {
161         return new Double JavaDoc(x, y, width, height);
162     }
163     public Rectangle2D createIntersection(Rectangle2D r) {
164         // FIXME: Implement
165
return null;
166     }
167     public Rectangle2D createUnion(Rectangle2D r) {
168         // FIXME: Implement
169
return null;
170     }
171     public String JavaDoc 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         // FIXME: Implement
225
return 0;
226     }
227     public Rectangle2D getBounds2D() {
228             // FIXME: Implement
229
return null;
230     }
231     public Rectangle2D createIntersection(Rectangle2D r) {
232             // FIXME: Implement
233
return null;
234     }
235     public Rectangle2D createUnion(Rectangle2D r) {
236             // FIXME: Implement
237
return null;
238     }
239     public String JavaDoc toString() {
240         return getClass().getName()
241         + "[x=" + x +
242         ",y=" + y +
243         ",w=" + width +
244         ",h=" + height + "]";
245     }
246     }
247
248 }
249
Popular Tags