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