1 47 48 package org.jfree.chart.renderer; 49 50 import java.awt.Color ; 51 import java.awt.Font ; 52 import java.awt.Graphics2D ; 53 import java.awt.Paint ; 54 import java.awt.Stroke ; 55 import java.awt.geom.Line2D ; 56 import java.awt.geom.Rectangle2D ; 57 import java.io.Serializable ; 58 59 import org.jfree.chart.CrosshairInfo; 60 import org.jfree.chart.axis.ValueAxis; 61 import org.jfree.chart.labels.XYToolTipGenerator; 62 import org.jfree.chart.plot.PlotRenderingInfo; 63 import org.jfree.chart.plot.XYPlot; 64 import org.jfree.chart.urls.XYURLGenerator; 65 import org.jfree.data.WindDataset; 66 import org.jfree.data.XYDataset; 67 import org.jfree.ui.RectangleEdge; 68 import org.jfree.util.PublicCloneable; 69 70 75 public class WindItemRenderer extends AbstractXYItemRenderer implements XYItemRenderer, 76 Cloneable , 77 PublicCloneable, 78 Serializable { 79 80 83 public WindItemRenderer() { 84 super(); 85 } 86 87 95 public WindItemRenderer(XYToolTipGenerator toolTipGenerator, XYURLGenerator urlGenerator) { 96 97 super(); 98 setToolTipGenerator(toolTipGenerator); 99 setURLGenerator(urlGenerator); 100 101 } 102 103 119 public void drawItem(Graphics2D g2, 120 XYItemRendererState state, 121 Rectangle2D plotArea, 122 PlotRenderingInfo info, 123 XYPlot plot, 124 ValueAxis domainAxis, 125 ValueAxis rangeAxis, 126 XYDataset dataset, 127 int series, 128 int item, 129 CrosshairInfo crosshairs, 130 int pass) { 131 132 WindDataset windData = (WindDataset) dataset; 133 134 Paint seriesPaint = getItemPaint(series, item); 135 Stroke seriesStroke = getItemStroke(series, item); 136 g2.setPaint(seriesPaint); 137 g2.setStroke(seriesStroke); 138 139 141 Number x = windData.getXValue(series, item); 142 Number windDir = windData.getWindDirection(series, item); 143 Number wforce = windData.getWindForce(series, item); 144 double windForce = wforce.doubleValue(); 145 146 double wdirt = Math.toRadians(windDir.doubleValue() * (-30.0) - 90.0); 147 148 double ax1, ax2, ay1, ay2, rax2, ray2; 149 150 RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); 151 RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); 152 ax1 = domainAxis.translateValueToJava2D(x.doubleValue(), plotArea, domainAxisLocation); 153 ay1 = rangeAxis.translateValueToJava2D(0.0, plotArea, rangeAxisLocation); 154 155 rax2 = x.doubleValue() + (windForce * Math.cos(wdirt) * 8000000.0); 156 ray2 = windForce * Math.sin(wdirt); 157 158 ax2 = domainAxis.translateValueToJava2D(rax2, plotArea, domainAxisLocation); 159 ay2 = rangeAxis.translateValueToJava2D(ray2, plotArea, rangeAxisLocation); 160 161 int diri = windDir.intValue(); 162 int forcei = wforce.intValue(); 163 String dirforce = diri + "-" + forcei; 164 Line2D line = new Line2D.Double (ax1, ay1, ax2, ay2); 165 166 g2.draw(line); 167 g2.setPaint(Color.blue); 168 g2.setFont(new Font ("foo", 1, 9)); 169 170 g2.drawString(dirforce, (float) ax1, (float) ay1); 171 172 g2.setPaint(seriesPaint); 173 g2.setStroke(seriesStroke); 174 175 double alx2, aly2, arx2, ary2; 176 double ralx2, raly2, rarx2, rary2; 177 178 double aldir = Math.toRadians(windDir.doubleValue() * (-30.0) - 90.0 - 5.0); 179 ralx2 = wforce.doubleValue() * Math.cos(aldir) * 8000000 * 0.8 + x.doubleValue(); 180 raly2 = wforce.doubleValue() * Math.sin(aldir) * 0.8; 181 182 alx2 = domainAxis.translateValueToJava2D(ralx2, plotArea, domainAxisLocation); 183 aly2 = rangeAxis.translateValueToJava2D(raly2, plotArea, rangeAxisLocation); 184 185 line = new Line2D.Double (alx2, aly2, ax2, ay2); 186 g2.draw(line); 187 188 double ardir = Math.toRadians(windDir.doubleValue() * (-30.0) - 90.0 + 5.0); 189 rarx2 = wforce.doubleValue() * Math.cos(ardir) * 8000000 * 0.8 + x.doubleValue(); 190 rary2 = wforce.doubleValue() * Math.sin(ardir) * 0.8; 191 192 arx2 = domainAxis.translateValueToJava2D(rarx2, plotArea, domainAxisLocation); 193 ary2 = rangeAxis.translateValueToJava2D(rary2, plotArea, rangeAxisLocation); 194 195 line = new Line2D.Double (arx2, ary2, ax2, ay2); 196 g2.draw(line); 197 198 } 199 200 207 public Object clone() throws CloneNotSupportedException { 208 return super.clone(); 209 } 210 211 } 212 | Popular Tags |