Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/jfree/XYStyle.java @ 6905:1b35b2ddfc28
Artifacts: Introduce ThemeDocument & make stuff compileable again. THIS BREAKS THE SYSTEM! TODO: Move ThemeUtils into ThemeDocument.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 22 Aug 2013 23:31:38 +0200 |
parents | af13ceeba52a |
children | 2d690611d110 |
comparison
equal
deleted
inserted
replaced
6904:d710bd3df387 | 6905:1b35b2ddfc28 |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.jfree; | 9 package org.dive4elements.river.jfree; |
10 | 10 |
11 import org.dive4elements.river.utils.ThemeUtil; | 11 import org.dive4elements.river.themes.ThemeDocument; |
12 | 12 |
13 import java.awt.BasicStroke; | 13 import java.awt.BasicStroke; |
14 import java.awt.Color; | 14 import java.awt.Color; |
15 import java.awt.geom.Ellipse2D; | 15 import java.awt.geom.Ellipse2D; |
16 | 16 |
17 import org.apache.log4j.Logger; | 17 import org.apache.log4j.Logger; |
18 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; | 18 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; |
19 import org.w3c.dom.Document; | |
20 | 19 |
21 | 20 |
22 /** | 21 /** |
23 * Utility to apply theme-settings to a renderer. | 22 * Utility to apply theme-settings to a renderer. |
24 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 23 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
25 */ | 24 */ |
26 public class XYStyle implements Style { | 25 public class XYStyle implements Style { |
27 | 26 |
28 private static Logger logger = Logger.getLogger(XYStyle.class); | 27 private static Logger logger = Logger.getLogger(XYStyle.class); |
29 | 28 |
30 protected Document theme; | 29 protected ThemeDocument theme; |
31 | 30 |
32 protected XYLineAndShapeRenderer renderer; | 31 protected XYLineAndShapeRenderer renderer; |
33 | 32 |
34 | 33 |
35 public XYStyle(Document theme) { | 34 public XYStyle(ThemeDocument theme) { |
36 this.theme = theme; | 35 this.theme = theme; |
37 this.renderer = null; | |
38 } | 36 } |
39 | 37 |
40 | 38 |
41 /** | 39 /** |
42 * Applies line color, size and type attributes to renderer, also | 40 * Applies line color, size and type attributes to renderer, also |
74 } | 72 } |
75 | 73 |
76 | 74 |
77 /** Set line color to renderer. */ | 75 /** Set line color to renderer. */ |
78 protected void applyLineColor(XYLineAndShapeRenderer r, int idx) { | 76 protected void applyLineColor(XYLineAndShapeRenderer r, int idx) { |
79 Color c = ThemeUtil.parseLineColorField(theme); | 77 Color c = theme.parseLineColorField(); |
80 if(c != null) { | 78 if(c != null) { |
81 logger.debug("applyLineColor " + c.toString()); | 79 logger.debug("applyLineColor " + c.toString()); |
82 r.setSeriesPaint(idx, c); | 80 r.setSeriesPaint(idx, c); |
83 } | 81 } |
84 else { | 82 else { |
90 /** Tells the renderer whether or not to add a label to a line. */ | 88 /** Tells the renderer whether or not to add a label to a line. */ |
91 protected void applyShowLineLabel(XYLineAndShapeRenderer r, int idx) { | 89 protected void applyShowLineLabel(XYLineAndShapeRenderer r, int idx) { |
92 if (!(r instanceof EnhancedLineAndShapeRenderer)) { | 90 if (!(r instanceof EnhancedLineAndShapeRenderer)) { |
93 return; | 91 return; |
94 } | 92 } |
95 boolean showLabelLine = ThemeUtil.parseShowLineLabel(theme); | 93 boolean showLabelLine = theme.parseShowLineLabel(); |
96 boolean anyLabel = showLabelLine || ThemeUtil.parseShowWidth(theme) || | 94 boolean anyLabel = showLabelLine || theme.parseShowWidth() || |
97 ThemeUtil.parseShowLevel(theme) || | 95 theme.parseShowLevel() || |
98 ThemeUtil.parseShowMiddleHeight(theme); | 96 theme.parseShowMiddleHeight(); |
99 ((EnhancedLineAndShapeRenderer)r).setShowLineLabel(anyLabel, idx); | 97 ((EnhancedLineAndShapeRenderer)r).setShowLineLabel(anyLabel, idx); |
100 } | 98 } |
101 | 99 |
102 | 100 |
103 /** Tells the renderer whether or not to fill the bg of a lines label. */ | 101 /** Tells the renderer whether or not to fill the bg of a lines label. */ |
104 protected void applyShowLineLabelBG(XYLineAndShapeRenderer r, int idx) { | 102 protected void applyShowLineLabelBG(XYLineAndShapeRenderer r, int idx) { |
105 if (!(r instanceof EnhancedLineAndShapeRenderer)) { | 103 if (!(r instanceof EnhancedLineAndShapeRenderer)) { |
106 return; | 104 return; |
107 } | 105 } |
108 boolean showLabelLine = ThemeUtil.parseLabelShowBackground(theme); | 106 boolean showLabelLine = theme.parseLabelShowBackground(); |
109 ((EnhancedLineAndShapeRenderer)r).setShowLineLabelBG(idx, showLabelLine); | 107 ((EnhancedLineAndShapeRenderer)r).setShowLineLabelBG(idx, showLabelLine); |
110 } | 108 } |
111 | 109 |
112 /** Tell the renderer which font (and -size and -style) to use for | 110 /** Tell the renderer which font (and -size and -style) to use for |
113 * linelabels. */ | 111 * linelabels. */ |
114 protected void applyLineLabelFont(XYLineAndShapeRenderer r, int idx) { | 112 protected void applyLineLabelFont(XYLineAndShapeRenderer r, int idx) { |
115 if (!(r instanceof EnhancedLineAndShapeRenderer)) { | 113 if (!(r instanceof EnhancedLineAndShapeRenderer)) { |
116 return; | 114 return; |
117 } | 115 } |
118 ((EnhancedLineAndShapeRenderer)r).setLineLabelFont( | 116 ((EnhancedLineAndShapeRenderer)r).setLineLabelFont( |
119 ThemeUtil.parseTextFont(theme), idx); | 117 theme.parseTextFont(), idx); |
120 } | 118 } |
121 | 119 |
122 /** Tell the renderer which color to use for | 120 /** Tell the renderer which color to use for |
123 * linelabels. */ | 121 * linelabels. */ |
124 protected void applyLineLabelColor(XYLineAndShapeRenderer r, int idx) { | 122 protected void applyLineLabelColor(XYLineAndShapeRenderer r, int idx) { |
125 if (!(r instanceof EnhancedLineAndShapeRenderer)) { | 123 if (!(r instanceof EnhancedLineAndShapeRenderer)) { |
126 return; | 124 return; |
127 } | 125 } |
128 ((EnhancedLineAndShapeRenderer)r).setLineLabelTextColor( | 126 ((EnhancedLineAndShapeRenderer)r).setLineLabelTextColor( |
129 idx, ThemeUtil.parseTextColor(theme)); | 127 idx, theme.parseTextColor()); |
130 } | 128 } |
131 | 129 |
132 /** Tell the renderer which color to use for bg of | 130 /** Tell the renderer which color to use for bg of |
133 * linelabels. */ | 131 * linelabels. */ |
134 protected void applyLineLabelBGColor(XYLineAndShapeRenderer r, int idx) { | 132 protected void applyLineLabelBGColor(XYLineAndShapeRenderer r, int idx) { |
135 if (!(r instanceof EnhancedLineAndShapeRenderer)) { | 133 if (!(r instanceof EnhancedLineAndShapeRenderer)) { |
136 return; | 134 return; |
137 } | 135 } |
138 ((EnhancedLineAndShapeRenderer)r).setLineLabelBGColor(idx, | 136 ((EnhancedLineAndShapeRenderer)r).setLineLabelBGColor(idx, |
139 ThemeUtil.parseTextBackground(theme)); | 137 theme.parseTextBackground()); |
140 } | 138 } |
141 | 139 |
142 /** Set stroke of series. */ | 140 /** Set stroke of series. */ |
143 protected void applyLineSize(XYLineAndShapeRenderer r, int idx) { | 141 protected void applyLineSize(XYLineAndShapeRenderer r, int idx) { |
144 int size = ThemeUtil.parseLineWidth(theme); | 142 int size = theme.parseLineWidth(); |
145 r.setSeriesStroke( | 143 r.setSeriesStroke( |
146 idx, | 144 idx, |
147 new BasicStroke(size)); | 145 new BasicStroke(size)); |
148 } | 146 } |
149 | 147 |
150 | 148 |
151 /** Set stroke strength of series. */ | 149 /** Set stroke strength of series. */ |
152 protected void applyLineType(XYLineAndShapeRenderer r, int idx) { | 150 protected void applyLineType(XYLineAndShapeRenderer r, int idx) { |
153 int size = ThemeUtil.parseLineWidth(theme); | 151 int size = theme.parseLineWidth(); |
154 float[] dashes = ThemeUtil.parseLineStyle(theme); | 152 float[] dashes = theme.parseLineStyle(); |
155 | 153 |
156 // Do not apply the dashed style. | 154 // Do not apply the dashed style. |
157 if (dashes.length <= 1) { | 155 if (dashes.length <= 1) { |
158 return; | 156 return; |
159 } | 157 } |
168 0.0f)); | 166 0.0f)); |
169 } | 167 } |
170 | 168 |
171 | 169 |
172 protected void applyPointSize(XYLineAndShapeRenderer r, int idx) { | 170 protected void applyPointSize(XYLineAndShapeRenderer r, int idx) { |
173 int size = ThemeUtil.parsePointWidth(theme); | 171 int size = theme.parsePointWidth(); |
174 int dim = 2 * size; | 172 int dim = 2 * size; |
175 | 173 |
176 r.setSeriesShape(idx, new Ellipse2D.Double(-size, -size, dim, dim)); | 174 r.setSeriesShape(idx, new Ellipse2D.Double(-size, -size, dim, dim)); |
177 } | 175 } |
178 | 176 |
179 | 177 |
180 protected void applyPointColor(XYLineAndShapeRenderer r, int idx) { | 178 protected void applyPointColor(XYLineAndShapeRenderer r, int idx) { |
181 Color c = ThemeUtil.parsePointColor(theme); | 179 Color c = theme.parsePointColor(); |
182 | 180 |
183 if (c != null) { | 181 if (c != null) { |
184 r.setSeriesFillPaint(idx, c); | 182 r.setSeriesFillPaint(idx, c); |
185 r.setUseFillPaint(true); | 183 r.setUseFillPaint(true); |
186 r.setDrawOutlines(false); | 184 r.setDrawOutlines(false); |
190 | 188 |
191 /** | 189 /** |
192 * Sets form and visibility of points. | 190 * Sets form and visibility of points. |
193 */ | 191 */ |
194 protected void applyShowPoints(XYLineAndShapeRenderer r, int idx) { | 192 protected void applyShowPoints(XYLineAndShapeRenderer r, int idx) { |
195 boolean show = ThemeUtil.parseShowPoints(theme); | 193 boolean show = theme.parseShowPoints(); |
196 | 194 |
197 r.setSeriesShapesVisible(idx, show); | 195 r.setSeriesShapesVisible(idx, show); |
198 r.setDrawOutlines(true); | 196 r.setDrawOutlines(true); |
199 } | 197 } |
200 | 198 |
201 | 199 |
202 protected void applyShowLine(XYLineAndShapeRenderer r, int idx) { | 200 protected void applyShowLine(XYLineAndShapeRenderer r, int idx) { |
203 boolean show = ThemeUtil.parseShowLine(theme); | 201 boolean show = theme.parseShowLine(); |
204 r.setSeriesLinesVisible(idx, show); | 202 r.setSeriesLinesVisible(idx, show); |
205 } | 203 } |
206 | 204 |
207 | 205 |
208 protected void applyShowMinimum(XYLineAndShapeRenderer r, int idx) { | 206 protected void applyShowMinimum(XYLineAndShapeRenderer r, int idx) { |
209 if (!(r instanceof EnhancedLineAndShapeRenderer)) { | 207 if (!(r instanceof EnhancedLineAndShapeRenderer)) { |
210 return; | 208 return; |
211 } | 209 } |
212 | 210 |
213 boolean visible = ThemeUtil.parseShowMinimum(theme); | 211 boolean visible = theme.parseShowMinimum(); |
214 | 212 |
215 EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r; | 213 EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r; |
216 er.setIsMinimumShapeVisisble(idx, visible); | 214 er.setIsMinimumShapeVisisble(idx, visible); |
217 } | 215 } |
218 | 216 |
220 protected void applyShowMaximum(XYLineAndShapeRenderer r, int idx) { | 218 protected void applyShowMaximum(XYLineAndShapeRenderer r, int idx) { |
221 if (!(r instanceof EnhancedLineAndShapeRenderer)) { | 219 if (!(r instanceof EnhancedLineAndShapeRenderer)) { |
222 return; | 220 return; |
223 } | 221 } |
224 | 222 |
225 boolean visible = ThemeUtil.parseShowMaximum(theme); | 223 boolean visible = theme.parseShowMaximum(); |
226 | 224 |
227 EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r; | 225 EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r; |
228 er.setIsMaximumShapeVisible(idx, visible); | 226 er.setIsMaximumShapeVisible(idx, visible); |
229 } | 227 } |
230 | 228 |