Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java @ 3278:c27c4e06dd87
Re-add HYK rendering code to CrossSectionGenerator
flys-artifacts/trunk@4924 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Wed, 11 Jul 2012 09:24:07 +0000 |
parents | 698d09930329 |
children | 4a70525c5b0d |
comparison
equal
deleted
inserted
replaced
3277:fc0d613e5073 | 3278:c27c4e06dd87 |
---|---|
1 package de.intevation.flys.exports; | 1 package de.intevation.flys.exports; |
2 | |
3 import java.text.NumberFormat; | |
4 import java.util.List; | |
5 | |
6 import org.apache.log4j.Logger; | |
7 import org.jfree.chart.JFreeChart; | |
8 import org.jfree.chart.title.TextTitle; | |
9 import org.jfree.data.xy.XYSeries; | |
10 import org.w3c.dom.Document; | |
11 | 2 |
12 import de.intevation.artifactdatabase.state.ArtifactAndFacet; | 3 import de.intevation.artifactdatabase.state.ArtifactAndFacet; |
13 import de.intevation.artifacts.DataProvider; | 4 import de.intevation.artifacts.DataProvider; |
14 import de.intevation.flys.artifacts.geom.Lines; | 5 import de.intevation.flys.artifacts.geom.Lines; |
15 import de.intevation.flys.artifacts.model.CrossSectionFacet; | 6 import de.intevation.flys.artifacts.model.CrossSectionFacet; |
16 import de.intevation.flys.artifacts.model.FacetTypes; | 7 import de.intevation.flys.artifacts.model.FacetTypes; |
17 import de.intevation.flys.artifacts.model.HYKFactory; | 8 import de.intevation.flys.artifacts.model.HYKFactory; |
18 import de.intevation.flys.jfree.FLYSAnnotation; | 9 import de.intevation.flys.jfree.FLYSAnnotation; |
19 import de.intevation.flys.jfree.StyledXYSeries; | 10 import de.intevation.flys.jfree.StyledXYSeries; |
20 import de.intevation.flys.model.FastCrossSectionLine; | 11 import de.intevation.flys.model.FastCrossSectionLine; |
12 import de.intevation.flys.themes.ThemeAccess; | |
21 import de.intevation.flys.utils.Formatter; | 13 import de.intevation.flys.utils.Formatter; |
22 import de.intevation.flys.utils.ThemeUtil; | 14 import de.intevation.flys.utils.ThemeUtil; |
15 | |
16 import java.awt.BasicStroke; | |
17 import java.awt.Color; | |
18 import java.awt.Paint; | |
19 import java.awt.Stroke; | |
20 import java.text.NumberFormat; | |
21 import java.util.List; | |
22 | |
23 import org.apache.log4j.Logger; | |
24 import org.jfree.chart.JFreeChart; | |
25 import org.jfree.chart.LegendItemCollection; | |
26 import org.jfree.chart.annotations.XYBoxAnnotation; | |
27 import org.jfree.chart.annotations.XYTextAnnotation; | |
28 import org.jfree.chart.plot.XYPlot; | |
29 import org.jfree.chart.title.TextTitle; | |
30 import org.jfree.data.xy.XYSeries; | |
31 import org.w3c.dom.Document; | |
23 | 32 |
24 | 33 |
25 /** | 34 /** |
26 * An OutGenerator that generates cross section graphs. | 35 * An OutGenerator that generates cross section graphs. |
27 */ | 36 */ |
123 protected void addSubtitles(JFreeChart chart) { | 132 protected void addSubtitles(JFreeChart chart) { |
124 String subtitle = getChartSubtitle(); | 133 String subtitle = getChartSubtitle(); |
125 chart.addSubtitle(new TextTitle(subtitle)); | 134 chart.addSubtitle(new TextTitle(subtitle)); |
126 } | 135 } |
127 | 136 |
137 /** Get color for hyk zones by their type (which is the name). */ | |
138 protected Paint colorForHYKZone(String zoneName) { | |
139 if (zoneName.startsWith("R")) { | |
140 // Brownish. | |
141 return new Color(153, 60, 0); | |
142 } | |
143 else if (zoneName.startsWith("V")) { | |
144 // Greenish. | |
145 return new Color(0, 255, 0); | |
146 } | |
147 else if (zoneName.startsWith("B")) { | |
148 // Grayish. | |
149 return new Color(128, 128, 128); | |
150 } | |
151 else if (zoneName.startsWith("H")) { | |
152 // Blueish. | |
153 return new Color(0, 0, 255); | |
154 } | |
155 else { | |
156 // Default. | |
157 logger.debug("Unknown zone type found."); | |
158 return new Color(255, 0, 0); | |
159 } | |
160 } | |
161 | |
162 @Override | |
163 protected void addAnnotationsToRenderer(XYPlot plot) { | |
164 super.addAnnotationsToRenderer(plot); | |
165 | |
166 // Paints for the boxes/lines. | |
167 Stroke basicStroke = new BasicStroke(1.0f); | |
168 | |
169 Paint linePaint = new Color(255, 0,0,60); | |
170 Paint fillPaint = new Color(0, 255,0,60); | |
171 Paint tranPaint = new Color(0, 0,0, 0); | |
172 | |
173 // OPTMIMIZE: Pre-calculate positions | |
174 ChartArea area = new ChartArea( | |
175 plot.getDomainAxis(0).getRange(), | |
176 plot.getRangeAxis().getRange()); | |
177 | |
178 for(FLYSAnnotation fa : this.annotations) { | |
179 | |
180 // Access text styling, if any. | |
181 Document theme = fa.getTheme(); | |
182 ThemeAccess.TextStyle textStyle = null; | |
183 ThemeAccess.LineStyle lineStyle = null; | |
184 | |
185 // Get Themeing information and add legend item. | |
186 if (theme != null) { | |
187 ThemeAccess themeAccess = new ThemeAccess(theme); | |
188 textStyle = themeAccess.parseTextStyle(); | |
189 lineStyle = themeAccess.parseLineStyle(); | |
190 if (fa.getLabel() != null) { | |
191 LegendItemCollection lic = new LegendItemCollection(); | |
192 LegendItemCollection old = plot.getFixedLegendItems(); | |
193 lic.add(createLegendItem(theme, fa.getLabel())); | |
194 // (Re-)Add prior legend entries. | |
195 if (old != null) { | |
196 old.addAll(lic); | |
197 } | |
198 else { | |
199 old = lic; | |
200 } | |
201 plot.setFixedLegendItems(old); | |
202 } | |
203 } | |
204 | |
205 // Hyks. | |
206 for (HYKFactory.Zone zone: fa.getBoxes()) { | |
207 // For each zone, create a box to fill with color, a box to draw | |
208 // the lines and a text to display the type. | |
209 fillPaint = colorForHYKZone(zone.getName()); | |
210 | |
211 XYBoxAnnotation boxA = new XYBoxAnnotation(zone.getFrom(), area.atGround(), | |
212 zone.getTo(), area.ofGround(0.03f), basicStroke, tranPaint, fillPaint); | |
213 XYBoxAnnotation boxB = new XYBoxAnnotation(zone.getFrom(), area.atGround(), | |
214 zone.getTo(), area.atTop(), basicStroke, fillPaint, tranPaint); | |
215 | |
216 XYTextAnnotation tex = new XYTextAnnotation(zone.getName(), | |
217 zone.getFrom() + (zone.getTo() - zone.getFrom()) / 1.0d, | |
218 area.ofGround(0.015f)); | |
219 if (textStyle != null) { | |
220 textStyle.apply(tex); | |
221 } | |
222 | |
223 plot.getRenderer().addAnnotation(boxA, org.jfree.ui.Layer.BACKGROUND); | |
224 plot.getRenderer().addAnnotation(boxB, org.jfree.ui.Layer.BACKGROUND); | |
225 plot.getRenderer().addAnnotation(tex, org.jfree.ui.Layer.BACKGROUND); | |
226 } | |
227 } | |
228 } | |
128 | 229 |
129 @Override | 230 @Override |
130 protected String getDefaultXAxisLabel() { | 231 protected String getDefaultXAxisLabel() { |
131 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); | 232 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); |
132 } | 233 } |
139 | 240 |
140 | 241 |
141 /** | 242 /** |
142 * Let one facet do its job. | 243 * Let one facet do its job. |
143 */ | 244 */ |
245 @Override | |
144 public void doOut( | 246 public void doOut( |
145 ArtifactAndFacet artifactFacet, | 247 ArtifactAndFacet artifactFacet, |
146 Document attr, | 248 Document attr, |
147 boolean visible | 249 boolean visible |
148 ) { | 250 ) { |
199 } | 301 } |
200 } | 302 } |
201 | 303 |
202 | 304 |
203 /** Look up the axis identifier for a given facet type. */ | 305 /** Look up the axis identifier for a given facet type. */ |
306 @Override | |
204 public int axisIdxForFacet(String facetName) { | 307 public int axisIdxForFacet(String facetName) { |
205 // TODO Where to add thid axis too. | 308 // TODO Where to add thid axis too. |
206 return 0; | 309 return 0; |
207 } | 310 } |
208 | 311 |
227 | 330 |
228 if (!ThemeUtil.parseShowLineLabel(theme)) { | 331 if (!ThemeUtil.parseShowLineLabel(theme)) { |
229 series.setLabel(""); | 332 series.setLabel(""); |
230 } | 333 } |
231 if (ThemeUtil.parseShowWidth(theme)) { | 334 if (ThemeUtil.parseShowWidth(theme)) { |
232 NumberFormat nf = nf = Formatter.getMeterFormat(this.context); | 335 NumberFormat nf = Formatter.getMeterFormat(this.context); |
233 String labelAdd = "b=" + nf.format(lines.width) + "m"; | 336 String labelAdd = "b=" + nf.format(lines.width) + "m"; |
234 if (series.getLabel().equals("")) { | 337 if (series.getLabel().equals("")) { |
235 series.setLabel(labelAdd); | 338 series.setLabel(labelAdd); |
236 } | 339 } |
237 else { | 340 else { |
238 series.setLabel(series.getLabel() + ", " + labelAdd); | 341 series.setLabel(series.getLabel() + ", " + labelAdd); |
239 } | 342 } |
240 } | 343 } |
241 if (ThemeUtil.parseShowLevel(theme) && lines.points.length >0 | 344 if (ThemeUtil.parseShowLevel(theme) && lines.points.length >0 |
242 && lines.points[1].length > 0) { | 345 && lines.points[1].length > 0) { |
243 NumberFormat nf = nf = Formatter.getMeterFormat(this.context); | 346 NumberFormat nf = Formatter.getMeterFormat(this.context); |
244 String labelAdd = "W=" + nf.format(lines.points[1][0]) + "NN+m"; | 347 String labelAdd = "W=" + nf.format(lines.points[1][0]) + "NN+m"; |
245 if (series.getLabel().equals("")) { | 348 if (series.getLabel().equals("")) { |
246 series.setLabel(labelAdd); | 349 series.setLabel(labelAdd); |
247 } | 350 } |
248 else { | 351 else { |
249 series.setLabel(series.getLabel() + ", " + labelAdd); | 352 series.setLabel(series.getLabel() + ", " + labelAdd); |
250 } | 353 } |
251 } | 354 } |
252 if (ThemeUtil.parseShowMiddleHeight(theme) && lines.width != 0) { | 355 if (ThemeUtil.parseShowMiddleHeight(theme) && lines.width != 0) { |
253 NumberFormat nf = nf = Formatter.getMeterFormat(this.context); | 356 NumberFormat nf = Formatter.getMeterFormat(this.context); |
254 String labelAdd = "H=" + nf.format(lines.area / lines.width) + "m"; | 357 String labelAdd = "H=" + nf.format(lines.area / lines.width) + "m"; |
255 // : " + lines.area + "/" + lines.width); | 358 // : " + lines.area + "/" + lines.width); |
256 if (series.getLabel().equals("")) { | 359 if (series.getLabel().equals("")) { |
257 series.setLabel(labelAdd); | 360 series.setLabel(labelAdd); |
258 } | 361 } |