KickJava   Java API By Example, From Geeks To Geeks.

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


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  * YIntervalRenderer.java
24  * ----------------------
25  * (C) Copyright 2002, 2003, by Object Refinery Limited.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited);
28  * Contributor(s): -;
29  *
30  * $Id: YIntervalRenderer.java,v 1.17 2003/11/03 14:21:28 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 05-Nov-2002 : Version 1 (DG);
35  * 25-Mar-2003 : Implemented Serializable (DG);
36  * 01-May-2003 : Modified drawItem(...) method signature (DG);
37  * 20-Aug-2003 : Implemented Cloneable and PublicCloneable (DG);
38  * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG);
39  *
40  */

41
42 package org.jfree.chart.renderer;
43
44 import java.awt.Graphics2D JavaDoc;
45 import java.awt.Paint JavaDoc;
46 import java.awt.Shape JavaDoc;
47 import java.awt.Stroke JavaDoc;
48 import java.awt.geom.Line2D JavaDoc;
49 import java.awt.geom.Rectangle2D JavaDoc;
50 import java.io.Serializable JavaDoc;
51
52 import org.jfree.chart.CrosshairInfo;
53 import org.jfree.chart.axis.ValueAxis;
54 import org.jfree.chart.entity.EntityCollection;
55 import org.jfree.chart.entity.XYItemEntity;
56 import org.jfree.chart.labels.XYToolTipGenerator;
57 import org.jfree.chart.plot.PlotOrientation;
58 import org.jfree.chart.plot.PlotRenderingInfo;
59 import org.jfree.chart.plot.XYPlot;
60 import org.jfree.data.IntervalXYDataset;
61 import org.jfree.data.XYDataset;
62 import org.jfree.ui.RectangleEdge;
63 import org.jfree.util.PublicCloneable;
64
65 /**
66  * A renderer that draws a line connecting the start and end Y values for an {@link XYPlot}.
67  *
68  * @author David Gilbert
69  */

70 public class YIntervalRenderer extends AbstractXYItemRenderer implements XYItemRenderer,
71                                                                          Cloneable JavaDoc,
72                                                                          PublicCloneable,
73                                                                          Serializable JavaDoc {
74
75     /**
76      * The default constructor.
77      */

78     public YIntervalRenderer() {
79         super();
80     }
81
82     /**
83      * Creates a new renderer with the specified tool tip generator.
84      *
85      * @param toolTipGenerator the tool tip generator.
86      *
87      * @deprecated Use default constructor.
88      */

89     public YIntervalRenderer(XYToolTipGenerator toolTipGenerator) {
90         super();
91         setToolTipGenerator(toolTipGenerator);
92     }
93
94     /**
95      * Draws the visual representation of a single data item.
96      *
97      * @param g2 the graphics device.
98      * @param state the renderer state.
99      * @param dataArea the area within which the plot is being drawn.
100      * @param info collects information about the drawing.
101      * @param plot the plot (can be used to obtain standard color information etc).
102      * @param domainAxis the domain axis.
103      * @param rangeAxis the range axis.
104      * @param dataset the dataset.
105      * @param series the series index (zero-based).
106      * @param item the item index (zero-based).
107      * @param crosshairInfo information about crosshairs on a plot.
108      * @param pass the pass index (ignored here).
109      */

110     public void drawItem(Graphics2D JavaDoc g2,
111                          XYItemRendererState state,
112                          Rectangle2D JavaDoc dataArea,
113                          PlotRenderingInfo info,
114                          XYPlot plot,
115                          ValueAxis domainAxis,
116                          ValueAxis rangeAxis,
117                          XYDataset dataset,
118                          int series,
119                          int item,
120                          CrosshairInfo crosshairInfo,
121                          int pass) {
122
123         // setup for collecting optional entity info...
124
Shape JavaDoc entityArea = null;
125         EntityCollection entities = null;
126         if (info != null) {
127             entities = info.getOwner().getEntityCollection();
128         }
129
130         IntervalXYDataset intervalData = (IntervalXYDataset) dataset;
131
132         Number JavaDoc x = intervalData.getXValue(series, item);
133         Number JavaDoc yLow = intervalData.getStartYValue(series, item);
134         Number JavaDoc yHigh = intervalData.getEndYValue(series, item);
135
136         RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
137         RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
138         
139         double xx = domainAxis.translateValueToJava2D(x.doubleValue(), dataArea, xAxisLocation);
140         double yyLow
141             = rangeAxis.translateValueToJava2D(yLow.doubleValue(), dataArea, yAxisLocation);
142         double yyHigh
143             = rangeAxis.translateValueToJava2D(yHigh.doubleValue(), dataArea, yAxisLocation);
144
145         Paint JavaDoc p = getItemPaint(series, item);
146         Stroke JavaDoc s = getItemStroke(series, item);
147         
148         Line2D JavaDoc line = null;
149         Shape JavaDoc shape = getItemShape(series, item);
150         Shape JavaDoc top = null;
151         Shape JavaDoc bottom = null;
152         PlotOrientation orientation = plot.getOrientation();
153         if (orientation == PlotOrientation.HORIZONTAL) {
154             line = new Line2D.Double JavaDoc(yyLow, xx, yyHigh, xx);
155             top = createTransformedShape(shape, yyHigh, xx);
156             bottom = createTransformedShape(shape, yyLow, xx);
157         }
158         else if (orientation == PlotOrientation.VERTICAL) {
159             line = new Line2D.Double JavaDoc(xx, yyLow, xx, yyHigh);
160             top = createTransformedShape(shape, xx, yyHigh);
161             bottom = createTransformedShape(shape, xx, yyLow);
162         }
163         g2.setPaint(p);
164         g2.setStroke(s);
165         g2.draw(line);
166
167         g2.fill(top);
168         g2.fill(bottom);
169
170         // add an entity for the item...
171
if (entities != null) {
172             if (entityArea == null) {
173                 entityArea = line.getBounds();
174             }
175             String JavaDoc tip = null;
176             if (getToolTipGenerator() != null) {
177                 tip = getToolTipGenerator().generateToolTip(dataset, series, item);
178             }
179             String JavaDoc url = null;
180             if (getURLGenerator() != null) {
181                 url = getURLGenerator().generateURL(dataset, series, item);
182             }
183             XYItemEntity entity = new XYItemEntity(entityArea, dataset, series, item, tip, url);
184             entities.addEntity(entity);
185         }
186
187     }
188     
189     /**
190      * Returns a clone of the renderer.
191      *
192      * @return A clone.
193      *
194      * @throws CloneNotSupportedException if the renderer cannot be cloned.
195      */

196     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
197         return super.clone();
198     }
199
200 }
201
Popular Tags