comparison gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonRenderer.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
25 import org.jfree.text.TextUtilities; 25 import org.jfree.text.TextUtilities;
26 26
27 import org.jfree.ui.RectangleEdge; 27 import org.jfree.ui.RectangleEdge;
28 28
29 /** 29 /**
30 * This renderer is used to draw polygons into a Graphics object.
31 *
30 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 32 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
31 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> 33 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
32 */ 34 */
33 public class PolygonRenderer 35 public class PolygonRenderer
34 { 36 {
35 private static Logger log = Logger.getLogger( 37 private static Logger log = Logger.getLogger(
36 PolygonRenderer.class); 38 PolygonRenderer.class);
37 39
38 public interface PaintLookup { 40 /**
39 41 * This interfaces describes a single method to retrieve a Paint object
40 Paint getPaint(int index); 42 * for a given index.
43 */
44 public interface PaintLookup {
45
46 /**
47 *
48 * @param index Index.
49 * @return Paint
50 */
51 Paint getPaint(int index);
41 52
42 } // interface PaintLookup 53 } // interface PaintLookup
43 54
44 public static class DefaultLabelGenerator 55 /**
56 * This class is used to generate labels for a given series.
57 */
58 public static class DefaultLabelGenerator
45 implements PolygonSeriesLabelGenerator 59 implements PolygonSeriesLabelGenerator
46 { 60 {
47 public DefaultLabelGenerator() { 61 /**
48 } 62 * Construts an empty DefaultLabelGenerator.
49 63 */
50 public String generateLabel(PolygonSeries series) { 64 public DefaultLabelGenerator() {
65 }
66
67 /**
68 *
69 * @param series A PolygonSeries.
70 * @return The label of series.
71 */
72 public String generateLabel(PolygonSeries series) {
51 Object label = series.getAttribute("label"); 73 Object label = series.getAttribute("label");
52 return label != null 74 return label != null
53 ? toString(label) 75 ? toString(label)
54 : null; 76 : null;
55 } 77 }
56 78
57 protected String toString(Object label) { 79 /**
80 *
81 * @param label Object
82 * @return String representaton of label.
83 */
84 protected String toString(Object label) {
58 return label.toString(); 85 return label.toString();
59 } 86 }
60 } // class DefaultLabelGenerator 87 } // class DefaultLabelGenerator
61 88
62 public static final PolygonSeriesLabelGenerator 89 /**
90 * Constructor.
91 */
92 public static final PolygonSeriesLabelGenerator
63 DEFAULT_LABEL_GENERATOR_INSTANCE = new DefaultLabelGenerator(); 93 DEFAULT_LABEL_GENERATOR_INSTANCE = new DefaultLabelGenerator();
64 94
65 protected PaintLookup lookup; 95 /**
96 *
97 */
98 protected PaintLookup lookup;
99 /**
100 *
101 */
66 protected PolygonSeriesLabelGenerator labelGenerator; 102 protected PolygonSeriesLabelGenerator labelGenerator;
67 103
104 /**
105 *
106 * @param lookup
107 */
68 public PolygonRenderer(PaintLookup lookup) { 108 public PolygonRenderer(PaintLookup lookup) {
69 this(lookup, null); 109 this(lookup, null);
70 } 110 }
71 111
112 /**
113 *
114 * @param lookup
115 * @param labelGenerator
116 */
72 public PolygonRenderer( 117 public PolygonRenderer(
73 PaintLookup lookup, 118 PaintLookup lookup,
74 PolygonSeriesLabelGenerator labelGenerator 119 PolygonSeriesLabelGenerator labelGenerator
75 ) { 120 ) {
76 this.lookup = lookup; 121 this.lookup = lookup;
77 this.labelGenerator = labelGenerator; 122 this.labelGenerator = labelGenerator;
78 } 123 }
79 124
125 /**
126 * This method draws polygons of each series in <code>dataset</code> into
127 * the given graphics object. If a polygon has no attribute 'fill', we
128 * expect that it is a line, otherwise the polygon is filled.
129 *
130 * @param graphics
131 * @param plot
132 * @param area
133 * @param dataset
134 */
80 public void drawPolygons( 135 public void drawPolygons(
81 Graphics2D graphics, 136 Graphics2D graphics,
82 PolygonPlot plot, 137 PolygonPlot plot,
83 Rectangle2D area, 138 Rectangle2D area,
84 PolygonDataset dataset 139 PolygonDataset dataset
102 graphics.draw(constructShape(plot, area, series, false)); 157 graphics.draw(constructShape(plot, area, series, false));
103 } 158 }
104 } 159 }
105 } 160 }
106 161
162 /**
163 * Draw labels at each item of a series in the given dataset. If the series
164 * has no label attritue, no label is drawn.
165 *
166 * @param graphics
167 * @param plot
168 * @param area
169 * @param dataset
170 */
107 public void drawLabels( 171 public void drawLabels(
108 final Graphics2D graphics, 172 final Graphics2D graphics,
109 final PolygonPlot plot, 173 final PolygonPlot plot,
110 final Rectangle2D area, 174 final Rectangle2D area,
111 PolygonDataset dataset 175 PolygonDataset dataset
167 } 231 }
168 } // for all items in series 232 } // for all items in series
169 } // for all series 233 } // for all series
170 } 234 }
171 235
236 /**
237 * Creates a shape made up of the CompactXYItems object stored in the given
238 * series.
239 *
240 * @param plot The plot.
241 * @param area The boundary.
242 * @param series The series storing the items.
243 * @param close Specifies if the polygon should be closed or not.
244 * @return
245 */
172 protected Shape constructShape( 246 protected Shape constructShape(
173 PolygonPlot plot, 247 PolygonPlot plot,
174 Rectangle2D area, 248 Rectangle2D area,
175 PolygonSeries series, 249 PolygonSeries series,
176 boolean close 250 boolean close
204 } 278 }
205 } 279 }
206 return path; 280 return path;
207 } 281 }
208 282
283 /**
284 * Retrieves the bounding box of a dataset.
285 *
286 * @param dataset
287 * @return
288 */
209 public Rectangle2D getBoundingBox(PolygonDataset dataset) { 289 public Rectangle2D getBoundingBox(PolygonDataset dataset) {
210 Rectangle2D bbox = null; 290 Rectangle2D bbox = null;
211 291
212 for (int i = 0, N = dataset.getSeriesCount(); i < N; i++) { 292 for (int i = 0, N = dataset.getSeriesCount(); i < N; i++) {
213 Range domain = dataset.getSeries(i).getDomainBounds(); 293 Range domain = dataset.getSeries(i).getDomainBounds();
227 } 307 }
228 308
229 return bbox; 309 return bbox;
230 } 310 }
231 311
312 /**
313 *
314 * @param series
315 * @return the bounds of a series.
316 */
232 public Rectangle2D getBounds(PolygonSeries series) { 317 public Rectangle2D getBounds(PolygonSeries series) {
233 318
234 Range domain = series.getDomainBounds(); 319 Range domain = series.getDomainBounds();
235 Range range = series.getRangeBounds(); 320 Range range = series.getRangeBounds();
236 321

http://dive4elements.wald.intevation.org