annotate gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonRenderer.java @ 781:5dd94448538d

Added timegap definitions as attribute to each state. gnv-artifacts/trunk@860 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 29 Mar 2010 10:02:42 +0000
parents c4156275c1e1
children cdade5005cba
rev   line source
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.gnv.jfreechart;
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
3 import java.awt.BasicStroke;
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 import java.awt.Color;
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
5 import java.awt.Font;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
6 import java.awt.FontMetrics;
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 import java.awt.Graphics2D;
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 import java.awt.Paint;
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 import java.awt.Shape;
447
92b7ccbf6163 Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
10
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 import java.awt.geom.GeneralPath;
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
12
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
13 import java.awt.geom.Rectangle2D.Double;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
14
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 import java.awt.geom.Rectangle2D;
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
16
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
17 import java.util.ArrayList;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
18
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
19 import org.apache.log4j.Logger;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
20
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
21 import org.jfree.chart.axis.ValueAxis;
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 import org.jfree.data.Range;
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
25 import org.jfree.text.TextUtilities;
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
26
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
27 import org.jfree.ui.RectangleEdge;
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
28
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 /**
780
c4156275c1e1 Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 779
diff changeset
30 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
c4156275c1e1 Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 779
diff changeset
31 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 */
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 public class PolygonRenderer
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 {
447
92b7ccbf6163 Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
35 private static Logger log = Logger.getLogger(
92b7ccbf6163 Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
36 PolygonRenderer.class);
92b7ccbf6163 Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
37
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 public interface PaintLookup {
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 Paint getPaint(int index);
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 } // interface PaintLookup
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
44 public static class DefaultLabelGenerator
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
45 implements PolygonSeriesLabelGenerator
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
46 {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
47 public DefaultLabelGenerator() {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
48 }
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
50 public String generateLabel(PolygonSeries series) {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
51 Object label = series.getAttribute("label");
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
52 return label != null
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
53 ? toString(label)
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
54 : null;
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
55 }
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
57 protected String toString(Object label) {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
58 return label.toString();
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
59 }
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
60 } // class DefaultLabelGenerator
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 451
diff changeset
62 public static final PolygonSeriesLabelGenerator
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
63 DEFAULT_LABEL_GENERATOR_INSTANCE = new DefaultLabelGenerator();
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
64
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
65 protected PaintLookup lookup;
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
66 protected PolygonSeriesLabelGenerator labelGenerator;
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 public PolygonRenderer(PaintLookup lookup) {
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
69 this(lookup, null);
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
72 public PolygonRenderer(
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 451
diff changeset
73 PaintLookup lookup,
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
74 PolygonSeriesLabelGenerator labelGenerator
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
75 ) {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
76 this.lookup = lookup;
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
77 this.labelGenerator = labelGenerator;
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
80 public void drawPolygons(
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81 Graphics2D graphics,
451
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
82 PolygonPlot plot,
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
83 Rectangle2D area,
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84 PolygonDataset dataset
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 ) {
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 int seriesCount = dataset.getSeriesCount();
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 for (int i = 0; i < seriesCount; i++) {
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 PolygonSeries series = dataset.getSeries(i);
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 Integer colorIdx = (Integer)series.getAttribute("fill");
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 if (colorIdx != null) {
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 Paint paint = lookup.getPaint(colorIdx.intValue());
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 graphics.setPaint(paint != null ? paint : Color.black);
451
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
94 graphics.fill(constructShape(plot, area, series, true));
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 else {
447
92b7ccbf6163 Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
97 Number lineWidth = (Number)series.getAttribute("line.width");
92b7ccbf6163 Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
98 BasicStroke stroke = new BasicStroke(
92b7ccbf6163 Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
99 lineWidth != null ? lineWidth.floatValue() : 1f);
92b7ccbf6163 Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
100 graphics.setStroke(stroke);
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 graphics.setPaint(Color.black);
451
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
102 graphics.draw(constructShape(plot, area, series, false));
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 }
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
105 }
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
106
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
107 public void drawLabels(
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
108 final Graphics2D graphics,
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
109 final PolygonPlot plot,
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
110 final Rectangle2D area,
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
111 PolygonDataset dataset
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
112 ) {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
113 if (labelGenerator == null) {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
114 return;
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
115 }
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
116
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
117 final ArrayList<Rectangle2D> bboxes = new ArrayList<Rectangle2D>();
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
118
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
119 Font font = graphics.getFont();
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
120 font = font.deriveFont(Font.PLAIN, Math.max(8, font.getSize()-3));
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
121 graphics.setFont(font);
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
122 FontMetrics metrics = graphics.getFontMetrics(font);
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
123
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
124 for (int i = dataset.getSeriesCount()-1; i >= 0; --i) {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
125 PolygonSeries series = dataset.getSeries(i);
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
126
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
127 String label = labelGenerator.generateLabel(series);
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
128 if (label == null) {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
129 continue;
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
130 }
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
131
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
132 final Rectangle2D box = TextUtilities.getTextBounds(
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
133 label, graphics, metrics);
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
134
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
135 for (int j = series.getItemCount()-1; j >= 0; --j) {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
136 final CompactXYItems ring = series.getItem(j);
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
137 LevelOrderIndices loi = new LevelOrderIndices(ring.size()-1);
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
138 Rectangle2D r = (Rectangle2D)loi.visit(
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 451
diff changeset
139 new LevelOrderIndices.Visitor()
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
140 {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
141 ValueAxis da = plot.getDomainAxis();
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
142 ValueAxis ra = plot.getRangeAxis();
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
143 RectangleEdge de = plot.getDomainAxisEdge();
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
144 RectangleEdge re = plot.getRangeAxisEdge();
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
145 Rectangle2D.Double r = new Rectangle2D.Double(
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
146 0d, 0d, box.getWidth(), box.getHeight());
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
147
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
148 public Object visit(int index) {
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 451
diff changeset
149 r.x = da.valueToJava2D(ring.getX(index), area, de)
450
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
150 - 0.5*box.getWidth();
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
151 r.y = ra.valueToJava2D(ring.getY(index), area, re)
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
152 + 0.5*box.getHeight();
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
153
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
154 for (Rectangle2D b: bboxes) {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
155 if (b.intersects(r)) {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
156 return null;
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
157 }
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
158 }
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
159 return r;
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
160 }
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
161 });
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
162
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
163 if (r != null) {
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
164 bboxes.add(r);
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
165 graphics.drawString(
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
166 label, (float)r.getX(), (float)r.getY());
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
167 }
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
168 } // for all items in series
20a480753ff9 Render labels in vertical cross section charts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 447
diff changeset
169 } // for all series
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
170 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
171
451
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
172 protected Shape constructShape(
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
173 PolygonPlot plot,
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
174 Rectangle2D area,
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 451
diff changeset
175 PolygonSeries series,
451
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
176 boolean close
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
177 ) {
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
178 ValueAxis da = plot.getDomainAxis();
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
179 ValueAxis ra = plot.getRangeAxis();
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
180 RectangleEdge de = plot.getDomainAxisEdge();
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
181 RectangleEdge re = plot.getRangeAxisEdge();
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
182
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
183 CompactXYItems [] rings = series.getRings();
451
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
184 GeneralPath path = new GeneralPath();
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
185
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
186 for (int i = 0; i < rings.length; ++i) {
451
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
187
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
188 CompactXYItems ring = rings[i];
451
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
189
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
190 double [] data = ring.getData();
451
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
191
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
192 if (data.length >= 2) {
451
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
193 path.moveTo(
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
194 (float)da.valueToJava2D(data[0], area, de),
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
195 (float)ra.valueToJava2D(data[1], area, re));
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
196 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
197 for (int j = 2; j < data.length;) {
451
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
198 path.lineTo(
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
199 (float)da.valueToJava2D(data[j++], area, de),
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 450
diff changeset
200 (float)ra.valueToJava2D(data[j++], area, re));
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
201 }
437
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 422
diff changeset
202 if (close) {
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 422
diff changeset
203 path.closePath();
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 422
diff changeset
204 }
422
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
205 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
206 return path;
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
207 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
208
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
209 public Rectangle2D getBoundingBox(PolygonDataset dataset) {
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
210 Rectangle2D bbox = null;
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
211
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
212 for (int i = 0, N = dataset.getSeriesCount(); i < N; i++) {
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
213 Range domain = dataset.getSeries(i).getDomainBounds();
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
214 Range range = dataset.getSeries(i).getRangeBounds();
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
215
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
216 double x = domain.getLowerBound();
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
217 double y = range.getLowerBound();
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
218 double w = Math.abs(domain.getUpperBound() - x);
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
219 double h = Math.abs(range.getUpperBound() - y);
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
220
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
221 if (bbox == null) {
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
222 bbox = new Rectangle2D.Double(x, y, w, h);
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
223 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
224 else {
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
225 bbox.add(new Rectangle2D.Double(x, y, w, h));
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
226 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
227 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
228
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
229 return bbox;
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
230 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
231
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
232 public Rectangle2D getBounds(PolygonSeries series) {
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
233
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
234 Range domain = series.getDomainBounds();
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
235 Range range = series.getRangeBounds();
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
236
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
237 return new Rectangle2D.Double(
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
238 domain.getLowerBound(), range.getLowerBound(),
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
239 domain.getUpperBound(), range.getUpperBound()
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
240 );
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
241 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
242 }
f426f55d4f7a Added Ingo Weinzierl's special JFreeChart classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
243 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org