KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > demo > CircleDrawer


1 /* ======================================
2  * JFreeChart : a free Java chart library
3  * ======================================
4  *
5  * Project Info: http://www.jfree.org/jfreechart/index.html
6  * Project Lead: David Gilbert (david.gilbert@object-refinery.com);
7  *
8  * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it under the terms
11  * of the GNU Lesser General Public License as published by the Free Software Foundation;
12  * either version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License along with this
19  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * -----------------
23  * CircleDrawer.java
24  * -----------------
25  * (C) Copyright 2003, by Object Refinery Limited and Contributors.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited);
28  * Contributor(s): -;
29  *
30  * $Id: CircleDrawer.java,v 1.5 2003/11/28 10:09:20 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 21-May-2003 : Version 1 (DG);
35  *
36  */

37
38 package org.jfree.chart.demo;
39
40 import java.awt.BasicStroke JavaDoc;
41 import java.awt.Color JavaDoc;
42 import java.awt.Graphics2D JavaDoc;
43 import java.awt.Paint JavaDoc;
44 import java.awt.Stroke JavaDoc;
45 import java.awt.geom.Ellipse2D JavaDoc;
46 import java.awt.geom.Line2D JavaDoc;
47 import java.awt.geom.Rectangle2D JavaDoc;
48
49 import org.jfree.ui.Drawable;
50
51 /**
52  * An implementation of the {@link Drawable} interface, to illustrate the use of the
53  * {@link XYDrawableAnnotation} class.
54  *
55  * @author David Gilbert
56  */

57 public class CircleDrawer implements Drawable {
58
59     /** The outline paint. */
60     private Paint JavaDoc outlinePaint;
61
62     /** The outline stroke. */
63     private Stroke JavaDoc outlineStroke;
64
65     /** The fill paint. */
66     private Paint JavaDoc fillPaint;
67
68     /**
69      * Creates a new instance.
70      *
71      * @param outlinePaint the outline paint.
72      * @param outlineStroke the outline stroke.
73      * @param fillPaint the fill paint.
74      */

75     public CircleDrawer(Paint JavaDoc outlinePaint, Stroke JavaDoc outlineStroke, Paint JavaDoc fillPaint) {
76         this.outlinePaint = outlinePaint;
77         this.outlineStroke = outlineStroke;
78         this.fillPaint = fillPaint;
79     }
80
81     /**
82      * Draws the circle.
83      *
84      * @param g2 the graphics device.
85      * @param area the area in which to draw.
86      */

87     public void draw(Graphics2D JavaDoc g2, Rectangle2D JavaDoc area) {
88         Ellipse2D JavaDoc ellipse = new Ellipse2D.Double JavaDoc(area.getX(), area.getY(),
89                                                  area.getWidth(), area.getHeight());
90         if (this.fillPaint != null) {
91             g2.setPaint(this.fillPaint);
92             g2.fill(ellipse);
93         }
94         if (this.outlinePaint != null && this.outlineStroke != null) {
95             g2.setPaint(this.outlinePaint);
96             g2.setStroke(this.outlineStroke);
97             g2.draw(ellipse);
98         }
99
100         g2.setPaint(Color.black);
101         g2.setStroke(new BasicStroke JavaDoc(1.0f));
102         Line2D JavaDoc line1 = new Line2D.Double JavaDoc(area.getCenterX(), area.getMinY(),
103                                          area.getCenterX(), area.getMaxY());
104         Line2D JavaDoc line2 = new Line2D.Double JavaDoc(area.getMinX(), area.getCenterY(),
105                                          area.getMaxX(), area.getCenterY());
106         g2.draw(line1);
107         g2.draw(line2);
108     }
109 }
110
Popular Tags