1 49 50 package org.jfree.chart.renderer.xy; 51 52 import java.awt.Graphics2D ; 53 import java.awt.Paint ; 54 import java.awt.Shape ; 55 import java.awt.Stroke ; 56 import java.awt.geom.Line2D ; 57 import java.awt.geom.Rectangle2D ; 58 import java.io.Serializable ; 59 60 import org.jfree.chart.axis.ValueAxis; 61 import org.jfree.chart.entity.EntityCollection; 62 import org.jfree.chart.entity.XYItemEntity; 63 import org.jfree.chart.labels.XYToolTipGenerator; 64 import org.jfree.chart.plot.CrosshairState; 65 import org.jfree.chart.plot.PlotOrientation; 66 import org.jfree.chart.plot.PlotRenderingInfo; 67 import org.jfree.chart.plot.XYPlot; 68 import org.jfree.data.xy.IntervalXYDataset; 69 import org.jfree.data.xy.XYDataset; 70 import org.jfree.ui.RectangleEdge; 71 import org.jfree.util.PublicCloneable; 72 import org.jfree.util.ShapeUtilities; 73 74 78 public class YIntervalRenderer extends AbstractXYItemRenderer 79 implements XYItemRenderer, 80 Cloneable , 81 PublicCloneable, 82 Serializable { 83 84 private static final long serialVersionUID = -2951586537224143260L; 85 86 89 public YIntervalRenderer() { 90 super(); 91 } 92 93 111 public void drawItem(Graphics2D g2, 112 XYItemRendererState state, 113 Rectangle2D dataArea, 114 PlotRenderingInfo info, 115 XYPlot plot, 116 ValueAxis domainAxis, 117 ValueAxis rangeAxis, 118 XYDataset dataset, 119 int series, 120 int item, 121 CrosshairState crosshairState, 122 int pass) { 123 124 Shape entityArea = null; 126 EntityCollection entities = null; 127 if (info != null) { 128 entities = info.getOwner().getEntityCollection(); 129 } 130 131 IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset; 132 133 double x = intervalDataset.getXValue(series, item); 134 double yLow = intervalDataset.getStartYValue(series, item); 135 double yHigh = intervalDataset.getEndYValue(series, item); 136 137 RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); 138 RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); 139 140 double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation); 141 double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation); 142 double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation); 143 144 Paint p = getItemPaint(series, item); 145 Stroke s = getItemStroke(series, item); 146 147 Line2D line = null; 148 Shape shape = getItemShape(series, item); 149 Shape top = null; 150 Shape bottom = null; 151 PlotOrientation orientation = plot.getOrientation(); 152 if (orientation == PlotOrientation.HORIZONTAL) { 153 line = new Line2D.Double (yyLow, xx, yyHigh, xx); 154 top = ShapeUtilities.createTranslatedShape(shape, yyHigh, xx); 155 bottom = ShapeUtilities.createTranslatedShape(shape, yyLow, xx); 156 } 157 else if (orientation == PlotOrientation.VERTICAL) { 158 line = new Line2D.Double (xx, yyLow, xx, yyHigh); 159 top = ShapeUtilities.createTranslatedShape(shape, xx, yyHigh); 160 bottom = ShapeUtilities.createTranslatedShape(shape, xx, yyLow); 161 } 162 g2.setPaint(p); 163 g2.setStroke(s); 164 g2.draw(line); 165 166 g2.fill(top); 167 g2.fill(bottom); 168 169 if (entities != null) { 171 if (entityArea == null) { 172 entityArea = line.getBounds(); 173 } 174 String tip = null; 175 XYToolTipGenerator generator = getToolTipGenerator(series, item); 176 if (generator != null) { 177 tip = generator.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( 184 entityArea, dataset, series, item, tip, url 185 ); 186 entities.add(entity); 187 } 188 189 } 190 191 198 public Object clone() throws CloneNotSupportedException { 199 return super.clone(); 200 } 201 202 } 203 | Popular Tags |