1:
48:
49: package ;
50:
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59: import ;
60: import ;
61: import ;
62: import ;
63:
64: import ;
65: import ;
66: import ;
67: import ;
68: import ;
69: import ;
70: import ;
71: import ;
72: import ;
73: import ;
74: import ;
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:
98:
99:
100:
101:
106: public DrawingSupplier getDrawingSupplier() {
107: DrawingSupplier result = null;
108: PolarPlot p = getPlot();
109: if (p != null) {
110: result = p.getDrawingSupplier();
111: }
112: return result;
113: }
114:
115:
116:
117:
118:
123: public void setPlot(PolarPlot plot) {
124: this.plot = plot;
125: }
126:
127:
132: public PolarPlot getPlot() {
133: return this.plot;
134: }
135:
136:
146: public void drawSeries(Graphics2D g2,
147: Rectangle2D dataArea,
148: PlotRenderingInfo info,
149: PolarPlot plot,
150: XYDataset dataset,
151: int seriesIndex) {
152:
153: Polygon poly = new Polygon();
154: int numPoints = dataset.getItemCount(seriesIndex);
155: for (int i = 0; i < numPoints; i++) {
156: double theta = dataset.getXValue(seriesIndex, i);
157: double radius = dataset.getYValue(seriesIndex, i);
158: Point p = plot.translateValueThetaRadiusToJava2D(
159: theta, radius, dataArea
160: );
161: poly.addPoint(p.x, p.y);
162: }
163: g2.setPaint(getSeriesPaint(seriesIndex));
164: g2.setStroke(getSeriesStroke(seriesIndex));
165: if (isSeriesFilled(seriesIndex)) {
166: Composite savedComposite = g2.getComposite();
167: g2.setComposite(
168: AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)
169: );
170: g2.fill(poly);
171: g2.setComposite(savedComposite);
172: }
173: else {
174: g2.draw(poly);
175: }
176: }
177:
178:
186: public boolean isSeriesFilled(int series) {
187: boolean result = false;
188: Boolean b = this.seriesFilled.getBoolean(series);
189: if (b != null) {
190: result = b.booleanValue();
191: }
192: return result;
193: }
194:
195:
201: public void setSeriesFilled(int series, boolean filled) {
202: this.seriesFilled.setBoolean(series, BooleanUtilities.valueOf(filled));
203: }
204:
205:
213: public void drawAngularGridLines(Graphics2D g2,
214: PolarPlot plot,
215: List ticks,
216: Rectangle2D dataArea) {
217:
218: g2.setFont(plot.getAngleLabelFont());
219: g2.setStroke(plot.getAngleGridlineStroke());
220: g2.setPaint(plot.getAngleGridlinePaint());
221:
222: double axisMin = plot.getAxis().getLowerBound();
223: double maxRadius = plot.getMaxRadius();
224:
225: Point center = plot.translateValueThetaRadiusToJava2D(
226: axisMin, axisMin, dataArea
227: );
228: Iterator iterator = ticks.iterator();
229: while (iterator.hasNext()) {
230: NumberTick tick = (NumberTick) iterator.next();
231: Point p = plot.translateValueThetaRadiusToJava2D(
232: tick.getNumber().doubleValue(), maxRadius, dataArea
233: );
234: g2.setPaint(plot.getAngleGridlinePaint());
235: g2.drawLine(center.x, center.y, p.x, p.y);
236: if (plot.isAngleLabelsVisible()) {
237: int x = p.x;
238: int y = p.y;
239: g2.setPaint(plot.getAngleLabelPaint());
240: TextUtilities.drawAlignedString(
241: tick.getText(), g2, x, y, TextAnchor.CENTER
242: );
243: }
244: }
245: }
246:
247:
256: public void drawRadialGridLines(Graphics2D g2,
257: PolarPlot plot,
258: ValueAxis radialAxis,
259: List ticks,
260: Rectangle2D dataArea) {
261:
262: g2.setFont(radialAxis.getTickLabelFont());
263: g2.setPaint(plot.getRadiusGridlinePaint());
264: g2.setStroke(plot.getRadiusGridlineStroke());
265:
266: double axisMin = radialAxis.getLowerBound();
267: Point center = plot.translateValueThetaRadiusToJava2D(
268: axisMin, axisMin, dataArea
269: );
270:
271: Iterator iterator = ticks.iterator();
272: while (iterator.hasNext()) {
273: NumberTick tick = (NumberTick) iterator.next();
274: Point p = plot.translateValueThetaRadiusToJava2D(
275: 90.0, tick.getNumber().doubleValue(), dataArea
276: );
277: int r = p.x - center.x;
278: int upperLeftX = center.x - r;
279: int upperLeftY = center.y - r;
280: int d = 2 * r;
281: Ellipse2D ring = new Ellipse2D.Double(upperLeftX, upperLeftY, d, d);
282: g2.setPaint(plot.getRadiusGridlinePaint());
283: g2.draw(ring);
284: }
285: }
286:
287:
294: public LegendItem getLegendItem(int series) {
295: LegendItem result = null;
296: PolarPlot polarPlot = getPlot();
297: if (polarPlot != null) {
298: XYDataset dataset;
299: dataset = polarPlot.getDataset();
300: if (dataset != null) {
301: String label = dataset.getSeriesKey(series).toString();
302: String description = label;
303: Shape shape = getSeriesShape(series);
304: Paint paint = getSeriesPaint(series);
305: Paint outlinePaint = getSeriesOutlinePaint(series);
306: Stroke outlineStroke = getSeriesOutlineStroke(series);
307: result = new LegendItem(label, description, null, null,
308: shape, paint, outlineStroke, outlinePaint);
309: }
310: }
311: return result;
312: }
313:
314:
322: public boolean equals(Object obj) {
323: if (obj == null) {
324: return false;
325: }
326: if (!(obj instanceof DefaultPolarItemRenderer)) {
327: return false;
328: }
329: DefaultPolarItemRenderer that = (DefaultPolarItemRenderer) obj;
330: if (!this.seriesFilled.equals(that.seriesFilled)) {
331: return false;
332: }
333: return super.equals(obj);
334: }
335:
336:
343: public Object clone() throws CloneNotSupportedException {
344: return super.clone();
345: }
346:
347: }