1 64 65 package org.jfree.chart.renderer.xy; 66 67 import java.awt.Graphics2D ; 68 import java.awt.Paint ; 69 import java.awt.Shape ; 70 import java.awt.Stroke ; 71 import java.awt.geom.Line2D ; 72 import java.awt.geom.Rectangle2D ; 73 import java.io.Serializable ; 74 75 import org.jfree.chart.axis.ValueAxis; 76 import org.jfree.chart.entity.EntityCollection; 77 import org.jfree.chart.entity.XYItemEntity; 78 import org.jfree.chart.labels.XYToolTipGenerator; 79 import org.jfree.chart.plot.CrosshairState; 80 import org.jfree.chart.plot.PlotOrientation; 81 import org.jfree.chart.plot.PlotRenderingInfo; 82 import org.jfree.chart.plot.XYPlot; 83 import org.jfree.chart.urls.XYURLGenerator; 84 import org.jfree.data.xy.XYDataset; 85 import org.jfree.ui.RectangleEdge; 86 import org.jfree.util.PublicCloneable; 87 88 92 public class XYStepRenderer extends XYLineAndShapeRenderer 93 implements XYItemRenderer, 94 Cloneable , 95 PublicCloneable, 96 Serializable { 97 98 99 private static final long serialVersionUID = -8918141928884796108L; 100 101 104 public XYStepRenderer() { 105 this(null, null); 106 } 107 108 116 public XYStepRenderer(XYToolTipGenerator toolTipGenerator, 117 XYURLGenerator urlGenerator) { 118 super(); 119 setBaseToolTipGenerator(toolTipGenerator); 120 setURLGenerator(urlGenerator); 121 setShapesVisible(false); 122 } 123 124 142 public void drawItem(Graphics2D g2, 143 XYItemRendererState state, 144 Rectangle2D dataArea, 145 PlotRenderingInfo info, 146 XYPlot plot, 147 ValueAxis domainAxis, 148 ValueAxis rangeAxis, 149 XYDataset dataset, 150 int series, 151 int item, 152 CrosshairState crosshairState, 153 int pass) { 154 155 if (!getItemVisible(series, item)) { 157 return; 158 } 159 160 PlotOrientation orientation = plot.getOrientation(); 161 162 Paint seriesPaint = getItemPaint(series, item); 163 Stroke seriesStroke = getItemStroke(series, item); 164 g2.setPaint(seriesPaint); 165 g2.setStroke(seriesStroke); 166 167 double x1 = dataset.getXValue(series, item); 169 double y1 = dataset.getYValue(series, item); 170 if (Double.isNaN(y1)) { 171 return; 172 } 173 174 RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); 175 RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); 176 double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); 177 double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); 178 179 if (item > 0) { 180 double x0 = dataset.getXValue(series, item - 1); 182 double y0 = dataset.getYValue(series, item - 1); 183 if (!Double.isNaN(y0)) { 184 double transX0 = domainAxis.valueToJava2D(x0, dataArea, 185 xAxisLocation); 186 double transY0 = rangeAxis.valueToJava2D(y0, dataArea, 187 yAxisLocation); 188 189 Line2D line = state.workingLine; 190 if (orientation == PlotOrientation.HORIZONTAL) { 191 if (transY0 == transY1) { line.setLine(transY0, transX0, transY1, transX1); 194 g2.draw(line); 195 } 196 else { line.setLine(transY0, transX0, transY0, transX1); 198 g2.draw(line); 199 line.setLine(transY0, transX1, transY1, transX1); 200 g2.draw(line); 201 } 202 } 203 else if (orientation == PlotOrientation.VERTICAL) { 204 if (transY0 == transY1) { line.setLine(transX0, transY0, transX1, transY1); 207 g2.draw(line); 208 } 209 else { line.setLine(transX0, transY0, transX1, transY0); 211 g2.draw(line); 212 line.setLine(transX1, transY0, transX1, transY1); 213 g2.draw(line); 214 } 215 } 216 217 } 218 } 219 220 if (isItemLabelVisible(series, item)) { 222 double xx = transX1; 223 double yy = transY1; 224 if (orientation == PlotOrientation.HORIZONTAL) { 225 xx = transY1; 226 yy = transX1; 227 } 228 drawItemLabel(g2, orientation, dataset, series, item, xx, yy, 229 (y1 < 0.0)); 230 } 231 232 updateCrosshairValues(crosshairState, x1, y1, transX1, transY1, 233 orientation); 234 235 if (state.getInfo() != null) { 237 EntityCollection entities = state.getEntityCollection(); 238 if (entities != null) { 239 int r = getDefaultEntityRadius(); 240 Shape shape = orientation == PlotOrientation.VERTICAL 241 ? new Rectangle2D.Double (transX1 - r, transY1 - r, 2 * r, 242 2 * r) 243 : new Rectangle2D.Double (transY1 - r, transX1 - r, 2 * r, 244 2 * r); 245 if (shape != null) { 246 String tip = null; 247 XYToolTipGenerator generator 248 = getToolTipGenerator(series, item); 249 if (generator != null) { 250 tip = generator.generateToolTip(dataset, series, item); 251 } 252 String url = null; 253 if (getURLGenerator() != null) { 254 url = getURLGenerator().generateURL(dataset, series, 255 item); 256 } 257 XYItemEntity entity = new XYItemEntity(shape, dataset, 258 series, item, tip, url); 259 entities.add(entity); 260 } 261 } 262 } 263 } 264 265 272 public Object clone() throws CloneNotSupportedException { 273 return super.clone(); 274 } 275 276 } 277 | Popular Tags |