1 55 56 package org.jfree.chart.renderer; 57 58 import java.awt.Color ; 59 import java.awt.Graphics2D ; 60 import java.awt.Paint ; 61 import java.awt.Stroke ; 62 import java.awt.geom.Ellipse2D ; 63 import java.awt.geom.GeneralPath ; 64 import java.awt.geom.Rectangle2D ; 65 import java.io.Serializable ; 66 67 import org.jfree.chart.CrosshairInfo; 68 import org.jfree.chart.axis.ValueAxis; 69 import org.jfree.chart.entity.EntityCollection; 70 import org.jfree.chart.entity.XYItemEntity; 71 import org.jfree.chart.plot.PlotRenderingInfo; 72 import org.jfree.chart.plot.XYPlot; 73 import org.jfree.data.SignalsDataset; 74 import org.jfree.data.XYDataset; 75 import org.jfree.util.PublicCloneable; 76 77 82 public class SignalRenderer extends AbstractXYItemRenderer implements XYItemRenderer, 83 Cloneable , 84 PublicCloneable, 85 Serializable { 86 87 88 private double markOffset = 5; 89 90 91 private double shapeWidth = 15; 92 93 94 private double shapeHeight = 25; 95 96 99 public SignalRenderer() { 100 } 101 102 107 public double getMarkOffset() { 108 return this.markOffset; 109 } 110 111 116 public void setMarkOffset(double offset) { 117 this.markOffset = offset; 118 } 119 120 125 public double getShapeWidth() { 126 return this.shapeWidth; 127 } 128 129 134 public void setShapeWidth(double width) { 135 this.shapeWidth = width; 136 } 137 138 143 public double getShapeHeight() { 144 return this.shapeHeight; 145 } 146 147 152 public void setShapeHeight(double height) { 153 this.shapeHeight = height; 154 } 155 156 172 public void drawItem(Graphics2D g2, 173 XYItemRendererState state, 174 Rectangle2D dataArea, 175 PlotRenderingInfo info, 176 XYPlot plot, 177 ValueAxis horizontalAxis, 178 ValueAxis verticalAxis, 179 XYDataset dataset, 180 int series, 181 int item, 182 CrosshairInfo crosshairInfo, 183 int pass) { 184 185 EntityCollection entities = null; 187 if (info != null) { 188 entities = info.getOwner().getEntityCollection(); 189 } 190 191 SignalsDataset signalData = (SignalsDataset) dataset; 192 193 Number x = signalData.getXValue(series, item); 194 Number y = signalData.getYValue(series, item); 195 int type = signalData.getType(series, item); 196 198 double xx = horizontalAxis.translateValueToJava2D(x.doubleValue(), dataArea, 199 plot.getDomainAxisEdge()); 200 double yy = verticalAxis.translateValueToJava2D(y.doubleValue(), dataArea, 201 plot.getRangeAxisEdge()); 202 203 Paint p = getItemPaint(series, item); 204 Stroke s = getItemStroke(series, item); 205 g2.setPaint(p); 206 g2.setStroke(s); 207 208 int direction = 1; 209 if ((type == SignalsDataset.ENTER_LONG) || (type == SignalsDataset.EXIT_SHORT)) { 210 yy = yy + markOffset; 211 direction = -1; 212 } 213 else { 214 yy = yy - markOffset; 215 } 216 217 GeneralPath path = new GeneralPath (); 218 if ((type == SignalsDataset.ENTER_LONG) || (type == SignalsDataset.ENTER_SHORT)) { 219 path.moveTo((float) xx, (float) yy); 220 path.lineTo((float) (xx + shapeWidth / 2), (float) (yy - direction * shapeHeight / 3)); 221 path.lineTo((float) (xx + shapeWidth / 6), (float) (yy - direction * shapeHeight / 3)); 222 path.lineTo((float) (xx + shapeWidth / 6), (float) (yy - direction * shapeHeight)); 223 path.lineTo((float) (xx - shapeWidth / 6), (float) (yy - direction * shapeHeight)); 224 path.lineTo((float) (xx - shapeWidth / 6), (float) (yy - direction * shapeHeight / 3)); 225 path.lineTo((float) (xx - shapeWidth / 2), (float) (yy - direction * shapeHeight / 3)); 226 path.lineTo((float) xx, (float) yy); 227 } 228 else { 229 path.moveTo((float) xx, (float) yy); 230 path.lineTo((float) xx, (float) (yy - direction * shapeHeight)); 231 Ellipse2D.Double ellipse = new Ellipse2D.Double ( 232 xx - shapeWidth / 2, 233 yy + (direction == 1 ? -shapeHeight : shapeHeight - shapeWidth), 234 shapeWidth, 235 shapeWidth 236 ); 237 path.append(ellipse, false); 238 } 239 240 g2.fill(path); 241 g2.setPaint(Color.black); 242 g2.draw(path); 243 244 if (entities != null) { 246 String tip = null; 247 if (getToolTipGenerator() != null) { 248 tip = getToolTipGenerator().generateToolTip(dataset, series, item); 249 } 250 String url = null; 251 if (getURLGenerator() != null) { 252 url = getURLGenerator().generateURL(dataset, series, item); 253 } 254 XYItemEntity entity = new XYItemEntity(path, dataset, series, item, tip, url); 255 entities.addEntity(entity); 256 } 257 258 } 259 260 267 public Object clone() throws CloneNotSupportedException { 268 return super.clone(); 269 } 270 271 } 272 | Popular Tags |