KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jcckit > graphic > Rectangle


1 /*
2  * Copyright 2003-2004, Franz-Josef Elmer, All rights reserved
3  *
4  * This library is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation; either version 2.1 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details
13  * (http://www.gnu.org/copyleft/lesser.html).
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package jcckit.graphic;
20
21 /**
22  * A rectangle.
23  *
24  * @author Franz-Josef Elmer
25  */

26 public class Rectangle extends BasicGraphicalElement {
27   private final GraphPoint _center;
28   private final double _width;
29   private final double _height;
30
31   /**
32    * Creates a new instance.
33    * @param center The position of the center of this element.
34    * @param width The width.
35    * @param height The height.
36    * @param attributes Drawing attributes. Can be <tt>null</tt>.
37    */

38   public Rectangle(GraphPoint center, double width, double height,
39                    GraphicAttributes attributes) {
40     super(attributes);
41     _center = center;
42     _width = width;
43     _height = height;
44   }
45
46   /** Returns the center of this element. */
47   public GraphPoint getCenter() {
48     return _center;
49   }
50
51   /** Returns the width of this element. */
52   public double getWidth() {
53     return _width;
54   }
55
56   /** Returns the height of this element. */
57   public double getHeight() {
58     return _height;
59   }
60
61   /**
62    * Renders this rectangle with the specified {@link Renderer}.
63    * @param renderer An instance of {@link RectangleRenderer}.
64    * @throws IllegalArgumentException if <tt>renderer</tt> is not
65    * an instance of <tt>RectangleRenderer</tt>.
66    */

67   public void renderWith(Renderer renderer) {
68     if (renderer instanceof RectangleRenderer) {
69       ((RectangleRenderer) renderer).render(this);
70     } else {
71       throw new IllegalArgumentException JavaDoc(renderer
72                             + " does not implements RectangleRenderer.");
73     }
74   }
75 }
76
77
Popular Tags