1:
51:
52: package ;
53:
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59: import ;
60: import ;
61: import ;
62: import ;
63: import ;
64: import ;
65: import ;
66:
67: import ;
68: import ;
69: import ;
70: import ;
71: import ;
72: import ;
73: import ;
74: import ;
75: import ;
76: import ;
77: import ;
78:
79:
82: public class DefaultPolarItemRenderer extends AbstractRenderer
83: implements PolarItemRenderer {
84:
85:
86: private PolarPlot plot;
87:
88:
89: private BooleanList seriesFilled;
90:
91:
94: public DefaultPolarItemRenderer() {
95: this.seriesFilled = new BooleanList();
96: }
97:
98:
105: public void setPlot(PolarPlot plot) {
106: this.plot = plot;
107: }
108:
109:
116: public PolarPlot getPlot() {
117: return this.plot;
118: }
119:
120:
125: public DrawingSupplier getDrawingSupplier() {
126: DrawingSupplier result = null;
127: PolarPlot p = getPlot();
128: if (p != null) {
129: result = p.getDrawingSupplier();
130: }
131: return result;
132: }
133:
134:
142: public boolean isSeriesFilled(int series) {
143: boolean result = false;
144: Boolean b = this.seriesFilled.getBoolean(series);
145: if (b != null) {
146: result = b.booleanValue();
147: }
148: return result;
149: }
150:
151:
157: public void setSeriesFilled(int series, boolean filled) {
158: this.seriesFilled.setBoolean(series, BooleanUtilities.valueOf(filled));
159: }
160:
161:
171: public void drawSeries(Graphics2D g2,
172: Rectangle2D dataArea,
173: PlotRenderingInfo info,
174: PolarPlot plot,
175: XYDataset dataset,
176: int seriesIndex) {
177:
178: Polygon poly = new Polygon();
179: int numPoints = dataset.getItemCount(seriesIndex);
180: for (int i = 0; i < numPoints; i++) {
181: double theta = dataset.getXValue(seriesIndex, i);
182: double radius = dataset.getYValue(seriesIndex, i);
183: Point p = plot.translateValueThetaRadiusToJava2D(theta, radius,
184: dataArea);
185: poly.addPoint(p.x, p.y);
186: }
187: g2.setPaint(getSeriesPaint(seriesIndex));
188: g2.setStroke(getSeriesStroke(seriesIndex));
189: if (isSeriesFilled(seriesIndex)) {
190: Composite savedComposite = g2.getComposite();
191: g2.setComposite(AlphaComposite.getInstance(
192: AlphaComposite.SRC_OVER, 0.5f));
193: g2.fill(poly);
194: g2.setComposite(savedComposite);
195: }
196: else {
197: g2.draw(poly);
198: }
199: }
200:
201:
209: public void drawAngularGridLines(Graphics2D g2,
210: PolarPlot plot,
211: List ticks,
212: Rectangle2D dataArea) {
213:
214: g2.setFont(plot.getAngleLabelFont());
215: g2.setStroke(plot.getAngleGridlineStroke());
216: g2.setPaint(plot.getAngleGridlinePaint());
217:
218: double axisMin = plot.getAxis().getLowerBound();
219: double maxRadius = plot.getMaxRadius();
220:
221: Point center = plot.translateValueThetaRadiusToJava2D(axisMin, axisMin,
222: dataArea);
223: Iterator iterator = ticks.iterator();
224: while (iterator.hasNext()) {
225: NumberTick tick = (NumberTick) iterator.next();
226: Point p = plot.translateValueThetaRadiusToJava2D(
227: tick.getNumber().doubleValue(), maxRadius, dataArea);
228: g2.setPaint(plot.getAngleGridlinePaint());
229: g2.drawLine(center.x, center.y, p.x, p.y);
230: if (plot.isAngleLabelsVisible()) {
231: int x = p.x;
232: int y = p.y;
233: g2.setPaint(plot.getAngleLabelPaint());
234: TextUtilities.drawAlignedString(tick.getText(), g2, x, y,
235: TextAnchor.CENTER);
236: }
237: }
238: }
239:
240:
249: public void drawRadialGridLines(Graphics2D g2,
250: PolarPlot plot,
251: ValueAxis radialAxis,
252: List ticks,
253: Rectangle2D dataArea) {
254:
255: g2.setFont(radialAxis.getTickLabelFont());
256: g2.setPaint(plot.getRadiusGridlinePaint());
257: g2.setStroke(plot.getRadiusGridlineStroke());
258:
259: double axisMin = radialAxis.getLowerBound();
260: Point center = plot.translateValueThetaRadiusToJava2D(axisMin, axisMin,
261: dataArea);
262:
263: Iterator iterator = ticks.iterator();
264: while (iterator.hasNext()) {
265: NumberTick tick = (NumberTick) iterator.next();
266: Point p = plot.translateValueThetaRadiusToJava2D(90.0,
267: tick.getNumber().doubleValue(), dataArea);
268: int r = p.x - center.x;
269: int upperLeftX = center.x - r;
270: int upperLeftY = center.y - r;
271: int d = 2 * r;
272: Ellipse2D ring = new Ellipse2D.Double(upperLeftX, upperLeftY, d, d);
273: g2.setPaint(plot.getRadiusGridlinePaint());
274: g2.draw(ring);
275: }
276: }
277:
278:
285: public LegendItem getLegendItem(int series) {
286: LegendItem result = null;
287: PolarPlot polarPlot = getPlot();
288: if (polarPlot != null) {
289: XYDataset dataset;
290: dataset = polarPlot.getDataset();
291: if (dataset != null) {
292: String label = dataset.getSeriesKey(series).toString();
293: String description = label;
294: Shape shape = getSeriesShape(series);
295: Paint paint = getSeriesPaint(series);
296: Paint outlinePaint = getSeriesOutlinePaint(series);
297: Stroke outlineStroke = getSeriesOutlineStroke(series);
298: result = new LegendItem(label, description, null, null,
299: shape, paint, outlineStroke, outlinePaint);
300: }
301: }
302: return result;
303: }
304:
305:
313: public boolean equals(Object obj) {
314: if (obj == null) {
315: return false;
316: }
317: if (!(obj instanceof DefaultPolarItemRenderer)) {
318: return false;
319: }
320: DefaultPolarItemRenderer that = (DefaultPolarItemRenderer) obj;
321: if (!this.seriesFilled.equals(that.seriesFilled)) {
322: return false;
323: }
324: return super.equals(obj);
325: }
326:
327:
334: public Object clone() throws CloneNotSupportedException {
335: DefaultPolarItemRenderer clone
336: = (DefaultPolarItemRenderer) super.clone();
337: clone.seriesFilled = (BooleanList) this.seriesFilled.clone();
338: return clone;
339: }
340:
341: }