Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/exports/StyledXYSeries.java @ 3815:ecab7e7804a9 pre2.6-2012-01-04
merged flys-backend/pre2.6-2012-01-04
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:57 +0200 |
parents | e384d78ff78b |
children | 4cdd9c4896f6 |
rev | line source |
---|---|
924
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.exports; |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import java.awt.BasicStroke; |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 import java.awt.Color; |
1753
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
5 import java.awt.geom.Ellipse2D; |
924
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 import org.apache.log4j.Logger; |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import org.w3c.dom.Document; |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 import org.jfree.data.xy.XYSeries; |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 |
1753
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
14 import de.intevation.flys.utils.ThemeUtil; |
924
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 |
1814
a9b690d864a7
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1754
diff
changeset
|
16 /** |
2017
e384d78ff78b
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1963
diff
changeset
|
17 * Dataseries in two dimensions with additional theme-document and further |
e384d78ff78b
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1963
diff
changeset
|
18 * display options. |
1814
a9b690d864a7
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1754
diff
changeset
|
19 * The theme-document will later "style" the graphical representation. |
2017
e384d78ff78b
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1963
diff
changeset
|
20 * The display options can be used to control the z-order and the axis of the |
e384d78ff78b
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1963
diff
changeset
|
21 * dataseries. |
1814
a9b690d864a7
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1754
diff
changeset
|
22 */ |
924
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 public class StyledXYSeries extends XYSeries { |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 protected Document theme; |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 private static final Logger logger = Logger.getLogger(StyledXYSeries.class); |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 |
1741
1bc926b5b435
Fix for flys/issue316
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1714
diff
changeset
|
30 public StyledXYSeries(String key, Document theme) { |
1bc926b5b435
Fix for flys/issue316
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1714
diff
changeset
|
31 this(key, true, theme); |
1bc926b5b435
Fix for flys/issue316
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1714
diff
changeset
|
32 } |
924
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 |
1814
a9b690d864a7
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1754
diff
changeset
|
34 |
a9b690d864a7
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1754
diff
changeset
|
35 /** |
a9b690d864a7
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1754
diff
changeset
|
36 * @param sorted whether or not to sort the points. Sorting will move NANs |
a9b690d864a7
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1754
diff
changeset
|
37 * to one extrema which can cause problems in certain |
a9b690d864a7
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1754
diff
changeset
|
38 * algorithms. |
a9b690d864a7
Cosmetics, doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1754
diff
changeset
|
39 */ |
1741
1bc926b5b435
Fix for flys/issue316
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1714
diff
changeset
|
40 public StyledXYSeries(String key, boolean sorted, Document theme) { |
1bc926b5b435
Fix for flys/issue316
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1714
diff
changeset
|
41 super(key, sorted); |
924
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 this.theme = theme; |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 } |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 |
2017
e384d78ff78b
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1963
diff
changeset
|
46 /** |
e384d78ff78b
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1963
diff
changeset
|
47 * Applies line color, size and type attributes to renderer, also |
e384d78ff78b
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1963
diff
changeset
|
48 * whether to draw lines and/or points. |
e384d78ff78b
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1963
diff
changeset
|
49 */ |
924
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 public XYLineAndShapeRenderer applyTheme(XYLineAndShapeRenderer r, int idx){ |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 applyLineColor(r, idx); |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 applyLineSize(r, idx); |
1714
004b1b0838d6
Apply line type to styled themes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
924
diff
changeset
|
53 applyLineType(r, idx); |
1753
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
54 applyShowLine(r, idx); |
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
55 applyShowPoints(r, idx); |
924
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 return r; |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 } |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 |
2017
e384d78ff78b
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1963
diff
changeset
|
61 /** Set line color to renderer. */ |
924
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 protected void applyLineColor(XYLineAndShapeRenderer r, int idx) { |
1753
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
63 Color c = ThemeUtil.parseLineColorField(theme); |
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
64 r.setSeriesPaint(idx, c); |
924
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 } |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 protected void applyLineSize(XYLineAndShapeRenderer r, int idx) { |
1753
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
69 int size = ThemeUtil.parseLineWidth(theme); |
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
70 r.setSeriesStroke( |
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
71 idx, |
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
72 new BasicStroke(Integer.valueOf(size))); |
924
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 } |
1714
004b1b0838d6
Apply line type to styled themes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
924
diff
changeset
|
74 |
004b1b0838d6
Apply line type to styled themes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
924
diff
changeset
|
75 |
004b1b0838d6
Apply line type to styled themes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
924
diff
changeset
|
76 protected void applyLineType(XYLineAndShapeRenderer r, int idx) { |
1753
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
77 int size = ThemeUtil.parseLineWidth(theme); |
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
78 float[] dashes = ThemeUtil.parseLineStyle(theme); |
1714
004b1b0838d6
Apply line type to styled themes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
924
diff
changeset
|
79 |
1753
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
80 // Do not apply the dashed style. |
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
81 if (dashes.length <= 1) { |
1714
004b1b0838d6
Apply line type to styled themes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
924
diff
changeset
|
82 return; |
004b1b0838d6
Apply line type to styled themes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
924
diff
changeset
|
83 } |
004b1b0838d6
Apply line type to styled themes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
924
diff
changeset
|
84 |
1753
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
85 r.setSeriesStroke( |
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
86 idx, |
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
87 new BasicStroke(Integer.valueOf(size), |
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
88 BasicStroke.CAP_BUTT, |
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
89 BasicStroke.JOIN_ROUND, |
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
90 1.0f, |
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
91 dashes, |
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
92 0.0f)); |
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
93 } |
1714
004b1b0838d6
Apply line type to styled themes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
924
diff
changeset
|
94 |
1753
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
95 |
2017
e384d78ff78b
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1963
diff
changeset
|
96 /** |
e384d78ff78b
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1963
diff
changeset
|
97 * Sets form and visibility of points. |
e384d78ff78b
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1963
diff
changeset
|
98 */ |
1753
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
99 protected void applyShowPoints(XYLineAndShapeRenderer r, int idx) { |
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
100 boolean show = ThemeUtil.parseShowPoints(theme); |
1963
6c24ffe946a5
Issue 413.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1814
diff
changeset
|
101 int size = ThemeUtil.parseLineWidth(theme); |
6c24ffe946a5
Issue 413.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1814
diff
changeset
|
102 r.setSeriesShape(idx, new Ellipse2D.Double(- size, |
6c24ffe946a5
Issue 413.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1814
diff
changeset
|
103 - size, |
6c24ffe946a5
Issue 413.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1814
diff
changeset
|
104 2 * size, |
6c24ffe946a5
Issue 413.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1814
diff
changeset
|
105 2 * size)); |
1753
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
106 r.setSeriesShapesVisible(idx, show); |
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
107 r.setDrawOutlines(true); |
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
108 } |
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
109 |
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
110 |
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
111 protected void applyShowLine(XYLineAndShapeRenderer r, int idx) { |
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
112 boolean show = ThemeUtil.parseShowLine(theme); |
741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1741
diff
changeset
|
113 r.setSeriesLinesVisible(idx, show); |
1714
004b1b0838d6
Apply line type to styled themes.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
924
diff
changeset
|
114 } |
924
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
115 } |
f7761914f745
An initial implementation to render chart series based on the XML configuration in themes.xml.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
116 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |