source: ether_statistics/service/implementation/gov/noaa/pmel/util/Rectangle2D.java @ 569

Last change on this file since 569 was 569, checked in by vmipsl, 12 years ago

Nouveau projet

File size: 6.2 KB
Line 
1/*
2 * $Id: Rectangle2D.java,v 1.5 2003/08/22 23:02:40 dwd Exp $
3 *
4 * This software is provided by NOAA for full, free and open release.  It is
5 * understood by the recipient/user that NOAA assumes no liability for any
6 * errors contained in the code.  Although this software is released without
7 * conditions or restrictions in its use, it is expected that appropriate
8 * credit be given to its author and to the National Oceanic and Atmospheric
9 * Administration should the software be included by the recipient as an
10 * element in other product development.
11 */
12
13package  gov.noaa.pmel.util;
14
15import java.io.Serializable;
16
17/**
18 * Rectangle2D will be part of java.java2d
19 *
20 * @author Donald Denbo
21 * @version $Revision: 1.5 $, $Date: 2003/08/22 23:02:40 $
22 * @since sgt 1.0
23 */
24public abstract class Rectangle2D implements Serializable, Cloneable {
25  /**
26   * Inner class that implements <code>Rectangle2D</code> for
27   * type <code>double</code>.
28   *
29   * @since sgt 1.0
30   */
31  public static class Double extends Rectangle2D {
32    /** height of rectangle */
33    public double height;
34    /** width of rectangle */
35    public double width;
36    /** x coordinate of rectangle */
37    public double x;
38    /** y coordinate of rectangle */
39    public double y;
40    /**
41     * Default constructor
42     */
43    public Double() {
44    }
45    public Double(double x,double y,double width,double height) {
46      this.x = x;
47      this.y = y;
48      this.width = width;
49      this.height = height;
50    }
51    public Double(double width,double height) {
52      this.width = width;
53      this.height = height;
54    }
55    public Double(Rectangle2D.Double r) {
56      x = r.x;
57      y = r.y;
58      width = r.width;
59      height = r.height;
60    }
61    /**
62     * Test for equality. Height, width, x, and y must be equal for
63     * equality.
64     */
65    public boolean equals(Rectangle2D.Double r) {
66      return !(x != r.x ||
67              y != r.y ||
68              width != r.width ||
69              height != r.height);
70    }
71    public boolean equals(Object r) {
72      if(r instanceof Rectangle2D.Double) {
73        Rectangle2D.Double r2 = (Rectangle2D.Double)r;
74        return !(x != r2.x ||
75                y != r2.y ||
76                width != r2.width ||
77                height != r2.height);
78      } else {
79        return false;
80      }
81    }
82    public String toString() {
83        String result;
84        result = "[x=" + x + ",y=" + y + ",width=" + width + ",height=" + height + "]";
85        return result;
86    }
87    /**
88     * @since 3.0
89     */
90    public void setWidth(double w) {
91      width = w;
92    }
93    /**
94     * @since 3.0
95     */
96    public double getWidth() {
97      return width;
98    }
99    /**
100     * @since 3.0
101     */
102    public void setHeight(double h) {
103      height = h;
104    }
105    /**
106     * @since 3.0
107     */
108    public double getHeight() {
109      return height;
110    }
111    /**
112     * @since 3.0
113     */
114    public void setX(double x) {
115      this.x = x;
116    }
117    /**
118     * @since 3.0
119     */
120    public double getX() {
121      return x;
122    }
123    /**
124     * @since 3.0
125     */
126    public void setY(double y) {
127      this.y = y;
128    }
129    /**
130     * @since 3.0
131     */
132    public double getY() {
133      return y;
134    }
135    /**
136     * Make a copy of the <code>Rectangle2D</code>.
137     */
138    public Rectangle2D copy() {
139      try {
140        return (Rectangle2D)clone();
141      } catch (CloneNotSupportedException e) {
142        return null;
143      }
144    }
145  }
146  /**
147   * Inner class that implements <code>Rectangle2D</code> for
148   * type <code>float</code>.
149   *
150   * @since sgt 1.0
151   */
152  public static class Float extends Rectangle2D {
153    /** height of rectangle */
154    public float height;
155    /** width of rectangle */
156    public float width;
157    /** x coordinate of rectangle */
158    public float x;
159    /** y coordinate of rectangle */
160    public float y;
161    /**
162     * Default constructor
163     */
164    public Float() {
165    }
166    public Float(float x,float y,float width,float height) {
167      this.x = x;
168      this.y = y;
169      this.width = width;
170      this.height = height;
171    }
172    public Float(float width,float height) {
173      this.width = width;
174      this.height = height;
175    }
176    public Float(Rectangle2D.Float r) {
177      x = r.x;
178      y = r.y;
179      width = r.width;
180      height = r.height;
181    }
182    /**
183     * Test for equality. Height, width, x, and y must be equal for
184     * equality.
185     */
186    public boolean equals(Rectangle2D.Float r) {
187      return !(x != r.x ||
188              y != r.y ||
189              width != r.width ||
190              height != r.height);
191    }
192    public boolean equals(Object r) {
193      if(r instanceof Rectangle2D.Float) {
194        Rectangle2D.Float r2 = (Rectangle2D.Float)r;
195        return !(x != r2.x ||
196                y != r2.y ||
197                width != r2.width ||
198                height != r2.height);
199      } else {
200        return false;
201      }
202    }
203    public String toString() {
204        String result;
205        result = "[x=" + x + ",y=" + y + ",width=" + width + ",height=" + height + "]";
206        return result;
207    }
208    /**
209     * @since 3.0
210     */
211    public void setWidth(float w) {
212      width = w;
213    }
214    /**
215     * @since 3.0
216     */
217    public float getWidth() {
218      return width;
219    }
220    /**
221     * @since 3.0
222     */
223    public void setHeight(float h) {
224      height = h;
225    }
226    /**
227     * @since 3.0
228     */
229    public float getHeight() {
230      return height;
231    }
232    /**
233     * @since 3.0
234     */
235    public void setX(float x) {
236      this.x = x;
237    }
238    /**
239     * @since 3.0
240     */
241    public float getX() {
242      return x;
243    }
244    /**
245     * @since 3.0
246     */
247    public void setY(float y) {
248      this.y = y;
249    }
250    /**
251     * @since 3.0
252     */
253    public float getY() {
254      return y;
255    }
256    /**
257     * Make a copy of the <code>Rectangle2D</code>.
258     */
259    public Rectangle2D copy() {
260      try {
261        return (Rectangle2D)clone();
262      } catch (CloneNotSupportedException e) {
263        return null;
264      }
265    }
266  }
267  /**
268   * This is an abstract class that cannot be instantiated directly.
269   * Type-specific implementation subclasses are available for
270   * instantiation and provide a number of formats for storing
271   * the information necessary to satisfy the various accessor
272   * methods below.
273   *
274   */
275  protected Rectangle2D() { }
276  public abstract Rectangle2D copy();
277}
278
279
Note: See TracBrowser for help on using the repository browser.