Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java @ 3771:04309ca24614
Locales fix
flys-artifacts/trunk@5476 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Sat, 15 Sep 2012 13:42:44 +0000 |
parents | 1d2856de489d |
children | 2d2ca7bf70a7 |
comparison
equal
deleted
inserted
replaced
3770:6a08f4dc790b | 3771:04309ca24614 |
---|---|
1 package de.intevation.flys.exports; | 1 package de.intevation.flys.exports; |
2 | |
3 import java.awt.BasicStroke; | |
4 import java.awt.Color; | |
5 import java.awt.Paint; | |
6 import java.awt.Stroke; | |
7 import java.text.NumberFormat; | |
8 import java.util.List; | |
9 | |
10 import org.apache.log4j.Logger; | |
11 import org.jfree.chart.LegendItemCollection; | |
12 import org.jfree.chart.annotations.XYBoxAnnotation; | |
13 import org.jfree.chart.annotations.XYTextAnnotation; | |
14 import org.jfree.chart.plot.XYPlot; | |
15 import org.jfree.data.xy.XYSeries; | |
16 import org.w3c.dom.Document; | |
2 | 17 |
3 import de.intevation.artifactdatabase.state.ArtifactAndFacet; | 18 import de.intevation.artifactdatabase.state.ArtifactAndFacet; |
4 import de.intevation.artifacts.DataProvider; | 19 import de.intevation.artifacts.DataProvider; |
5 import de.intevation.flys.artifacts.geom.Lines; | 20 import de.intevation.flys.artifacts.geom.Lines; |
6 import de.intevation.flys.artifacts.model.CrossSectionFacet; | 21 import de.intevation.flys.artifacts.model.CrossSectionFacet; |
7 import de.intevation.flys.artifacts.model.FacetTypes; | 22 import de.intevation.flys.artifacts.model.FacetTypes; |
8 import de.intevation.flys.artifacts.model.HYKFactory; | 23 import de.intevation.flys.artifacts.model.HYKFactory; |
24 import de.intevation.flys.artifacts.resources.Resources; | |
9 import de.intevation.flys.jfree.FLYSAnnotation; | 25 import de.intevation.flys.jfree.FLYSAnnotation; |
10 import de.intevation.flys.jfree.StyledXYSeries; | 26 import de.intevation.flys.jfree.StyledXYSeries; |
11 import de.intevation.flys.model.FastCrossSectionLine; | 27 import de.intevation.flys.model.FastCrossSectionLine; |
12 import de.intevation.flys.themes.LineStyle; | 28 import de.intevation.flys.themes.LineStyle; |
13 import de.intevation.flys.themes.TextStyle; | 29 import de.intevation.flys.themes.TextStyle; |
14 import de.intevation.flys.themes.ThemeAccess; | 30 import de.intevation.flys.themes.ThemeAccess; |
15 import de.intevation.flys.utils.Formatter; | 31 import de.intevation.flys.utils.Formatter; |
16 import de.intevation.flys.utils.ThemeUtil; | 32 import de.intevation.flys.utils.ThemeUtil; |
17 | |
18 import java.awt.BasicStroke; | |
19 import java.awt.Color; | |
20 import java.awt.Paint; | |
21 import java.awt.Stroke; | |
22 import java.text.NumberFormat; | |
23 import java.util.List; | |
24 | |
25 import org.apache.log4j.Logger; | |
26 import org.jfree.chart.LegendItemCollection; | |
27 import org.jfree.chart.annotations.XYBoxAnnotation; | |
28 import org.jfree.chart.annotations.XYTextAnnotation; | |
29 import org.jfree.chart.plot.XYPlot; | |
30 import org.jfree.data.xy.XYSeries; | |
31 import org.w3c.dom.Document; | |
32 | 33 |
33 | 34 |
34 /** | 35 /** |
35 * An OutGenerator that generates cross section graphs. | 36 * An OutGenerator that generates cross section graphs. |
36 */ | 37 */ |
38 extends LongitudinalSectionGenerator | 39 extends LongitudinalSectionGenerator |
39 implements FacetTypes | 40 implements FacetTypes |
40 { | 41 { |
41 /** The logger that is used in this generator. */ | 42 /** The logger that is used in this generator. */ |
42 private static Logger logger = | 43 private static Logger logger = |
43 Logger.getLogger(CrossSectionGenerator.class); | 44 Logger.getLogger(CrossSectionGenerator.class); |
44 | 45 |
45 public static final String I18N_CHART_TITLE = | 46 public static final String I18N_CHART_TITLE = |
46 "chart.cross_section.title"; | 47 "chart.cross_section.title"; |
47 | 48 |
48 public static final String I18N_CHART_SUBTITLE = | 49 public static final String I18N_CHART_SUBTITLE = |
49 "chart.cross_section.subtitle"; | 50 "chart.cross_section.subtitle"; |
50 | 51 |
51 public static final String I18N_XAXIS_LABEL = | 52 public static final String I18N_XAXIS_LABEL = |
52 "chart.cross_section.xaxis.label"; | 53 "chart.cross_section.xaxis.label"; |
53 | 54 |
54 public static final String I18N_YAXIS_LABEL = | 55 public static final String I18N_YAXIS_LABEL = |
55 "chart.cross_section.yaxis.label"; | 56 "chart.cross_section.yaxis.label"; |
56 | 57 |
57 public static final String I18N_CHART_TITLE_DEFAULT = "Querprofildiagramm"; | 58 public static final String I18N_CHART_TITLE_DEFAULT = "Querprofildiagramm"; |
58 public static final String I18N_XAXIS_LABEL_DEFAULT = "Abstand [m]"; | 59 public static final String I18N_XAXIS_LABEL_DEFAULT = "Abstand [m]"; |
59 public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]"; | 60 public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]"; |
60 | 61 |
86 * Get localized chart title. | 87 * Get localized chart title. |
87 */ | 88 */ |
88 @Override | 89 @Override |
89 public String getDefaultChartTitle() { | 90 public String getDefaultChartTitle() { |
90 Object[] i18n_msg_args = new Object[] { | 91 Object[] i18n_msg_args = new Object[] { |
91 getRiverName() | 92 getRiverName() |
92 }; | 93 }; |
93 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT, i18n_msg_args); | 94 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT, i18n_msg_args); |
94 } | 95 } |
95 | 96 |
96 | 97 |
108 | 109 |
109 /** Get Charts default subtitle. */ | 110 /** Get Charts default subtitle. */ |
110 @Override | 111 @Override |
111 protected String getDefaultChartSubtitle() { | 112 protected String getDefaultChartSubtitle() { |
112 List<DataProvider> providers = | 113 List<DataProvider> providers = |
113 context.getDataProvider(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA); | 114 context.getDataProvider(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA); |
114 double km = 0d; | 115 double km = 0d; |
115 if (providers.size() > 0) { | 116 if (providers.size() > 0) { |
116 FastCrossSectionLine csl = (FastCrossSectionLine) providers.get(0). | 117 FastCrossSectionLine csl = (FastCrossSectionLine) providers.get(0). |
117 provideData(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA, | 118 provideData(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA, |
118 null, context); | 119 null, context); |
119 km = csl == null ? -1 : csl.getKm(); | 120 km = csl == null ? -1 : csl.getKm(); |
120 } | 121 } |
121 | 122 |
122 Object[] args = new Object[] { | 123 Object[] args = new Object[] { |
123 getRiverName(), | 124 getRiverName(), |
124 km | 125 km |
125 }; | 126 }; |
127 | |
128 logger.debug("Locale: " + Resources.getLocale(context.getMeta())); | |
126 | 129 |
127 return msg(I18N_CHART_SUBTITLE, "", args); | 130 return msg(I18N_CHART_SUBTITLE, "", args); |
128 } | 131 } |
129 | 132 |
130 | 133 |
164 Paint fillPaint = new Color(0, 255,0,60); | 167 Paint fillPaint = new Color(0, 255,0,60); |
165 Paint tranPaint = new Color(0, 0,0, 0); | 168 Paint tranPaint = new Color(0, 0,0, 0); |
166 | 169 |
167 // OPTMIMIZE: Pre-calculate positions | 170 // OPTMIMIZE: Pre-calculate positions |
168 ChartArea area = new ChartArea( | 171 ChartArea area = new ChartArea( |
169 plot.getDomainAxis(0).getRange(), | 172 plot.getDomainAxis(0).getRange(), |
170 plot.getRangeAxis().getRange()); | 173 plot.getRangeAxis().getRange()); |
171 | 174 |
172 for(FLYSAnnotation fa : this.annotations) { | 175 for(FLYSAnnotation fa : this.annotations) { |
173 | 176 |
174 // Access text styling, if any. | 177 // Access text styling, if any. |
175 Document theme = fa.getTheme(); | 178 Document theme = fa.getTheme(); |
201 // For each zone, create a box to fill with color, a box to draw | 204 // For each zone, create a box to fill with color, a box to draw |
202 // the lines and a text to display the type. | 205 // the lines and a text to display the type. |
203 fillPaint = colorForHYKZone(zone.getName()); | 206 fillPaint = colorForHYKZone(zone.getName()); |
204 | 207 |
205 XYBoxAnnotation boxA = new XYBoxAnnotation(zone.getFrom(), area.atGround(), | 208 XYBoxAnnotation boxA = new XYBoxAnnotation(zone.getFrom(), area.atGround(), |
206 zone.getTo(), area.ofGround(0.03f), basicStroke, tranPaint, fillPaint); | 209 zone.getTo(), area.ofGround(0.03f), basicStroke, tranPaint, fillPaint); |
207 XYBoxAnnotation boxB = new XYBoxAnnotation(zone.getFrom(), area.atGround(), | 210 XYBoxAnnotation boxB = new XYBoxAnnotation(zone.getFrom(), area.atGround(), |
208 zone.getTo(), area.atTop(), basicStroke, fillPaint, tranPaint); | 211 zone.getTo(), area.atTop(), basicStroke, fillPaint, tranPaint); |
209 | 212 |
210 XYTextAnnotation tex = new XYTextAnnotation(zone.getName(), | 213 XYTextAnnotation tex = new XYTextAnnotation(zone.getName(), |
211 zone.getFrom() + (zone.getTo() - zone.getFrom()) / 1.0d, | 214 zone.getFrom() + (zone.getTo() - zone.getFrom()) / 1.0d, |
212 area.ofGround(0.015f)); | 215 area.ofGround(0.015f)); |
213 if (textStyle != null) { | 216 if (textStyle != null) { |
214 textStyle.apply(tex); | 217 textStyle.apply(tex); |
215 } | 218 } |
216 | 219 |
217 plot.getRenderer().addAnnotation(boxA, org.jfree.ui.Layer.BACKGROUND); | 220 plot.getRenderer().addAnnotation(boxA, org.jfree.ui.Layer.BACKGROUND); |
236 /** | 239 /** |
237 * Let one facet do its job. | 240 * Let one facet do its job. |
238 */ | 241 */ |
239 @Override | 242 @Override |
240 public void doOut( | 243 public void doOut( |
241 ArtifactAndFacet artifactFacet, | 244 ArtifactAndFacet artifactFacet, |
242 Document attr, | 245 Document attr, |
243 boolean visible | 246 boolean visible |
244 ) { | 247 ) { |
245 String name = artifactFacet.getFacetName(); | 248 String name = artifactFacet.getFacetName(); |
246 | 249 |
247 logger.debug("CrossSectionGenerator.doOut: " + name); | 250 logger.debug("CrossSectionGenerator.doOut: " + name); |
248 | 251 |
249 if (name == null) { | 252 if (name == null) { |
251 return; | 254 return; |
252 } | 255 } |
253 | 256 |
254 if (name.equals(CROSS_SECTION)) { | 257 if (name.equals(CROSS_SECTION)) { |
255 doCrossSectionOut( | 258 doCrossSectionOut( |
256 artifactFacet.getData(context), | 259 artifactFacet.getData(context), |
257 artifactFacet.getFacetDescription(), | 260 artifactFacet.getFacetDescription(), |
258 attr, | 261 attr, |
259 visible); | 262 visible); |
260 } | 263 } |
261 else if (name.equals(CROSS_SECTION_WATER_LINE)) { | 264 else if (name.equals(CROSS_SECTION_WATER_LINE)) { |
262 doCrossSectionWaterLineOut( | 265 doCrossSectionWaterLineOut( |
263 artifactFacet.getData(context), | 266 artifactFacet.getData(context), |
264 artifactFacet.getFacetDescription(), | 267 artifactFacet.getFacetDescription(), |
265 attr, | 268 attr, |
266 visible); | 269 visible); |
267 } | 270 } |
268 else if (FacetTypes.IS.AREA(name)) { | 271 else if (FacetTypes.IS.AREA(name)) { |
269 doArea(artifactFacet.getData(context), | 272 doArea(artifactFacet.getData(context), |
270 artifactFacet, | 273 artifactFacet, |
271 attr, | 274 attr, |
272 visible); | 275 visible); |
273 } | 276 } |
274 else if (name.equals(HYK)) { | 277 else if (name.equals(HYK)) { |
275 doHyk(artifactFacet.getData(context), | 278 doHyk(artifactFacet.getData(context), |
276 artifactFacet.getFacetDescription(), | 279 artifactFacet.getFacetDescription(), |
277 attr, | 280 attr, |
278 visible); | 281 visible); |
279 } | 282 } |
280 else if (FacetTypes.IS.MANUALLINE(name)) { | 283 else if (FacetTypes.IS.MANUALLINE(name)) { |
281 doCrossSectionWaterLineOut( | 284 doCrossSectionWaterLineOut( |
282 artifactFacet.getData(context), | 285 artifactFacet.getData(context), |
283 artifactFacet.getFacetDescription(), | 286 artifactFacet.getFacetDescription(), |
284 attr, | 287 attr, |
285 visible); | 288 visible); |
286 } | 289 } |
287 else if (FacetTypes.IS.MANUALPOINTS(name)) { | 290 else if (FacetTypes.IS.MANUALPOINTS(name)) { |
288 doPoints(artifactFacet.getData(context), | 291 doPoints(artifactFacet.getData(context), |
289 artifactFacet, | 292 artifactFacet, |
290 attr, visible, YAXIS.W.idx); | 293 attr, visible, YAXIS.W.idx); |
291 } | 294 } |
292 else { | 295 else { |
293 logger.warn("CrossSection.doOut: Unknown facet name: " + name); | 296 logger.warn("CrossSection.doOut: Unknown facet name: " + name); |
294 return; | 297 return; |
295 } | 298 } |
309 * | 312 * |
310 * @param seriesName name of the data (line) to display in legend. | 313 * @param seriesName name of the data (line) to display in legend. |
311 * @param theme Theme for the data series. | 314 * @param theme Theme for the data series. |
312 */ | 315 */ |
313 protected void doCrossSectionWaterLineOut( | 316 protected void doCrossSectionWaterLineOut( |
314 Object o, | 317 Object o, |
315 String seriesName, | 318 String seriesName, |
316 Document theme, | 319 Document theme, |
317 boolean visible | 320 boolean visible |
318 ) { | 321 ) { |
319 logger.debug("CrossSectionGenerator.doCrossSectionWaterLineOut"); | 322 logger.debug("CrossSectionGenerator.doCrossSectionWaterLineOut"); |
320 | 323 |
321 Lines.LineData lines = (Lines.LineData) o; | 324 Lines.LineData lines = (Lines.LineData) o; |
322 // DO NOT SORT DATA! This destroys the gaps indicated by NaNs. | 325 // DO NOT SORT DATA! This destroys the gaps indicated by NaNs. |
323 StyledXYSeries series = new StyledXYSeries(seriesName, false, theme); | 326 StyledXYSeries series = new StyledXYSeries(seriesName, false, theme); |
327 } | 330 } |
328 if (ThemeUtil.parseShowWidth(theme)) { | 331 if (ThemeUtil.parseShowWidth(theme)) { |
329 NumberFormat nf = Formatter.getMeterFormat(this.context); | 332 NumberFormat nf = Formatter.getMeterFormat(this.context); |
330 String labelAdd = "b=" + nf.format(lines.width) + "m"; | 333 String labelAdd = "b=" + nf.format(lines.width) + "m"; |
331 if (series.getLabel().length() == 0) { | 334 if (series.getLabel().length() == 0) { |
332 series.setLabel(labelAdd); | 335 series.setLabel(labelAdd); |
333 } | 336 } |
334 else { | 337 else { |
335 series.setLabel(series.getLabel() + ", " + labelAdd); | 338 series.setLabel(series.getLabel() + ", " + labelAdd); |
336 } | 339 } |
337 } | 340 } |
338 if (ThemeUtil.parseShowLevel(theme) && lines.points.length >0 | 341 if (ThemeUtil.parseShowLevel(theme) && lines.points.length >0 |
339 && lines.points[1].length > 0) { | 342 && lines.points[1].length > 0) { |
340 NumberFormat nf = Formatter.getMeterFormat(this.context); | 343 NumberFormat nf = Formatter.getMeterFormat(this.context); |
341 String labelAdd = "W=" + nf.format(lines.points[1][0]) + "NN+m"; | 344 String labelAdd = "W=" + nf.format(lines.points[1][0]) + "NN+m"; |
342 if (series.getLabel().length() == 0) { | 345 if (series.getLabel().length() == 0) { |
343 series.setLabel(labelAdd); | 346 series.setLabel(labelAdd); |
344 } | 347 } |
345 else { | 348 else { |
346 series.setLabel(series.getLabel() + ", " + labelAdd); | 349 series.setLabel(series.getLabel() + ", " + labelAdd); |
347 } | 350 } |
348 } | 351 } |
349 if (ThemeUtil.parseShowMiddleHeight(theme) && lines.width != 0) { | 352 if (ThemeUtil.parseShowMiddleHeight(theme) && lines.width != 0) { |
350 NumberFormat nf = Formatter.getMeterFormat(this.context); | 353 NumberFormat nf = Formatter.getMeterFormat(this.context); |
351 String labelAdd = "T=" + nf.format(lines.area / lines.width) + "m"; | 354 String labelAdd = "T=" + nf.format(lines.area / lines.width) + "m"; |
352 // : " + lines.area + "/" + lines.width); | 355 // : " + lines.area + "/" + lines.width); |
353 if (series.getLabel().length() == 0) { | 356 if (series.getLabel().length() == 0) { |
354 series.setLabel(labelAdd); | 357 series.setLabel(labelAdd); |
355 } | 358 } |
356 else { | 359 else { |
357 series.setLabel(series.getLabel() + ", " + labelAdd); | 360 series.setLabel(series.getLabel() + ", " + labelAdd); |
358 } | 361 } |
359 } | 362 } |
364 } | 367 } |
365 | 368 |
366 | 369 |
367 /** Add HYK-Annotations (colorize and label some areas, draw lines. */ | 370 /** Add HYK-Annotations (colorize and label some areas, draw lines. */ |
368 protected void doHyk( | 371 protected void doHyk( |
369 Object o, | 372 Object o, |
370 String seriesName, | 373 String seriesName, |
371 Document theme, | 374 Document theme, |
372 boolean visible | 375 boolean visible |
373 ) { | 376 ) { |
374 logger.debug("CrossSectionGenerator.doHyk"); | 377 logger.debug("CrossSectionGenerator.doHyk"); |
375 | 378 |
376 List<HYKFactory.Zone> zones = (List<HYKFactory.Zone>) o; | 379 List<HYKFactory.Zone> zones = (List<HYKFactory.Zone>) o; |
377 | 380 |
378 if (zones == null || zones.isEmpty()) { | 381 if (zones == null || zones.isEmpty()) { |
392 * | 395 * |
393 * @param seriesName name of the data (line) to display in legend. | 396 * @param seriesName name of the data (line) to display in legend. |
394 * @param theme Theme for the data series. | 397 * @param theme Theme for the data series. |
395 */ | 398 */ |
396 protected void doCrossSectionOut( | 399 protected void doCrossSectionOut( |
397 Object o, | 400 Object o, |
398 String seriesName, | 401 String seriesName, |
399 Document theme, | 402 Document theme, |
400 boolean visible | 403 boolean visible |
401 ) { | 404 ) { |
402 logger.debug("CrossSectionGenerator.doCrossSectionOut"); | 405 logger.debug("CrossSectionGenerator.doCrossSectionOut"); |
403 | 406 |
404 XYSeries series = new StyledXYSeries(seriesName, theme); | 407 XYSeries series = new StyledXYSeries(seriesName, theme); |
405 | 408 |
406 StyledSeriesBuilder.addPoints(series, (double [][]) o, false); | 409 StyledSeriesBuilder.addPoints(series, (double [][]) o, false); |