Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/FixingsKMChartService.java @ 3170:79e7bba0f593
FixA: I18N for chart km service.
flys-artifacts/trunk@4783 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 25 Jun 2012 15:59:47 +0000 |
parents | 591be3486087 |
children | 0cf647fe2a96 |
comparison
equal
deleted
inserted
replaced
3169:b6da650b0718 | 3170:79e7bba0f593 |
---|---|
18 import de.intevation.flys.artifacts.model.GaugeFinderFactory; | 18 import de.intevation.flys.artifacts.model.GaugeFinderFactory; |
19 import de.intevation.flys.artifacts.model.GaugeRange; | 19 import de.intevation.flys.artifacts.model.GaugeRange; |
20 | 20 |
21 import de.intevation.flys.artifacts.model.fixings.QW; | 21 import de.intevation.flys.artifacts.model.fixings.QW; |
22 | 22 |
23 import de.intevation.flys.artifacts.resources.Resources; | |
24 | |
23 import de.intevation.flys.backend.SessionHolder; | 25 import de.intevation.flys.backend.SessionHolder; |
24 | 26 |
25 import de.intevation.flys.utils.Formatter; | 27 import de.intevation.flys.utils.Formatter; |
26 import de.intevation.flys.utils.Pair; | 28 import de.intevation.flys.utils.Pair; |
27 | 29 |
43 import javax.imageio.ImageIO; | 45 import javax.imageio.ImageIO; |
44 | 46 |
45 import org.apache.log4j.Logger; | 47 import org.apache.log4j.Logger; |
46 | 48 |
47 import org.jfree.chart.ChartFactory; | 49 import org.jfree.chart.ChartFactory; |
48 import org.jfree.chart.ChartUtilities; | |
49 import org.jfree.chart.JFreeChart; | 50 import org.jfree.chart.JFreeChart; |
50 import org.jfree.chart.LegendItemCollection; | 51 import org.jfree.chart.LegendItemCollection; |
51 | 52 |
52 import org.jfree.chart.axis.NumberAxis; | 53 import org.jfree.chart.axis.NumberAxis; |
53 | 54 |
72 Logger.getLogger(FixingsKMChartService.class); | 73 Logger.getLogger(FixingsKMChartService.class); |
73 | 74 |
74 public static final int DEFAULT_WIDTH = 240; | 75 public static final int DEFAULT_WIDTH = 240; |
75 public static final int DEFAULT_HEIGHT = 180; | 76 public static final int DEFAULT_HEIGHT = 180; |
76 | 77 |
77 // TODO: i18n | 78 public static final String [] I18N_Q_SECTOR_BOARDERS = { |
78 public static final String [] Q_SECTOR_LABELS = { | 79 "fix.km.chart.q.sector.border0", |
80 "fix.km.chart.q.sector.border1", | |
81 "fix.km.chart.q.sector.border2" | |
82 }; | |
83 | |
84 public static final String [] DEFAULT_Q_SECTOR_BORDERS = { | |
79 "(MNQ + MQ)/2", | 85 "(MNQ + MQ)/2", |
80 "(MQ + MHQ)/2", | 86 "(MQ + MHQ)/2", |
81 "HQ5" | 87 "HQ5" |
82 }; | 88 }; |
89 | |
90 public static final String I18N_CHART_LABEL_DATE = | |
91 "fix.km.chart.label.date"; | |
92 | |
93 public static final String DEFAULT_CHART_LABEL_DATE = | |
94 "yyyy/MM/dd"; | |
95 | |
96 public static final String I18N_CHART_TITLE = | |
97 "fix.km.chart.title"; | |
98 | |
99 public static final String DEFAULT_CHART_TITLE = | |
100 "Fixings {0} km {1,number,#.###}"; | |
101 | |
102 public static final String I18N_Q_AXIS = | |
103 "fix.km.chart.q.axis"; | |
104 | |
105 public static final String DEFAULT_Q_AXIS = | |
106 "Q [m\u00b3/s]"; | |
107 | |
108 public static final String I18N_W_AXIS = | |
109 "fix.km.chart.w.axis"; | |
110 | |
111 public static final String DEFAULT_W_AXIS = | |
112 "W [NN + m]"; | |
113 | |
83 | 114 |
84 public static final String DEFAULT_FORMAT = "png"; | 115 public static final String DEFAULT_FORMAT = "png"; |
85 | 116 |
86 // TODO: Load fancy image from resources. | 117 // TODO: Load fancy image from resources. |
87 public static final byte [] EMPTY = { | 118 public static final byte [] EMPTY = { |
215 List<Pair<Fixing.Column, FixingsColumn>> cols, | 246 List<Pair<Fixing.Column, FixingsColumn>> cols, |
216 String river, | 247 String river, |
217 double km, | 248 double km, |
218 CallMeta callMeta | 249 CallMeta callMeta |
219 ) { | 250 ) { |
220 // TODO: I18N | 251 String labelFormat = Resources.getMsg( |
221 QWSeriesCollection dataset = new QWSeriesCollection(); | 252 callMeta, I18N_CHART_LABEL_DATE, DEFAULT_CHART_LABEL_DATE); |
253 | |
254 QWSeriesCollection.LabelGenerator lg = | |
255 new QWSeriesCollection.DateFormatLabelGenerator(labelFormat); | |
256 | |
257 QWSeriesCollection dataset = new QWSeriesCollection(lg); | |
222 | 258 |
223 double [] w = new double[1]; | 259 double [] w = new double[1]; |
224 for (Pair<Fixing.Column, FixingsColumn> col: cols) { | 260 for (Pair<Fixing.Column, FixingsColumn> col: cols) { |
225 boolean interpolated = !col.getB().getW(km, w); | 261 boolean interpolated = !col.getB().getW(km, w); |
226 double q = col.getB().getQ(km); | 262 double q = col.getB().getQ(km); |
232 interpolated); | 268 interpolated); |
233 dataset.add(qw); | 269 dataset.add(qw); |
234 } | 270 } |
235 } | 271 } |
236 | 272 |
273 String title = Resources.format( | |
274 callMeta, I18N_CHART_TITLE, DEFAULT_CHART_TITLE, river, km); | |
275 | |
276 String qAxis = Resources.getMsg( | |
277 callMeta, I18N_Q_AXIS, DEFAULT_Q_AXIS); | |
278 | |
279 String wAxis = Resources.getMsg( | |
280 callMeta, I18N_W_AXIS, DEFAULT_W_AXIS); | |
281 | |
237 JFreeChart chart = ChartFactory.createXYLineChart( | 282 JFreeChart chart = ChartFactory.createXYLineChart( |
238 "Fixierungen " + river + ": km " + km, // TODO: i18n | 283 title, |
239 "Q [m\u00b3/s]", | 284 qAxis, |
240 "W [NN + m]", | 285 wAxis, |
241 null, | 286 null, |
242 PlotOrientation.VERTICAL, | 287 PlotOrientation.VERTICAL, |
243 true, | 288 true, |
244 true, | 289 true, |
245 false); | 290 false); |
269 | 314 |
270 LegendItemCollection lic = plot.getLegendItems(); | 315 LegendItemCollection lic = plot.getLegendItems(); |
271 dataset.addLegendItems(lic); | 316 dataset.addLegendItems(lic); |
272 plot.setFixedLegendItems(lic); | 317 plot.setFixedLegendItems(lic); |
273 | 318 |
274 applyQSectorMarkers(plot, river, km); | 319 applyQSectorMarkers(plot, river, km, callMeta); |
275 | 320 |
276 chart.setBackgroundPaint(Color.white); | 321 chart.setBackgroundPaint(Color.white); |
277 plot.setBackgroundPaint(Color.white); | 322 plot.setBackgroundPaint(Color.white); |
278 plot.setDomainGridlinePaint(Color.gray); | 323 plot.setDomainGridlinePaint(Color.gray); |
279 plot.setRangeGridlinePaint(Color.gray); | 324 plot.setRangeGridlinePaint(Color.gray); |
282 | 327 |
283 return chart; | 328 return chart; |
284 } | 329 } |
285 | 330 |
286 protected static void applyQSectorMarkers( | 331 protected static void applyQSectorMarkers( |
287 XYPlot plot, | 332 XYPlot plot, |
288 String river, | 333 String river, |
289 double km | 334 double km, |
335 CallMeta meta | |
290 ) { | 336 ) { |
291 GaugeFinderFactory ggf = GaugeFinderFactory.getInstance(); | 337 GaugeFinderFactory ggf = GaugeFinderFactory.getInstance(); |
292 GaugeFinder gf = ggf.getGaugeFinder(river); | 338 GaugeFinder gf = ggf.getGaugeFinder(river); |
293 | 339 |
294 if (gf == null) { | 340 if (gf == null) { |
305 | 351 |
306 if (log.isDebugEnabled()) { | 352 if (log.isDebugEnabled()) { |
307 log.debug(gr); | 353 log.debug(gr); |
308 } | 354 } |
309 | 355 |
310 for (int i = 0; i < Q_SECTOR_LABELS.length; ++i) { | 356 for (int i = 0; i < I18N_Q_SECTOR_BOARDERS.length; ++i) { |
357 String key = I18N_Q_SECTOR_BOARDERS[i]; | |
358 String def = DEFAULT_Q_SECTOR_BORDERS[i]; | |
359 String label = Resources.getMsg(meta, key, def); | |
360 | |
311 Marker m = createQSectorMarker( | 361 Marker m = createQSectorMarker( |
312 gr.getSectorBorder(i), | 362 gr.getSectorBorder(i), |
313 Q_SECTOR_LABELS[i]); | 363 label); |
364 | |
314 if (m != null) { | 365 if (m != null) { |
315 plot.addDomainMarker(m); | 366 plot.addDomainMarker(m); |
316 } | 367 } |
317 } | 368 } |
318 } | 369 } |