Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/StyledXYSeries.java @ 2321:991e4a5df323
Enabled styling in timeseries charts.
flys-artifacts/trunk@4003 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 09 Feb 2012 14:27:47 +0000 |
parents | 41037d51c8b6 |
children | 9d2a06c3a134 |
comparison
equal
deleted
inserted
replaced
2320:bb04f958b7aa | 2321:991e4a5df323 |
---|---|
1 package de.intevation.flys.jfree; | 1 package de.intevation.flys.jfree; |
2 | 2 |
3 import java.awt.BasicStroke; | |
4 import java.awt.Color; | |
5 import java.awt.geom.Ellipse2D; | |
6 | 3 |
7 import org.apache.log4j.Logger; | 4 import org.apache.log4j.Logger; |
8 | 5 |
9 import org.w3c.dom.Document; | 6 import org.w3c.dom.Document; |
10 | 7 |
11 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; | |
12 import org.jfree.data.xy.XYSeries; | 8 import org.jfree.data.xy.XYSeries; |
13 | 9 |
14 import de.intevation.flys.utils.ThemeUtil; | |
15 | 10 |
16 /** | 11 /** |
17 * Dataseries in two dimensions with additional theme-document and further | 12 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
18 * display options. | |
19 * The theme-document will later "style" the graphical representation. | |
20 * The display options can be used to control the z-order and the axis of the | |
21 * dataseries. | |
22 */ | 13 */ |
23 public class StyledXYSeries extends XYSeries { | 14 public class StyledXYSeries extends XYSeries implements StyledSeries { |
24 | |
25 protected Document theme; | |
26 | 15 |
27 private static final Logger logger = Logger.getLogger(StyledXYSeries.class); | 16 private static final Logger logger = Logger.getLogger(StyledXYSeries.class); |
17 | |
18 protected Style style; | |
28 | 19 |
29 | 20 |
30 public StyledXYSeries(String key, Document theme) { | 21 public StyledXYSeries(String key, Document theme) { |
31 this(key, true, theme); | 22 this(key, true, theme); |
32 } | 23 } |
37 * to one extrema which can cause problems in certain | 28 * to one extrema which can cause problems in certain |
38 * algorithms. | 29 * algorithms. |
39 */ | 30 */ |
40 public StyledXYSeries(String key, boolean sorted, Document theme) { | 31 public StyledXYSeries(String key, boolean sorted, Document theme) { |
41 super(key, sorted); | 32 super(key, sorted); |
42 this.theme = theme; | 33 setStyle(new XYStyle(theme)); |
43 } | 34 } |
44 | 35 |
45 | 36 |
46 /** | 37 @Override |
47 * Applies line color, size and type attributes to renderer, also | 38 public void setStyle(Style style) { |
48 * whether to draw lines and/or points. | 39 this.style = style; |
49 */ | |
50 public XYLineAndShapeRenderer applyTheme(XYLineAndShapeRenderer r, int idx){ | |
51 applyLineColor(r, idx); | |
52 applyLineSize(r, idx); | |
53 applyLineType(r, idx); | |
54 applyShowLine(r, idx); | |
55 applyShowPoints(r, idx); | |
56 applyPointSize(r, idx); | |
57 applyShowMinimum(r, idx); | |
58 applyShowMaximum(r, idx); | |
59 | |
60 return r; | |
61 } | 40 } |
62 | 41 |
63 | 42 |
64 /** Set line color to renderer. */ | 43 @Override |
65 protected void applyLineColor(XYLineAndShapeRenderer r, int idx) { | 44 public Style getStyle() { |
66 Color c = ThemeUtil.parseLineColorField(theme); | 45 return style; |
67 r.setSeriesPaint(idx, c); | |
68 } | |
69 | |
70 | |
71 protected void applyLineSize(XYLineAndShapeRenderer r, int idx) { | |
72 int size = ThemeUtil.parseLineWidth(theme); | |
73 r.setSeriesStroke( | |
74 idx, | |
75 new BasicStroke(Integer.valueOf(size))); | |
76 } | |
77 | |
78 | |
79 protected void applyLineType(XYLineAndShapeRenderer r, int idx) { | |
80 int size = ThemeUtil.parseLineWidth(theme); | |
81 float[] dashes = ThemeUtil.parseLineStyle(theme); | |
82 | |
83 // Do not apply the dashed style. | |
84 if (dashes.length <= 1) { | |
85 return; | |
86 } | |
87 | |
88 r.setSeriesStroke( | |
89 idx, | |
90 new BasicStroke(Integer.valueOf(size), | |
91 BasicStroke.CAP_BUTT, | |
92 BasicStroke.JOIN_ROUND, | |
93 1.0f, | |
94 dashes, | |
95 0.0f)); | |
96 } | |
97 | |
98 | |
99 protected void applyPointSize(XYLineAndShapeRenderer r, int idx) { | |
100 int size = ThemeUtil.parsePointWidth(theme); | |
101 int dim = 2 * size; | |
102 | |
103 r.setSeriesShape(idx, new Ellipse2D.Double(-size, -size, dim, dim)); | |
104 } | |
105 | |
106 | |
107 /** | |
108 * Sets form and visibility of points. | |
109 */ | |
110 protected void applyShowPoints(XYLineAndShapeRenderer r, int idx) { | |
111 boolean show = ThemeUtil.parseShowPoints(theme); | |
112 | |
113 r.setSeriesShapesVisible(idx, show); | |
114 r.setDrawOutlines(true); | |
115 } | |
116 | |
117 | |
118 protected void applyShowLine(XYLineAndShapeRenderer r, int idx) { | |
119 boolean show = ThemeUtil.parseShowLine(theme); | |
120 r.setSeriesLinesVisible(idx, show); | |
121 } | |
122 | |
123 | |
124 protected void applyShowMinimum(XYLineAndShapeRenderer r, int idx) { | |
125 if (!(r instanceof EnhancedLineAndShapeRenderer)) { | |
126 return; | |
127 } | |
128 | |
129 boolean visible = ThemeUtil.parseShowMinimum(theme); | |
130 | |
131 EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r; | |
132 er.setIsMinimumShapeVisisble(idx, visible); | |
133 } | |
134 | |
135 | |
136 protected void applyShowMaximum(XYLineAndShapeRenderer r, int idx) { | |
137 if (!(r instanceof EnhancedLineAndShapeRenderer)) { | |
138 return; | |
139 } | |
140 | |
141 boolean visible = ThemeUtil.parseShowMaximum(theme); | |
142 | |
143 EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r; | |
144 er.setIsMaximumShapeVisible(idx, visible); | |
145 } | 46 } |
146 } | 47 } |
147 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 48 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |