1 41 42 package org.jfree.chart.renderer; 43 44 import java.awt.Graphics2D ; 45 import java.awt.Paint ; 46 import java.awt.Shape ; 47 import java.awt.Stroke ; 48 import java.awt.geom.Line2D ; 49 import java.awt.geom.Rectangle2D ; 50 import java.io.Serializable ; 51 52 import org.jfree.chart.CrosshairInfo; 53 import org.jfree.chart.axis.ValueAxis; 54 import org.jfree.chart.entity.EntityCollection; 55 import org.jfree.chart.entity.XYItemEntity; 56 import org.jfree.chart.labels.XYToolTipGenerator; 57 import org.jfree.chart.plot.PlotOrientation; 58 import org.jfree.chart.plot.PlotRenderingInfo; 59 import org.jfree.chart.plot.XYPlot; 60 import org.jfree.data.IntervalXYDataset; 61 import org.jfree.data.XYDataset; 62 import org.jfree.ui.RectangleEdge; 63 import org.jfree.util.PublicCloneable; 64 65 70 public class YIntervalRenderer extends AbstractXYItemRenderer implements XYItemRenderer, 71 Cloneable , 72 PublicCloneable, 73 Serializable { 74 75 78 public YIntervalRenderer() { 79 super(); 80 } 81 82 89 public YIntervalRenderer(XYToolTipGenerator toolTipGenerator) { 90 super(); 91 setToolTipGenerator(toolTipGenerator); 92 } 93 94 110 public void drawItem(Graphics2D g2, 111 XYItemRendererState state, 112 Rectangle2D dataArea, 113 PlotRenderingInfo info, 114 XYPlot plot, 115 ValueAxis domainAxis, 116 ValueAxis rangeAxis, 117 XYDataset dataset, 118 int series, 119 int item, 120 CrosshairInfo crosshairInfo, 121 int pass) { 122 123 Shape entityArea = null; 125 EntityCollection entities = null; 126 if (info != null) { 127 entities = info.getOwner().getEntityCollection(); 128 } 129 130 IntervalXYDataset intervalData = (IntervalXYDataset) dataset; 131 132 Number x = intervalData.getXValue(series, item); 133 Number yLow = intervalData.getStartYValue(series, item); 134 Number yHigh = intervalData.getEndYValue(series, item); 135 136 RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); 137 RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); 138 139 double xx = domainAxis.translateValueToJava2D(x.doubleValue(), dataArea, xAxisLocation); 140 double yyLow 141 = rangeAxis.translateValueToJava2D(yLow.doubleValue(), dataArea, yAxisLocation); 142 double yyHigh 143 = rangeAxis.translateValueToJava2D(yHigh.doubleValue(), dataArea, yAxisLocation); 144 145 Paint p = getItemPaint(series, item); 146 Stroke s = getItemStroke(series, item); 147 148 Line2D line = null; 149 Shape shape = getItemShape(series, item); 150 Shape top = null; 151 Shape bottom = null; 152 PlotOrientation orientation = plot.getOrientation(); 153 if (orientation == PlotOrientation.HORIZONTAL) { 154 line = new Line2D.Double (yyLow, xx, yyHigh, xx); 155 top = createTransformedShape(shape, yyHigh, xx); 156 bottom = createTransformedShape(shape, yyLow, xx); 157 } 158 else if (orientation == PlotOrientation.VERTICAL) { 159 line = new Line2D.Double (xx, yyLow, xx, yyHigh); 160 top = createTransformedShape(shape, xx, yyHigh); 161 bottom = createTransformedShape(shape, xx, yyLow); 162 } 163 g2.setPaint(p); 164 g2.setStroke(s); 165 g2.draw(line); 166 167 g2.fill(top); 168 g2.fill(bottom); 169 170 if (entities != null) { 172 if (entityArea == null) { 173 entityArea = line.getBounds(); 174 } 175 String tip = null; 176 if (getToolTipGenerator() != null) { 177 tip = getToolTipGenerator().generateToolTip(dataset, series, item); 178 } 179 String url = null; 180 if (getURLGenerator() != null) { 181 url = getURLGenerator().generateURL(dataset, series, item); 182 } 183 XYItemEntity entity = new XYItemEntity(entityArea, dataset, series, item, tip, url); 184 entities.addEntity(entity); 185 } 186 187 } 188 189 196 public Object clone() throws CloneNotSupportedException { 197 return super.clone(); 198 } 199 200 } 201 | Popular Tags |