1 51 52 package org.jfree.chart.renderer; 53 54 import java.awt.Graphics2D ; 55 import java.awt.Paint ; 56 import java.awt.Shape ; 57 import java.awt.Stroke ; 58 import java.awt.geom.Line2D ; 59 import java.awt.geom.Rectangle2D ; 60 import java.io.Serializable ; 61 62 import org.jfree.chart.CrosshairInfo; 63 import org.jfree.chart.axis.ValueAxis; 64 import org.jfree.chart.entity.EntityCollection; 65 import org.jfree.chart.entity.XYItemEntity; 66 import org.jfree.chart.labels.XYToolTipGenerator; 67 import org.jfree.chart.plot.PlotRenderingInfo; 68 import org.jfree.chart.plot.XYPlot; 69 import org.jfree.data.HighLowDataset; 70 import org.jfree.data.XYDataset; 71 import org.jfree.ui.RectangleEdge; 72 import org.jfree.util.PublicCloneable; 73 74 80 public class HighLowRenderer extends AbstractXYItemRenderer implements XYItemRenderer, 81 Cloneable , 82 PublicCloneable, 83 Serializable { 84 85 88 public HighLowRenderer() { 89 super(); 90 } 91 92 99 public HighLowRenderer(XYToolTipGenerator toolTipGenerator) { 100 super(); 101 setToolTipGenerator(toolTipGenerator); 102 } 103 104 120 public void drawItem(Graphics2D g2, 121 XYItemRendererState state, 122 Rectangle2D dataArea, 123 PlotRenderingInfo info, 124 XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, 125 XYDataset dataset, int series, int item, 126 CrosshairInfo crosshairInfo, 127 int pass) { 128 129 Shape entityArea = null; 131 EntityCollection entities = null; 132 if (info != null) { 133 entities = info.getOwner().getEntityCollection(); 134 } 135 136 HighLowDataset highLowData = (HighLowDataset) dataset; 137 138 Number x = highLowData.getXValue(series, item); 139 Number yHigh = highLowData.getHighValue(series, item); 140 Number yLow = highLowData.getLowValue(series, item); 141 Number yOpen = highLowData.getOpenValue(series, item); 142 Number yClose = highLowData.getCloseValue(series, item); 143 144 double xx = domainAxis.translateValueToJava2D(x.doubleValue(), dataArea, 145 plot.getDomainAxisEdge()); 146 147 RectangleEdge location = plot.getRangeAxisEdge(); 148 double yyHigh = rangeAxis.translateValueToJava2D(yHigh.doubleValue(), dataArea, location); 149 double yyLow = rangeAxis.translateValueToJava2D(yLow.doubleValue(), dataArea, location); 150 double yyOpen = rangeAxis.translateValueToJava2D(yOpen.doubleValue(), dataArea, location); 151 double yyClose = rangeAxis.translateValueToJava2D(yClose.doubleValue(), dataArea, location); 152 153 Paint p = getItemPaint(series, item); 154 Stroke s = getItemStroke(series, item); 155 156 HighLow hl = new HighLow(xx, yyHigh, yyLow, yyOpen, yyClose, s, p); 157 Line2D l1 = hl.getOpenTickLine(); 158 Line2D l2 = hl.getLine(); 159 Line2D l3 = hl.getCloseTickLine(); 160 161 g2.setPaint(p); 162 g2.setStroke(s); 163 g2.draw(l1); 164 g2.draw(l2); 165 g2.draw(l3); 166 167 if (entities != null) { 169 if (entityArea == null) { 170 entityArea = hl.getBounds(); 171 } 172 String tip = null; 173 if (getToolTipGenerator() != null) { 174 tip = getToolTipGenerator().generateToolTip(dataset, series, item); 175 } 176 String url = null; 177 if (getURLGenerator() != null) { 178 url = getURLGenerator().generateURL(dataset, series, item); 179 } 180 XYItemEntity entity = new XYItemEntity(entityArea, dataset, series, item, tip, url); 181 entities.addEntity(entity); 182 } 183 184 } 185 186 193 public Object clone() throws CloneNotSupportedException { 194 return super.clone(); 195 } 196 197 } 198 | Popular Tags |