View Javadoc

1   /*
2    * SerializableGeneralPath.java
3    * 
4    * Created on December 8, 2001, 12:57 PM Last edited on October 11, 2002
5    */
6   package nl.javel.gisbeans.geom;
7   
8   import java.awt.geom.Rectangle2D;
9   import java.io.IOException;
10  
11  /***
12   * The SerializableRectangle2D class is a serializable version of the
13   * <code>java.awt.geom.Rectangle2D</code> class.
14   * 
15   * @author <a href="mailto:peter.jacobs@javel.nl">Peter Jacobs </a> <br>
16   *         <a href="mailto:paul.jacobs@javel.nl">Paul Jacobs </a>
17   * @since JDK 1.2
18   * @version 1.0
19   */
20  public abstract class SerializableRectangle2D extends java.awt.geom.Rectangle2D
21  		implements java.io.Serializable, java.awt.Shape, java.lang.Cloneable
22  {
23  
24  	/***
25  	 * constructs a new nl.javel.gisbeans.geom.SerializableRectangle2D
26  	 */
27  	protected SerializableRectangle2D()
28  	{
29  		super();
30  	}
31  
32  	/***
33  	 * The SerializableRectangle2D.Double class is a serializable version of the
34  	 * <code>java.awt.geom.Rectangle2D.Double</code> class.
35  	 * 
36  	 * @author <a href="mailto:peter.jacobs@javel.nl">Peter Jacobs </a> <br>
37  	 *         <a href="mailto:paul.jacobs@javel.nl">Paul Jacobs </a>
38  	 * @since JDK 1.2
39  	 * @version 1.0
40  	 */
41  	public static class Double extends SerializableRectangle2D
42  	{
43  
44  		/*** the rectangle */
45  		private Rectangle2D rectangle;
46  
47  		/***
48  		 * constructs a new
49  		 * nl.javel.gisbeans.geom.SerializableRectangle2D.Double
50  		 */
51  		public Double()
52  		{
53  			this.rectangle = new Rectangle2D.Double();
54  		}
55  
56  		/***
57  		 * constructs a new Double
58  		 * 
59  		 * @param x
60  		 * @param y
61  		 * @param w
62  		 * @param h
63  		 */
64  		public Double(final double x, final double y, final double w,
65  				final double h)
66  		{
67  			this.rectangle = new Rectangle2D.Double(x, y, w, h);
68  		}
69  
70  		/***
71  		 * @see java.awt.geom.Rectangle2D#createIntersection(java.awt.geom.Rectangle2D)
72  		 */
73  		public Rectangle2D createIntersection(final Rectangle2D r)
74  		{
75  			return this.rectangle.createIntersection(r);
76  		}
77  
78  		/***
79  		 * @see java.awt.geom.Rectangle2D#createUnion(java.awt.geom.Rectangle2D)
80  		 */
81  		public Rectangle2D createUnion(final Rectangle2D r)
82  		{
83  			return this.rectangle.createUnion(r);
84  		}
85  
86  		/***
87  		 * @see java.awt.Shape#getBounds2D()
88  		 */
89  		public Rectangle2D getBounds2D()
90  		{
91  			return this.rectangle.getBounds2D();
92  		}
93  
94  		/***
95  		 * @see java.awt.geom.RectangularShape#getHeight()
96  		 */
97  		public double getHeight()
98  		{
99  			return this.rectangle.getHeight();
100 		}
101 
102 		/***
103 		 * @see java.awt.geom.RectangularShape#getWidth()
104 		 */
105 		public double getWidth()
106 		{
107 			return this.rectangle.getWidth();
108 		}
109 
110 		/***
111 		 * @see java.awt.geom.RectangularShape#getX()
112 		 */
113 		public double getX()
114 		{
115 			return this.rectangle.getX();
116 		}
117 
118 		/***
119 		 * @see java.awt.geom.RectangularShape#getY()
120 		 */
121 		public double getY()
122 		{
123 			return this.rectangle.getY();
124 		}
125 
126 		/***
127 		 * @see java.awt.geom.RectangularShape#isEmpty()
128 		 */
129 		public boolean isEmpty()
130 		{
131 			return this.rectangle.isEmpty();
132 		}
133 
134 		/***
135 		 * @see java.awt.geom.Rectangle2D#outcode(double, double)
136 		 */
137 		public int outcode(final double x, final double y)
138 		{
139 			return this.rectangle.outcode(x, y);
140 		}
141 
142 		/***
143 		 * @see java.awt.geom.Rectangle2D#setRect(double, double, double,
144 		 *      double)
145 		 */
146 		public void setRect(final double x, final double y, final double w,
147 				final double h)
148 		{
149 			this.rectangle.setRect(x, y, w, h);
150 		}
151 
152 		/***
153 		 * @see java.awt.geom.Rectangle2D#setRect(java.awt.geom.Rectangle2D)
154 		 */
155 		public void setRect(final Rectangle2D r)
156 		{
157 			this.rectangle.setRect(r);
158 		}
159 
160 		/***
161 		 * @see java.lang.Object#toString()
162 		 */
163 		public String toString()
164 		{
165 			return this.rectangle.toString();
166 		}
167 
168 		/***
169 		 * Now the private serialization methods
170 		 * 
171 		 * @param out the outputstream
172 		 * @throws java.io.IOException on exception
173 		 */
174 		private void writeObject(final java.io.ObjectOutputStream out)
175 				throws java.io.IOException
176 		{
177 			out.writeDouble(this.rectangle.getX());
178 			out.writeDouble(this.rectangle.getY());
179 			out.writeDouble(this.rectangle.getWidth());
180 			out.writeDouble(this.rectangle.getHeight());
181 		}
182 
183 		/***
184 		 * we read the stream
185 		 * 
186 		 * @param in the input
187 		 * @throws java.io.IOException on exception
188 		 */
189 		private void readObject(final java.io.ObjectInputStream in)
190 				throws java.io.IOException
191 		{
192 			this.rectangle = new Rectangle2D.Double(in.readDouble(), in
193 					.readDouble(), in.readDouble(), in.readDouble());
194 		}
195 	}
196 
197 	/***
198 	 * The SerializableRectangle2D.Float class is a serializable version of the
199 	 * <code>java.awt.geom.Rectangle2D.Double</code> class.
200 	 * 
201 	 * @author <a href="mailto:peter.jacobs@javel.nl">Peter Jacobs </a> <br>
202 	 *         <a href="mailto:paul.jacobs@javel.nl">Paul Jacobs </a>
203 	 * @since JDK 1.2
204 	 * @version 1.0
205 	 */
206 	public static class Float extends SerializableRectangle2D
207 	{
208 
209 		/*** the rectangle */
210 		private Rectangle2D rectangle;
211 
212 		/***
213 		 * constructs a new nl.javel.gisbeans.geom.SerializableRectangle2D.Float
214 		 */
215 		public Float()
216 		{
217 			this.rectangle = new Rectangle2D.Float();
218 		}
219 
220 		/***
221 		 * constructs a new nl.javel.gisbeans.geom.SerializableRectangle2D.Float
222 		 * 
223 		 * @param x the x
224 		 * @param y the y
225 		 * @param w the width
226 		 * @param h the height
227 		 */
228 		public Float(final float x, final float y, final float w, final float h)
229 		{
230 			this.rectangle = new Rectangle2D.Float(x, y, w, h);
231 		}
232 
233 		/***
234 		 * @see java.awt.geom.Rectangle2D#createIntersection(java.awt.geom.Rectangle2D)
235 		 */
236 		public Rectangle2D createIntersection(final Rectangle2D r)
237 		{
238 			return this.rectangle.createIntersection(r);
239 		}
240 
241 		/***
242 		 * @see java.awt.geom.Rectangle2D#createUnion(java.awt.geom.Rectangle2D)
243 		 */
244 		public Rectangle2D createUnion(final Rectangle2D r)
245 		{
246 			return this.rectangle.createUnion(r);
247 		}
248 
249 		/***
250 		 * @see java.awt.Shape#getBounds2D()
251 		 */
252 		public Rectangle2D getBounds2D()
253 		{
254 			return this.rectangle.getBounds2D();
255 		}
256 
257 		/***
258 		 * @see java.awt.geom.RectangularShape#getHeight()
259 		 */
260 		public double getHeight()
261 		{
262 			return this.rectangle.getHeight();
263 		}
264 
265 		/***
266 		 * @see java.awt.geom.RectangularShape#getWidth()
267 		 */
268 		public double getWidth()
269 		{
270 			return this.rectangle.getWidth();
271 		}
272 
273 		/***
274 		 * @see java.awt.geom.RectangularShape#getX()
275 		 */
276 		public double getX()
277 		{
278 			return this.rectangle.getX();
279 		}
280 
281 		/***
282 		 * @see java.awt.geom.RectangularShape#getY()
283 		 */
284 		public double getY()
285 		{
286 			return this.rectangle.getY();
287 		}
288 
289 		/***
290 		 * @see java.awt.geom.RectangularShape#isEmpty()
291 		 */
292 		public boolean isEmpty()
293 		{
294 			return this.rectangle.isEmpty();
295 		}
296 
297 		/***
298 		 * @see java.awt.geom.Rectangle2D#outcode(double, double)
299 		 */
300 		public int outcode(final double x, final double y)
301 		{
302 			return this.rectangle.outcode(x, y);
303 		}
304 
305 		/***
306 		 * @param x
307 		 * @param y
308 		 * @param w
309 		 * @param h
310 		 */
311 		public void setRect(final float x, final float y, final float w,
312 				final float h)
313 		{
314 			this.rectangle.setRect(x, y, w, h);
315 		}
316 
317 		/***
318 		 * @see java.awt.geom.Rectangle2D#setRect(double, double, double,
319 		 *      double)
320 		 */
321 		public void setRect(final double x, final double y, final double w,
322 				final double h)
323 		{
324 			this.rectangle.setRect(x, y, w, h);
325 		}
326 
327 		/***
328 		 * @see java.awt.geom.Rectangle2D#setRect(java.awt.geom.Rectangle2D)
329 		 */
330 		public void setRect(final Rectangle2D r)
331 		{
332 			this.rectangle.setRect(r);
333 		}
334 
335 		/***
336 		 * @see java.lang.Object#toString()
337 		 */
338 		public String toString()
339 		{
340 			return this.rectangle.toString();
341 		}
342 
343 		/***
344 		 * writes to the stream
345 		 * 
346 		 * @param out the stream
347 		 * @throws IOException on IOException
348 		 */
349 		private void writeObject(final java.io.ObjectOutputStream out)
350 				throws IOException
351 		{
352 			out.writeDouble(this.rectangle.getX());
353 			out.writeDouble(this.rectangle.getY());
354 			out.writeDouble(this.rectangle.getWidth());
355 			out.writeDouble(this.rectangle.getHeight());
356 		}
357 
358 		/***
359 		 * Now the private serialization methods
360 		 * 
361 		 * @param in the stream
362 		 * @throws IOException on IOException
363 		 */
364 		private void readObject(final java.io.ObjectInputStream in)
365 				throws IOException
366 		{
367 			this.rectangle = new Rectangle2D.Float();
368 			this.rectangle.setRect(in.readDouble(), in.readDouble(), in
369 					.readDouble(), in.readDouble());
370 		}
371 	}
372 }