1 64 65 package org.jfree.chart.renderer.xy; 66 67 import java.awt.Color ; 68 import java.awt.Graphics2D ; 69 import java.awt.Paint ; 70 import java.awt.Stroke ; 71 import java.awt.geom.Ellipse2D ; 72 import java.awt.geom.GeneralPath ; 73 import java.awt.geom.Rectangle2D ; 74 import java.io.Serializable ; 75 76 import org.jfree.chart.axis.ValueAxis; 77 import org.jfree.chart.entity.EntityCollection; 78 import org.jfree.chart.entity.XYItemEntity; 79 import org.jfree.chart.labels.XYToolTipGenerator; 80 import org.jfree.chart.plot.CrosshairState; 81 import org.jfree.chart.plot.PlotRenderingInfo; 82 import org.jfree.chart.plot.XYPlot; 83 import org.jfree.data.xy.SignalsDataset; 84 import org.jfree.data.xy.XYDataset; 85 import org.jfree.util.PublicCloneable; 86 87 92 public class SignalRenderer extends AbstractXYItemRenderer 93 implements XYItemRenderer, 94 Cloneable , 95 PublicCloneable, 96 Serializable { 97 98 99 private static final long serialVersionUID = 1161092564576638268L; 100 101 102 private double markOffset = 5; 103 104 105 private double shapeWidth = 15; 106 107 108 private double shapeHeight = 25; 109 110 113 public SignalRenderer() { 114 super(); 115 } 116 117 122 public double getMarkOffset() { 123 return this.markOffset; 124 } 125 126 131 public void setMarkOffset(double offset) { 132 this.markOffset = offset; 133 } 134 135 140 public double getShapeWidth() { 141 return this.shapeWidth; 142 } 143 144 149 public void setShapeWidth(double width) { 150 this.shapeWidth = width; 151 } 152 153 158 public double getShapeHeight() { 159 return this.shapeHeight; 160 } 161 162 167 public void setShapeHeight(double height) { 168 this.shapeHeight = height; 169 } 170 171 189 public void drawItem(Graphics2D g2, 190 XYItemRendererState state, 191 Rectangle2D dataArea, 192 PlotRenderingInfo info, 193 XYPlot plot, 194 ValueAxis horizontalAxis, 195 ValueAxis verticalAxis, 196 XYDataset dataset, 197 int series, 198 int item, 199 CrosshairState crosshairState, 200 int pass) { 201 202 EntityCollection entities = null; 204 if (info != null) { 205 entities = info.getOwner().getEntityCollection(); 206 } 207 208 SignalsDataset signalData = (SignalsDataset) dataset; 209 210 Number x = signalData.getX(series, item); 211 Number y = signalData.getY(series, item); 212 int type = signalData.getType(series, item); 213 215 double xx = horizontalAxis.valueToJava2D( 216 x.doubleValue(), dataArea, plot.getDomainAxisEdge() 217 ); 218 double yy = verticalAxis.valueToJava2D( 219 y.doubleValue(), dataArea, plot.getRangeAxisEdge() 220 ); 221 222 Paint p = getItemPaint(series, item); 223 Stroke s = getItemStroke(series, item); 224 g2.setPaint(p); 225 g2.setStroke(s); 226 227 int direction = 1; 228 if ((type == SignalsDataset.ENTER_LONG) 229 || (type == SignalsDataset.EXIT_SHORT)) { 230 yy = yy + this.markOffset; 231 direction = -1; 232 } 233 else { 234 yy = yy - this.markOffset; 235 } 236 237 GeneralPath path = new GeneralPath (); 238 if ((type == SignalsDataset.ENTER_LONG) 239 || (type == SignalsDataset.ENTER_SHORT)) { 240 path.moveTo((float) xx, (float) yy); 241 path.lineTo( 242 (float) (xx + this.shapeWidth / 2), 243 (float) (yy - direction * this.shapeHeight / 3) 244 ); 245 path.lineTo( 246 (float) (xx + this.shapeWidth / 6), 247 (float) (yy - direction * this.shapeHeight / 3) 248 ); 249 path.lineTo( 250 (float) (xx + this.shapeWidth / 6), 251 (float) (yy - direction * this.shapeHeight) 252 ); 253 path.lineTo( 254 (float) (xx - this.shapeWidth / 6), 255 (float) (yy - direction * this.shapeHeight) 256 ); 257 path.lineTo( 258 (float) (xx - this.shapeWidth / 6), 259 (float) (yy - direction * this.shapeHeight / 3) 260 ); 261 path.lineTo( 262 (float) (xx - this.shapeWidth / 2), 263 (float) (yy - direction * this.shapeHeight / 3) 264 ); 265 path.lineTo((float) xx, (float) yy); 266 } 267 else { 268 path.moveTo((float) xx, (float) yy); 269 path.lineTo( 270 (float) xx, (float) (yy - direction * this.shapeHeight) 271 ); 272 Ellipse2D.Double ellipse = new Ellipse2D.Double ( 273 xx - this.shapeWidth / 2, 274 yy + (direction == 1 ? -this.shapeHeight 275 : this.shapeHeight - this.shapeWidth), 276 this.shapeWidth, 277 this.shapeWidth 278 ); 279 path.append(ellipse, false); 280 } 281 282 g2.fill(path); 283 g2.setPaint(Color.black); 284 g2.draw(path); 285 286 if (entities != null) { 288 String tip = null; 289 XYToolTipGenerator generator = getToolTipGenerator(series, item); 290 if (generator != null) { 291 tip = generator.generateToolTip(dataset, series, item); 292 } 293 String url = null; 294 if (getURLGenerator() != null) { 295 url = getURLGenerator().generateURL(dataset, series, item); 296 } 297 XYItemEntity entity = new XYItemEntity( 298 path, dataset, series, item, tip, url 299 ); 300 entities.add(entity); 301 } 302 303 } 304 305 312 public Object clone() throws CloneNotSupportedException { 313 return super.clone(); 314 } 315 316 } 317 | Popular Tags |