001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * ---------------------
028: * WindItemRenderer.java
029: * ---------------------
030: * (C) Copyright 2001-2007, by Achilleus Mantzios and Contributors.
031: *
032: * Original Author: Achilleus Mantzios;
033: * Contributor(s): David Gilbert (for Object Refinery Limited);
034: *
035: * $Id: WindItemRenderer.java,v 1.3.2.2 2007/02/02 15:51:30 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 06-Feb-2002 : Version 1, based on code contributed by Achilleus
040: * Mantzios (DG);
041: * 28-Mar-2002 : Added a property change listener mechanism so that renderers
042: * no longer need to be immutable. Changed StrictMath --> Math
043: * to retain JDK1.2 compatibility (DG);
044: * 09-Apr-2002 : Changed return type of the drawItem method to void, reflecting
045: * the change in the XYItemRenderer method (DG);
046: * 01-Oct-2002 : Fixed errors reported by Checkstyle (DG);
047: * 21-Jan-2003 : Added new constructor (DG);
048: * 25-Mar-2003 : Implemented Serializable (DG);
049: * 01-May-2003 : Modified drawItem() method signature (DG);
050: * 20-Aug-2003 : Implemented Cloneable and PublicCloneable (DG);
051: * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG);
052: * 25-Feb-2004 : Replaced CrosshairInfo with CrosshairState (DG);
053: * 15-Jul-2004 : Switched getX() with getXValue() and getY() with
054: * getYValue() (DG);
055: * ------------- JFREECHART 1.0.x ---------------------------------------------
056: * 02-Feb-2007 : Removed author tags from all over JFreeChart sources (DG);
057: *
058: */
059:
060: package org.jfree.chart.renderer.xy;
061:
062: import java.awt.Color;
063: import java.awt.Font;
064: import java.awt.Graphics2D;
065: import java.awt.Paint;
066: import java.awt.Stroke;
067: import java.awt.geom.Line2D;
068: import java.awt.geom.Rectangle2D;
069: import java.io.Serializable;
070:
071: import org.jfree.chart.axis.ValueAxis;
072: import org.jfree.chart.plot.CrosshairState;
073: import org.jfree.chart.plot.PlotRenderingInfo;
074: import org.jfree.chart.plot.XYPlot;
075: import org.jfree.data.xy.WindDataset;
076: import org.jfree.data.xy.XYDataset;
077: import org.jfree.ui.RectangleEdge;
078: import org.jfree.util.PublicCloneable;
079:
080: /**
081: * A specialised renderer for displaying wind intensity/direction data.
082: */
083: public class WindItemRenderer extends AbstractXYItemRenderer implements
084: XYItemRenderer, Cloneable, PublicCloneable, Serializable {
085:
086: /** For serialization. */
087: private static final long serialVersionUID = 8078914101916976844L;
088:
089: /**
090: * Creates a new renderer.
091: */
092: public WindItemRenderer() {
093: super ();
094: }
095:
096: /**
097: * Draws the visual representation of a single data item.
098: *
099: * @param g2 the graphics device.
100: * @param state the renderer state.
101: * @param plotArea the area within which the plot is being drawn.
102: * @param info optional information collection.
103: * @param plot the plot (can be used to obtain standard color
104: * information etc).
105: * @param domainAxis the horizontal axis.
106: * @param rangeAxis the vertical axis.
107: * @param dataset the dataset.
108: * @param series the series index (zero-based).
109: * @param item the item index (zero-based).
110: * @param crosshairState crosshair information for the plot
111: * (<code>null</code> permitted).
112: * @param pass the pass index.
113: */
114: public void drawItem(Graphics2D g2, XYItemRendererState state,
115: Rectangle2D plotArea, PlotRenderingInfo info, XYPlot plot,
116: ValueAxis domainAxis, ValueAxis rangeAxis,
117: XYDataset dataset, int series, int item,
118: CrosshairState crosshairState, int pass) {
119:
120: WindDataset windData = (WindDataset) dataset;
121:
122: Paint seriesPaint = getItemPaint(series, item);
123: Stroke seriesStroke = getItemStroke(series, item);
124: g2.setPaint(seriesPaint);
125: g2.setStroke(seriesStroke);
126:
127: // get the data point...
128:
129: Number x = windData.getX(series, item);
130: Number windDir = windData.getWindDirection(series, item);
131: Number wforce = windData.getWindForce(series, item);
132: double windForce = wforce.doubleValue();
133:
134: double wdirt = Math.toRadians(windDir.doubleValue() * (-30.0)
135: - 90.0);
136:
137: double ax1, ax2, ay1, ay2, rax2, ray2;
138:
139: RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
140: RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
141: ax1 = domainAxis.valueToJava2D(x.doubleValue(), plotArea,
142: domainAxisLocation);
143: ay1 = rangeAxis.valueToJava2D(0.0, plotArea, rangeAxisLocation);
144:
145: rax2 = x.doubleValue()
146: + (windForce * Math.cos(wdirt) * 8000000.0);
147: ray2 = windForce * Math.sin(wdirt);
148:
149: ax2 = domainAxis.valueToJava2D(rax2, plotArea,
150: domainAxisLocation);
151: ay2 = rangeAxis
152: .valueToJava2D(ray2, plotArea, rangeAxisLocation);
153:
154: int diri = windDir.intValue();
155: int forcei = wforce.intValue();
156: String dirforce = diri + "-" + forcei;
157: Line2D line = new Line2D.Double(ax1, ay1, ax2, ay2);
158:
159: g2.draw(line);
160: g2.setPaint(Color.blue);
161: g2.setFont(new Font("foo", 1, 9));
162:
163: g2.drawString(dirforce, (float) ax1, (float) ay1);
164:
165: g2.setPaint(seriesPaint);
166: g2.setStroke(seriesStroke);
167:
168: double alx2, aly2, arx2, ary2;
169: double ralx2, raly2, rarx2, rary2;
170:
171: double aldir = Math.toRadians(windDir.doubleValue() * (-30.0)
172: - 90.0 - 5.0);
173: ralx2 = wforce.doubleValue() * Math.cos(aldir) * 8000000 * 0.8
174: + x.doubleValue();
175: raly2 = wforce.doubleValue() * Math.sin(aldir) * 0.8;
176:
177: alx2 = domainAxis.valueToJava2D(ralx2, plotArea,
178: domainAxisLocation);
179: aly2 = rangeAxis.valueToJava2D(raly2, plotArea,
180: rangeAxisLocation);
181:
182: line = new Line2D.Double(alx2, aly2, ax2, ay2);
183: g2.draw(line);
184:
185: double ardir = Math.toRadians(windDir.doubleValue() * (-30.0)
186: - 90.0 + 5.0);
187: rarx2 = wforce.doubleValue() * Math.cos(ardir) * 8000000 * 0.8
188: + x.doubleValue();
189: rary2 = wforce.doubleValue() * Math.sin(ardir) * 0.8;
190:
191: arx2 = domainAxis.valueToJava2D(rarx2, plotArea,
192: domainAxisLocation);
193: ary2 = rangeAxis.valueToJava2D(rary2, plotArea,
194: rangeAxisLocation);
195:
196: line = new Line2D.Double(arx2, ary2, ax2, ay2);
197: g2.draw(line);
198:
199: }
200:
201: /**
202: * Returns a clone of the renderer.
203: *
204: * @return A clone.
205: *
206: * @throws CloneNotSupportedException if the renderer cannot be cloned.
207: */
208: public Object clone() throws CloneNotSupportedException {
209: return super.clone();
210: }
211:
212: }
|