KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > renderer > XYDotRenderer


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  * XYDotRenderer.java
24  * ------------------
25  * (C) Copyright 2002, 2003, by Object Refinery Limited.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited);
28  * Contributor(s): Christian W. Zuckschwerdt;
29 ;
30  *
31  * $Id: XYDotRenderer.java,v 1.16 2003/11/03 14:21:28 mungady Exp $
32  *
33  * Changes (from 29-Oct-2002)
34  * --------------------------
35  * 29-Oct-2002 : Added standard header (DG);
36  * 25-Mar-2003 : Implemented Serializable (DG);
37  * 01-May-2003 : Modified drawItem(...) method signature (DG);
38  * 30-Jul-2003 : Modified entity constructor (CZ);
39  * 20-Aug-2003 : Implemented Cloneable and PublicCloneable (DG);
40  * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG);
41  *
42  */

43
44 package org.jfree.chart.renderer;
45
46 import java.awt.Graphics2D JavaDoc;
47 import java.awt.geom.Rectangle2D JavaDoc;
48 import java.io.Serializable JavaDoc;
49
50 import org.jfree.chart.CrosshairInfo;
51 import org.jfree.chart.axis.ValueAxis;
52 import org.jfree.chart.plot.PlotOrientation;
53 import org.jfree.chart.plot.PlotRenderingInfo;
54 import org.jfree.chart.plot.XYPlot;
55 import org.jfree.data.XYDataset;
56 import org.jfree.ui.RectangleEdge;
57 import org.jfree.util.PublicCloneable;
58
59 /**
60  * A renderer that draws a small dot at each data point for an {@link XYPlot}.
61  *
62  * @author David Gilbert
63  */

64 public class XYDotRenderer extends AbstractXYItemRenderer implements XYItemRenderer,
65                                                                      Cloneable JavaDoc,
66                                                                      PublicCloneable,
67                                                                      Serializable JavaDoc {
68
69     /**
70      * Constructs a new renderer.
71      */

72     public XYDotRenderer() {
73
74     }
75
76     /**
77      * Draws the visual representation of a single data item.
78      *
79      * @param g2 the graphics device.
80      * @param state the renderer state.
81      * @param dataArea the area within which the data is being drawn.
82      * @param info collects information about the drawing.
83      * @param plot the plot (can be used to obtain standard color information etc).
84      * @param domainAxis the domain (horizontal) axis.
85      * @param rangeAxis the range (vertical) axis.
86      * @param dataset the dataset.
87      * @param series the series index (zero-based).
88      * @param item the item index (zero-based).
89      * @param crosshairInfo information about crosshairs on a plot.
90      * @param pass the pass index.
91      */

92     public void drawItem(Graphics2D JavaDoc g2,
93                          XYItemRendererState state,
94                          Rectangle2D JavaDoc dataArea,
95                          PlotRenderingInfo info,
96                          XYPlot plot,
97                          ValueAxis domainAxis,
98                          ValueAxis rangeAxis,
99                          XYDataset dataset,
100                          int series,
101                          int item,
102                          CrosshairInfo crosshairInfo,
103                          int pass) {
104
105         // get the data point...
106
Number JavaDoc xn = dataset.getXValue(series, item);
107         Number JavaDoc yn = dataset.getYValue(series, item);
108         if (yn != null) {
109             double x = xn.doubleValue();
110             double y = yn.doubleValue();
111             RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
112             RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
113             double transX = domainAxis.translateValueToJava2D(x, dataArea, xAxisLocation);
114             double transY = rangeAxis.translateValueToJava2D(y, dataArea, yAxisLocation);
115
116             g2.setPaint(this.getItemPaint(series, item));
117             PlotOrientation orientation = plot.getOrientation();
118             if (orientation == PlotOrientation.HORIZONTAL) {
119                 g2.drawRect((int) transY, (int) transX, 1, 1);
120             }
121             else if (orientation == PlotOrientation.VERTICAL) {
122                 g2.drawRect((int) transX, (int) transY, 1, 1);
123             }
124
125             // do we need to update the crosshair values?
126
if (plot.isDomainCrosshairLockedOnData()) {
127                 if (plot.isRangeCrosshairLockedOnData()) {
128                     // both axes
129
crosshairInfo.updateCrosshairPoint(x, y, transX, transY);
130                 }
131                 else {
132                     // just the horizontal axis...
133
crosshairInfo.updateCrosshairX(x);
134                 }
135             }
136             else {
137                 if (plot.isRangeCrosshairLockedOnData()) {
138                     // just the vertical axis...
139
crosshairInfo.updateCrosshairY(y);
140                 }
141             }
142         }
143
144     }
145
146     /**
147      * Returns a clone of the renderer.
148      *
149      * @return A clone.
150      *
151      * @throws CloneNotSupportedException if the renderer cannot be cloned.
152      */

153     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
154         return super.clone();
155     }
156
157 }
158
Popular Tags