comparison gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonPlot.java @ 795:cdade5005cba

Added javadoc in jfreechart package. gnv-artifacts/trunk@877 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 31 Mar 2010 13:48:07 +0000
parents c4156275c1e1
children feae2f9d6c6f
comparison
equal deleted inserted replaced
794:d0967fdee36f 795:cdade5005cba
30 import org.jfree.ui.RectangleInsets; 30 import org.jfree.ui.RectangleInsets;
31 31
32 import org.jfree.util.ObjectList; 32 import org.jfree.util.ObjectList;
33 33
34 /** 34 /**
35 * A class for plotting polygons into a 2D chart. This plot makes use of <code>
36 * PolygonRenderer</code>.
37 *
35 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 38 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
36 */ 39 */
37 // TODO implement cloneable 40 // TODO implement cloneable
38 public class PolygonPlot 41 public class PolygonPlot
39 extends Plot 42 extends Plot
40 { 43 {
44 /**
45 *
46 */
41 public static final String PLOT_TYPE = "PolygonPlot"; 47 public static final String PLOT_TYPE = "PolygonPlot";
42 48
49 /**
50 *
51 */
43 public static final PlotOrientation DEFAULT_PLOT_ORIENTATION = 52 public static final PlotOrientation DEFAULT_PLOT_ORIENTATION =
44 PlotOrientation.VERTICAL; 53 PlotOrientation.VERTICAL;
45 54
46 private PolygonDataset dataset; 55 private PolygonDataset dataset;
47 private transient PolygonRenderer renderer; 56 private transient PolygonRenderer renderer;
54 private ObjectList rangeAxisLocation; 63 private ObjectList rangeAxisLocation;
55 private ObjectList domainAxes; 64 private ObjectList domainAxes;
56 private ObjectList rangeAxes; 65 private ObjectList rangeAxes;
57 66
58 67
68 /**
69 * Constructs a new PolygonPlot with a dataset and a renderer.
70 *
71 * @param dataset Dataset containing polygons.
72 * @param renderer The renderer used to draw polygons.
73 */
59 public PolygonPlot(PolygonDataset dataset, PolygonRenderer renderer) { 74 public PolygonPlot(PolygonDataset dataset, PolygonRenderer renderer) {
60 this(dataset, renderer, null, null, PlotOrientation.HORIZONTAL); 75 this(dataset, renderer, null, null, PlotOrientation.HORIZONTAL);
61 } 76 }
62 77
63 78
79 /**
80 *
81 * @param dataset Dataset containing polygons.
82 * @param renderer The renderer used to draw polygons.
83 * @param orientation The orientation used for this plot.
84 */
64 public PolygonPlot( 85 public PolygonPlot(
65 PolygonDataset dataset, 86 PolygonDataset dataset,
66 PolygonRenderer renderer, 87 PolygonRenderer renderer,
67 PlotOrientation orientation 88 PlotOrientation orientation
68 ) { 89 ) {
69 this(dataset, renderer, null, null, orientation); 90 this(dataset, renderer, null, null, orientation);
70 } 91 }
71 92
72 93
94 /**
95 *
96 * @param dataset Dataset containing polygons.
97 * @param renderer The renderer used to draw polygons.
98 * @param domainAxis The x axis.
99 * @param rangeAxis The y axis.
100 * @param orientation The orientation used for this plot.
101 */
73 public PolygonPlot( 102 public PolygonPlot(
74 PolygonDataset dataset, 103 PolygonDataset dataset,
75 PolygonRenderer renderer, 104 PolygonRenderer renderer,
76 ValueAxis domainAxis, 105 ValueAxis domainAxis,
77 ValueAxis rangeAxis, 106 ValueAxis rangeAxis,
107 configureDomainAxis(); 136 configureDomainAxis();
108 configureRangeAxis(); 137 configureRangeAxis();
109 } 138 }
110 139
111 140
141 /**
142 *
143 */
112 public void configureDomainAxis() { 144 public void configureDomainAxis() {
113 // we just have 1 dataset 145 // we just have 1 dataset
114 Range domainAxisRange = getDataset().getDomainBounds(); 146 Range domainAxisRange = getDataset().getDomainBounds();
115 147
116 for (int i = 0; i < domainAxes.size(); i++) { 148 for (int i = 0; i < domainAxes.size(); i++) {
121 axis.setRange(domainAxisRange); 153 axis.setRange(domainAxisRange);
122 } 154 }
123 } 155 }
124 } 156 }
125 157
158 /**
159 *
160 * @return
161 */
126 public ValueAxis getDomainAxis() { 162 public ValueAxis getDomainAxis() {
127 return getDomainAxis(0); 163 return getDomainAxis(0);
128 } 164 }
129 165
166 /**
167 *
168 * @param index
169 * @return
170 */
130 public ValueAxis getDomainAxis(int index) { 171 public ValueAxis getDomainAxis(int index) {
131 return index < domainAxes.size() 172 return index < domainAxes.size()
132 ? (ValueAxis)domainAxes.get(index) 173 ? (ValueAxis)domainAxes.get(index)
133 : null; 174 : null;
134 } 175 }
135 176
177 /**
178 *
179 * @return
180 */
136 public ValueAxis getRangeAxis() { 181 public ValueAxis getRangeAxis() {
137 return getRangeAxis(0); 182 return getRangeAxis(0);
138 } 183 }
139 184
185 /**
186 *
187 * @param index
188 * @return
189 */
140 public ValueAxis getRangeAxis(int index) { 190 public ValueAxis getRangeAxis(int index) {
141 return index < rangeAxes.size() 191 return index < rangeAxes.size()
142 ? (ValueAxis)rangeAxes.get(index) 192 ? (ValueAxis)rangeAxes.get(index)
143 : null; 193 : null;
144 } 194 }
145 195
196 /**
197 *
198 */
146 public void configureRangeAxis() { 199 public void configureRangeAxis() {
147 // we just have 1 dataset 200 // we just have 1 dataset
148 Range rangeAxisRange = getDataset().getRangeBounds(); 201 Range rangeAxisRange = getDataset().getRangeBounds();
149 202
150 for (int i = 0; i < rangeAxes.size(); i++) { 203 for (int i = 0; i < rangeAxes.size(); i++) {
156 } 209 }
157 } 210 }
158 } 211 }
159 212
160 213
214 /**
215 *
216 * @return
217 */
161 public PolygonDataset getDataset(){ 218 public PolygonDataset getDataset(){
162 return this.dataset; 219 return this.dataset;
163 } 220 }
164 221
165 222
223 /**
224 *
225 * @return
226 */
166 public String getPlotType() { 227 public String getPlotType() {
167 return PLOT_TYPE; 228 return PLOT_TYPE;
168 } 229 }
169 230
170 231
232 /**
233 *
234 * @param dataset
235 */
171 public void setDataset(PolygonDataset dataset) { 236 public void setDataset(PolygonDataset dataset) {
172 this.dataset = dataset; 237 this.dataset = dataset;
173 } 238 }
174 239
175 240
241 /**
242 * This is the major method to draw the into a given Graphic2D object.
243 *
244 * @param g2 Graphics object where the plot is drawn into.
245 * @param area The bounds for drawing this plot.
246 * @param anchor An anchor point.
247 * @param parentState The plot state.
248 * @param info
249 */
176 public void draw( 250 public void draw(
177 Graphics2D g2, 251 Graphics2D g2,
178 Rectangle2D area, 252 Rectangle2D area,
179 Point2D anchor, 253 Point2D anchor,
180 PlotState parentState, 254 PlotState parentState,
216 g2.setClip(savedClip); 290 g2.setClip(savedClip);
217 g2.setComposite(originalComposite); 291 g2.setComposite(originalComposite);
218 } 292 }
219 293
220 294
295 /**
296 * Method to draw the axis for this plot.
297 *
298 * @param g2
299 * @param plotArea
300 * @param dataArea
301 * @param plotState
302 */
221 private void drawAxes( 303 private void drawAxes(
222 Graphics2D g2, 304 Graphics2D g2,
223 Rectangle2D plotArea, 305 Rectangle2D plotArea,
224 Rectangle2D dataArea, 306 Rectangle2D dataArea,
225 PlotRenderingInfo plotState 307 PlotRenderingInfo plotState
288 axisStateMap.put(axis, info); 370 axisStateMap.put(axis, info);
289 } 371 }
290 } 372 }
291 373
292 374
375 /**
376 * Put some labels at data items into the plot. Uses PolygonRenderer to do
377 * this job.
378 *
379 * @param g2
380 * @param area
381 * @param info
382 */
293 private void drawLabels( 383 private void drawLabels(
294 Graphics2D g2, 384 Graphics2D g2,
295 Rectangle2D area, 385 Rectangle2D area,
296 PlotRenderingInfo info 386 PlotRenderingInfo info
297 ) { 387 ) {
298 renderer.drawLabels(g2, this, area, dataset); 388 renderer.drawLabels(g2, this, area, dataset);
299 } 389 }
300 390
391
392 /**
393 * Plot the polygons. Uses PolygonRenderer to do this job.
394 *
395 * @param g2
396 * @param area
397 * @param info
398 */
301 private void drawPolygons( 399 private void drawPolygons(
302 Graphics2D g2, 400 Graphics2D g2,
303 Rectangle2D area, 401 Rectangle2D area,
304 PlotRenderingInfo info 402 PlotRenderingInfo info
305 ) { 403 ) {
306 renderer.drawPolygons(g2, this, area, dataset); 404 renderer.drawPolygons(g2, this, area, dataset);
307 } 405 }
308 406
309 407
408 /**
409 *
410 * @param g2
411 * @param plotArea
412 * @return
413 */
310 private AxisSpace calculateAxisSpace(Graphics2D g2, Rectangle2D plotArea) { 414 private AxisSpace calculateAxisSpace(Graphics2D g2, Rectangle2D plotArea) {
311 AxisSpace space = new AxisSpace(); 415 AxisSpace space = new AxisSpace();
312 space = calculateRangeAxisSpace(g2, plotArea, space); 416 space = calculateRangeAxisSpace(g2, plotArea, space);
313 Rectangle2D tmpPlotArea = space.shrink(plotArea, null); 417 Rectangle2D tmpPlotArea = space.shrink(plotArea, null);
314 space = calculateDomainAxisSpace(g2, plotArea, space); 418 space = calculateDomainAxisSpace(g2, plotArea, space);
315 419
316 return space; 420 return space;
317 } 421 }
318 422
319 423
424 /**
425 *
426 * @param g2
427 * @param plotArea
428 * @param space
429 * @return
430 */
320 private AxisSpace calculateDomainAxisSpace( 431 private AxisSpace calculateDomainAxisSpace(
321 Graphics2D g2, 432 Graphics2D g2,
322 Rectangle2D plotArea, 433 Rectangle2D plotArea,
323 AxisSpace space 434 AxisSpace space
324 ) { 435 ) {
336 447
337 return space; 448 return space;
338 } 449 }
339 450
340 451
452 /**
453 *
454 * @param g2
455 * @param plotArea
456 * @param space
457 * @return
458 */
341 private AxisSpace calculateRangeAxisSpace( 459 private AxisSpace calculateRangeAxisSpace(
342 Graphics2D g2, 460 Graphics2D g2,
343 Rectangle2D plotArea, 461 Rectangle2D plotArea,
344 AxisSpace space 462 AxisSpace space
345 ) { 463 ) {
356 } 474 }
357 475
358 return space; 476 return space;
359 } 477 }
360 478
479
480 /**
481 *
482 * @return
483 */
361 public RectangleEdge getDomainAxisEdge() { 484 public RectangleEdge getDomainAxisEdge() {
362 return Plot.resolveDomainAxisLocation( 485 return Plot.resolveDomainAxisLocation(
363 getDomainAxisLocation(), orientation 486 getDomainAxisLocation(), orientation
364 ); 487 );
365 } 488 }
366 489
367 490
491 /**
492 *
493 * @param idx
494 * @return
495 */
368 public RectangleEdge getDomainAxisEdge(int idx) { 496 public RectangleEdge getDomainAxisEdge(int idx) {
369 AxisLocation location = getDomainAxisLocation(idx); 497 AxisLocation location = getDomainAxisLocation(idx);
370 RectangleEdge result = Plot.resolveDomainAxisLocation( 498 RectangleEdge result = Plot.resolveDomainAxisLocation(
371 location, orientation 499 location, orientation
372 ); 500 );
376 504
377 return result; 505 return result;
378 } 506 }
379 507
380 508
509 /**
510 *
511 * @return
512 */
381 public RectangleEdge getRangeAxisEdge() { 513 public RectangleEdge getRangeAxisEdge() {
382 return Plot.resolveRangeAxisLocation( 514 return Plot.resolveRangeAxisLocation(
383 getRangeAxisLocation(), orientation 515 getRangeAxisLocation(), orientation
384 ); 516 );
385 } 517 }
386 518
387 519
520 /**
521 *
522 * @param idx
523 * @return
524 */
388 public RectangleEdge getRangeAxisEdge(int idx) { 525 public RectangleEdge getRangeAxisEdge(int idx) {
389 AxisLocation location = getRangeAxisLocation(idx); 526 AxisLocation location = getRangeAxisLocation(idx);
390 RectangleEdge result = Plot.resolveRangeAxisLocation( 527 RectangleEdge result = Plot.resolveRangeAxisLocation(
391 location, 528 location,
392 orientation 529 orientation
397 534
398 return result; 535 return result;
399 } 536 }
400 537
401 538
539 /**
540 *
541 * @return
542 */
402 public AxisLocation getDomainAxisLocation() { 543 public AxisLocation getDomainAxisLocation() {
403 return (AxisLocation) domainAxisLocation.get(0); 544 return (AxisLocation) domainAxisLocation.get(0);
404 } 545 }
405 546
406 547
548 /**
549 *
550 * @param idx
551 * @return
552 */
407 public AxisLocation getDomainAxisLocation(int idx) { 553 public AxisLocation getDomainAxisLocation(int idx) {
408 if (idx < domainAxisLocation.size()) 554 if (idx < domainAxisLocation.size())
409 return (AxisLocation) domainAxisLocation.get(idx); 555 return (AxisLocation) domainAxisLocation.get(idx);
410 556
411 return null; 557 return null;
412 } 558 }
413 559
414 560
561 /**
562 *
563 * @return
564 */
415 public AxisLocation getRangeAxisLocation() { 565 public AxisLocation getRangeAxisLocation() {
416 return (AxisLocation) rangeAxisLocation.get(0); 566 return (AxisLocation) rangeAxisLocation.get(0);
417 } 567 }
418 568
419 569
570 /**
571 *
572 * @param idx
573 * @return
574 */
420 public AxisLocation getRangeAxisLocation(int idx) { 575 public AxisLocation getRangeAxisLocation(int idx) {
421 if (idx < rangeAxisLocation.size()) 576 if (idx < rangeAxisLocation.size())
422 return (AxisLocation) rangeAxisLocation.get(idx); 577 return (AxisLocation) rangeAxisLocation.get(idx);
423 578
424 return null; 579 return null;
425 } 580 }
426 581
427 582
583 /**
584 *
585 * @param dataset
586 * @return true, if dataset is null or if it does not contain any
587 * PolygonSeries, otherwise false.
588 */
428 private boolean isEmptyOrNull(PolygonDataset dataset) { 589 private boolean isEmptyOrNull(PolygonDataset dataset) {
429 if (dataset != null) { 590 if (dataset != null) {
430 int seriesCount = dataset.getSeriesCount(); 591 int seriesCount = dataset.getSeriesCount();
431 for (int s = 0; s < seriesCount; s++) { 592 for (int s = 0; s < seriesCount; s++) {
432 PolygonSeries series = dataset.getSeries(s); 593 PolygonSeries series = dataset.getSeries(s);
436 } 597 }
437 } 598 }
438 return true; 599 return true;
439 } 600 }
440 } 601 }
602 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org