1 51 52 package org.jfree.chart.renderer.xy; 53 54 import java.awt.Graphics2D ; 55 import java.awt.geom.Rectangle2D ; 56 import java.io.Serializable ; 57 58 import org.jfree.chart.axis.ValueAxis; 59 import org.jfree.chart.event.RendererChangeEvent; 60 import org.jfree.chart.plot.CrosshairState; 61 import org.jfree.chart.plot.PlotOrientation; 62 import org.jfree.chart.plot.PlotRenderingInfo; 63 import org.jfree.chart.plot.XYPlot; 64 import org.jfree.data.xy.XYDataset; 65 import org.jfree.ui.RectangleEdge; 66 import org.jfree.util.PublicCloneable; 67 68 71 public class XYDotRenderer extends AbstractXYItemRenderer 72 implements XYItemRenderer, 73 Cloneable , 74 PublicCloneable, 75 Serializable { 76 77 78 private static final long serialVersionUID = -2764344339073566425L; 79 80 81 private int dotWidth; 82 83 84 private int dotHeight; 85 86 89 public XYDotRenderer() { 90 super(); 91 this.dotWidth = 1; 92 this.dotHeight = 1; 93 } 94 95 103 public int getDotWidth() { 104 return this.dotWidth; 105 } 106 107 118 public void setDotWidth(int w) { 119 if (w < 1) { 120 throw new IllegalArgumentException ("Requires w > 0."); 121 } 122 this.dotWidth = w; 123 notifyListeners(new RendererChangeEvent(this)); 124 } 125 126 134 public int getDotHeight() { 135 return this.dotHeight; 136 } 137 138 149 public void setDotHeight(int h) { 150 if (h < 1) { 151 throw new IllegalArgumentException ("Requires h > 0."); 152 } 153 this.dotHeight = h; 154 notifyListeners(new RendererChangeEvent(this)); 155 } 156 157 175 public void drawItem(Graphics2D g2, 176 XYItemRendererState state, 177 Rectangle2D dataArea, 178 PlotRenderingInfo info, 179 XYPlot plot, 180 ValueAxis domainAxis, 181 ValueAxis rangeAxis, 182 XYDataset dataset, 183 int series, 184 int item, 185 CrosshairState crosshairState, 186 int pass) { 187 188 double x = dataset.getXValue(series, item); 190 double y = dataset.getYValue(series, item); 191 double adjx = (this.dotWidth - 1) / 2.0; 192 double adjy = (this.dotHeight - 1) / 2.0; 193 if (!Double.isNaN(y)) { 194 RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); 195 RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); 196 double transX = domainAxis.valueToJava2D(x, dataArea, 197 xAxisLocation) - adjx; 198 double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) 199 - adjy; 200 201 g2.setPaint(getItemPaint(series, item)); 202 PlotOrientation orientation = plot.getOrientation(); 203 if (orientation == PlotOrientation.HORIZONTAL) { 204 g2.fillRect((int) transY, (int) transX, this.dotHeight, 205 this.dotWidth); 206 } 207 else if (orientation == PlotOrientation.VERTICAL) { 208 g2.fillRect((int) transX, (int) transY, this.dotWidth, 209 this.dotHeight); 210 } 211 212 updateCrosshairValues(crosshairState, x, y, transX, transY, 213 orientation); 214 } 215 216 } 217 218 232 public boolean equals(Object obj) { 233 if (obj == this) { 234 return true; 235 } 236 if (!(obj instanceof XYDotRenderer)) { 237 return false; 238 } 239 XYDotRenderer that = (XYDotRenderer) obj; 240 if (this.dotWidth != that.dotWidth) { 241 return false; 242 } 243 if (this.dotHeight != that.dotHeight) { 244 return false; 245 } 246 return super.equals(obj); 247 } 248 249 256 public Object clone() throws CloneNotSupportedException { 257 return super.clone(); 258 } 259 260 } 261 | Popular Tags |