KickJava   Java API By Example, From Geeks To Geeks.

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


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  * HighLowRenderer.java
24  * --------------------
25  * (C) Copyright 2001-2003, by Object Refinery Limited.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited);
28  * Contributor(s): Richard Atkinson;
29  * Christian W. Zuckschwerdt;
30  *
31  * $Id: HighLowRenderer.java,v 1.16 2003/11/03 14:21:27 mungady Exp $
32  *
33  * Changes
34  * -------
35  * 13-Dec-2001 : Version 1 (DG);
36  * 23-Jan-2002 : Added DrawInfo parameter to drawItem(...) method (DG);
37  * 28-Mar-2002 : Added a property change listener mechanism so that renderers no longer need to be
38  * immutable (DG);
39  * 09-Apr-2002 : Removed translatedRangeZero from the drawItem(...) method, and changed the return
40  * type of the drawItem method to void, reflecting a change in the XYItemRenderer
41  * interface. Added tooltip code to drawItem(...) method (DG);
42  * 05-Aug-2002 : Small modification to drawItem method to support URLs for HTML image maps (RA);
43  * 25-Mar-2003 : Implemented Serializable (DG);
44  * 01-May-2003 : Modified drawItem(...) method signature (DG);
45  * 30-Jul-2003 : Modified entity constructor (CZ);
46  * 31-Jul-2003 : Deprecated constructor (DG);
47  * 20-Aug-2003 : Implemented Cloneable and PublicCloneable (DG);
48  * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG);
49  *
50  */

51
52 package org.jfree.chart.renderer;
53
54 import java.awt.Graphics2D JavaDoc;
55 import java.awt.Paint JavaDoc;
56 import java.awt.Shape JavaDoc;
57 import java.awt.Stroke JavaDoc;
58 import java.awt.geom.Line2D JavaDoc;
59 import java.awt.geom.Rectangle2D JavaDoc;
60 import java.io.Serializable JavaDoc;
61
62 import org.jfree.chart.CrosshairInfo;
63 import org.jfree.chart.axis.ValueAxis;
64 import org.jfree.chart.entity.EntityCollection;
65 import org.jfree.chart.entity.XYItemEntity;
66 import org.jfree.chart.labels.XYToolTipGenerator;
67 import org.jfree.chart.plot.PlotRenderingInfo;
68 import org.jfree.chart.plot.XYPlot;
69 import org.jfree.data.HighLowDataset;
70 import org.jfree.data.XYDataset;
71 import org.jfree.ui.RectangleEdge;
72 import org.jfree.util.PublicCloneable;
73
74 /**
75  * A renderer that draws high/low/open/close markers on an {@link XYPlot} (requires
76  * a {@link HighLowDataset}).
77  *
78  * @author David Gilbert
79  */

80 public class HighLowRenderer extends AbstractXYItemRenderer implements XYItemRenderer,
81                                                                        Cloneable JavaDoc,
82                                                                        PublicCloneable,
83                                                                        Serializable JavaDoc {
84
85     /**
86      * The default constructor.
87      */

88     public HighLowRenderer() {
89         super();
90     }
91
92     /**
93      * Creates a new renderer with the specified tool tip generator.
94      *
95      * @param toolTipGenerator the tool tip generator.
96      *
97      * @deprecated Use default constructor then set tooltip generator.
98      */

99     public HighLowRenderer(XYToolTipGenerator toolTipGenerator) {
100         super();
101         setToolTipGenerator(toolTipGenerator);
102     }
103
104     /**
105      * Draws the visual representation of a single data item.
106      *
107      * @param g2 the graphics device.
108      * @param state the renderer state.
109      * @param dataArea the area within which the plot is being drawn.
110      * @param info collects information about the drawing.
111      * @param plot the plot (can be used to obtain standard color information etc).
112      * @param domainAxis the domain axis.
113      * @param rangeAxis the range axis.
114      * @param dataset the dataset.
115      * @param series the series index (zero-based).
116      * @param item the item index (zero-based).
117      * @param crosshairInfo information about crosshairs on a plot.
118      * @param pass the pass index.
119      */

120     public void drawItem(Graphics2D JavaDoc g2,
121                          XYItemRendererState state,
122                          Rectangle2D JavaDoc dataArea,
123                          PlotRenderingInfo info,
124                          XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis,
125                          XYDataset dataset, int series, int item,
126                          CrosshairInfo crosshairInfo,
127                          int pass) {
128
129         // setup for collecting optional entity info...
130
Shape JavaDoc entityArea = null;
131         EntityCollection entities = null;
132         if (info != null) {
133             entities = info.getOwner().getEntityCollection();
134         }
135
136         HighLowDataset highLowData = (HighLowDataset) dataset;
137
138         Number JavaDoc x = highLowData.getXValue(series, item);
139         Number JavaDoc yHigh = highLowData.getHighValue(series, item);
140         Number JavaDoc yLow = highLowData.getLowValue(series, item);
141         Number JavaDoc yOpen = highLowData.getOpenValue(series, item);
142         Number JavaDoc yClose = highLowData.getCloseValue(series, item);
143
144         double xx = domainAxis.translateValueToJava2D(x.doubleValue(), dataArea,
145                                                       plot.getDomainAxisEdge());
146
147         RectangleEdge location = plot.getRangeAxisEdge();
148         double yyHigh = rangeAxis.translateValueToJava2D(yHigh.doubleValue(), dataArea, location);
149         double yyLow = rangeAxis.translateValueToJava2D(yLow.doubleValue(), dataArea, location);
150         double yyOpen = rangeAxis.translateValueToJava2D(yOpen.doubleValue(), dataArea, location);
151         double yyClose = rangeAxis.translateValueToJava2D(yClose.doubleValue(), dataArea, location);
152
153         Paint JavaDoc p = getItemPaint(series, item);
154         Stroke JavaDoc s = getItemStroke(series, item);
155
156         HighLow hl = new HighLow(xx, yyHigh, yyLow, yyOpen, yyClose, s, p);
157         Line2D JavaDoc l1 = hl.getOpenTickLine();
158         Line2D JavaDoc l2 = hl.getLine();
159         Line2D JavaDoc l3 = hl.getCloseTickLine();
160
161         g2.setPaint(p);
162         g2.setStroke(s);
163         g2.draw(l1);
164         g2.draw(l2);
165         g2.draw(l3);
166
167         // add an entity for the item...
168
if (entities != null) {
169             if (entityArea == null) {
170                 entityArea = hl.getBounds();
171             }
172             String JavaDoc tip = null;
173             if (getToolTipGenerator() != null) {
174                 tip = getToolTipGenerator().generateToolTip(dataset, series, item);
175             }
176             String JavaDoc url = null;
177             if (getURLGenerator() != null) {
178                 url = getURLGenerator().generateURL(dataset, series, item);
179             }
180             XYItemEntity entity = new XYItemEntity(entityArea, dataset, series, item, tip, url);
181             entities.addEntity(entity);
182         }
183
184     }
185     
186     /**
187      * Returns a clone of the renderer.
188      *
189      * @return A clone.
190      *
191      * @throws CloneNotSupportedException if the renderer cannot be cloned.
192      */

193     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
194         return super.clone();
195     }
196
197 }
198
Popular Tags