1 48 49 package org.jfree.chart.renderer; 50 51 import java.awt.AlphaComposite ; 52 import java.awt.Composite ; 53 import java.awt.Graphics2D ; 54 import java.awt.Paint ; 55 import java.awt.Point ; 56 import java.awt.Polygon ; 57 import java.awt.Shape ; 58 import java.awt.Stroke ; 59 import java.awt.geom.Ellipse2D ; 60 import java.awt.geom.Rectangle2D ; 61 import java.util.Iterator ; 62 import java.util.List ; 63 64 import org.jfree.chart.LegendItem; 65 import org.jfree.chart.axis.NumberTick; 66 import org.jfree.chart.axis.ValueAxis; 67 import org.jfree.chart.plot.DrawingSupplier; 68 import org.jfree.chart.plot.PlotRenderingInfo; 69 import org.jfree.chart.plot.PolarPlot; 70 import org.jfree.data.xy.XYDataset; 71 import org.jfree.text.TextUtilities; 72 import org.jfree.ui.TextAnchor; 73 import org.jfree.util.BooleanList; 74 import org.jfree.util.BooleanUtilities; 75 76 81 public class DefaultPolarItemRenderer extends AbstractRenderer 82 implements PolarItemRenderer { 83 84 85 private PolarPlot plot; 86 87 88 private BooleanList seriesFilled; 89 90 93 public DefaultPolarItemRenderer() { 94 this.seriesFilled = new BooleanList(); 95 } 96 97 102 public DrawingSupplier getDrawingSupplier() { 103 DrawingSupplier result = null; 104 PolarPlot p = getPlot(); 105 if (p != null) { 106 result = p.getDrawingSupplier(); 107 } 108 return result; 109 } 110 111 116 public void setPlot(PolarPlot plot) { 117 this.plot = plot; 118 } 119 120 125 public PolarPlot getPlot() { 126 return this.plot; 127 } 128 129 139 public void drawSeries(Graphics2D g2, 140 Rectangle2D dataArea, 141 PlotRenderingInfo info, 142 PolarPlot plot, 143 XYDataset dataset, 144 int seriesIndex) { 145 146 Polygon poly = new Polygon (); 147 int numPoints = dataset.getItemCount(seriesIndex); 148 for (int i = 0; i < numPoints; i++) { 149 double theta = dataset.getXValue(seriesIndex, i); 150 double radius = dataset.getYValue(seriesIndex, i); 151 Point p = plot.translateValueThetaRadiusToJava2D(theta, radius, 152 dataArea); 153 poly.addPoint(p.x, p.y); 154 } 155 g2.setPaint(getSeriesPaint(seriesIndex)); 156 g2.setStroke(getSeriesStroke(seriesIndex)); 157 if (isSeriesFilled(seriesIndex)) { 158 Composite savedComposite = g2.getComposite(); 159 g2.setComposite(AlphaComposite.getInstance( 160 AlphaComposite.SRC_OVER, 0.5f)); 161 g2.fill(poly); 162 g2.setComposite(savedComposite); 163 } 164 else { 165 g2.draw(poly); 166 } 167 } 168 169 177 public boolean isSeriesFilled(int series) { 178 boolean result = false; 179 Boolean b = this.seriesFilled.getBoolean(series); 180 if (b != null) { 181 result = b.booleanValue(); 182 } 183 return result; 184 } 185 186 192 public void setSeriesFilled(int series, boolean filled) { 193 this.seriesFilled.setBoolean(series, BooleanUtilities.valueOf(filled)); 194 } 195 196 204 public void drawAngularGridLines(Graphics2D g2, 205 PolarPlot plot, 206 List ticks, 207 Rectangle2D dataArea) { 208 209 g2.setFont(plot.getAngleLabelFont()); 210 g2.setStroke(plot.getAngleGridlineStroke()); 211 g2.setPaint(plot.getAngleGridlinePaint()); 212 213 double axisMin = plot.getAxis().getLowerBound(); 214 double maxRadius = plot.getMaxRadius(); 215 216 Point center = plot.translateValueThetaRadiusToJava2D(axisMin, axisMin, 217 dataArea); 218 Iterator iterator = ticks.iterator(); 219 while (iterator.hasNext()) { 220 NumberTick tick = (NumberTick) iterator.next(); 221 Point p = plot.translateValueThetaRadiusToJava2D( 222 tick.getNumber().doubleValue(), maxRadius, dataArea); 223 g2.setPaint(plot.getAngleGridlinePaint()); 224 g2.drawLine(center.x, center.y, p.x, p.y); 225 if (plot.isAngleLabelsVisible()) { 226 int x = p.x; 227 int y = p.y; 228 g2.setPaint(plot.getAngleLabelPaint()); 229 TextUtilities.drawAlignedString(tick.getText(), g2, x, y, 230 TextAnchor.CENTER); 231 } 232 } 233 } 234 235 244 public void drawRadialGridLines(Graphics2D g2, 245 PolarPlot plot, 246 ValueAxis radialAxis, 247 List ticks, 248 Rectangle2D dataArea) { 249 250 g2.setFont(radialAxis.getTickLabelFont()); 251 g2.setPaint(plot.getRadiusGridlinePaint()); 252 g2.setStroke(plot.getRadiusGridlineStroke()); 253 254 double axisMin = radialAxis.getLowerBound(); 255 Point center = plot.translateValueThetaRadiusToJava2D(axisMin, axisMin, 256 dataArea); 257 258 Iterator iterator = ticks.iterator(); 259 while (iterator.hasNext()) { 260 NumberTick tick = (NumberTick) iterator.next(); 261 Point p = plot.translateValueThetaRadiusToJava2D(90.0, 262 tick.getNumber().doubleValue(), dataArea); 263 int r = p.x - center.x; 264 int upperLeftX = center.x - r; 265 int upperLeftY = center.y - r; 266 int d = 2 * r; 267 Ellipse2D ring = new Ellipse2D.Double (upperLeftX, upperLeftY, d, d); 268 g2.setPaint(plot.getRadiusGridlinePaint()); 269 g2.draw(ring); 270 } 271 } 272 273 280 public LegendItem getLegendItem(int series) { 281 LegendItem result = null; 282 PolarPlot polarPlot = getPlot(); 283 if (polarPlot != null) { 284 XYDataset dataset; 285 dataset = polarPlot.getDataset(); 286 if (dataset != null) { 287 String label = dataset.getSeriesKey(series).toString(); 288 String description = label; 289 Shape shape = getSeriesShape(series); 290 Paint paint = getSeriesPaint(series); 291 Paint outlinePaint = getSeriesOutlinePaint(series); 292 Stroke outlineStroke = getSeriesOutlineStroke(series); 293 result = new LegendItem(label, description, null, null, 294 shape, paint, outlineStroke, outlinePaint); 295 } 296 } 297 return result; 298 } 299 300 308 public boolean equals(Object obj) { 309 if (obj == null) { 310 return false; 311 } 312 if (!(obj instanceof DefaultPolarItemRenderer)) { 313 return false; 314 } 315 DefaultPolarItemRenderer that = (DefaultPolarItemRenderer) obj; 316 if (!this.seriesFilled.equals(that.seriesFilled)) { 317 return false; 318 } 319 return super.equals(obj); 320 } 321 322 329 public Object clone() throws CloneNotSupportedException { 330 return super.clone(); 331 } 332 333 } 334 | Popular Tags |