Mercurial > dive4elements > river
changeset 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 | b6da650b0718 |
children | 70966b52c073 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/resources/Resources.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/FixingsKMChartService.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/QWSeriesCollection.java flys-artifacts/src/main/resources/messages.properties flys-artifacts/src/main/resources/messages_de.properties flys-artifacts/src/main/resources/messages_de_DE.properties flys-artifacts/src/main/resources/messages_en.properties |
diffstat | 8 files changed, 133 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Mon Jun 25 15:53:34 2012 +0000 +++ b/flys-artifacts/ChangeLog Mon Jun 25 15:59:47 2012 +0000 @@ -1,3 +1,20 @@ +2012-06-25 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/services/FixingsKMChartService.java: + Uses I18N now. + + * src/main/java/de/intevation/flys/artifacts/services/QWSeriesCollection.java: + Added convenience constructor for creating date formatters with strings. + + * src/main/java/de/intevation/flys/artifacts/resources/Resources.java: + Added variadic method format(). + + * src/main/resources/messages.properties, + src/main/resources/messages_de_DE.properties, + src/main/resources/messages_en.properties, + src/main/resources/messages_de.properties: + Added strings. + 2012-06-25 Raimund Renkert <raimund.renkert@intevation.de> * src/main/java/de/intevation/flys/exports/fixings/FixLongitudinalSectionGenerator.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/resources/Resources.java Mon Jun 25 15:53:34 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/resources/Resources.java Mon Jun 25 15:59:47 2012 +0000 @@ -128,6 +128,20 @@ return MessageFormat.format(template, args); } + public static String format( + CallMeta meta, + String key, + String def, + Object ... args + ) { + String template = getMsg(meta, key, (String)null); + + if (template == null) { + return template = def; + } + + return MessageFormat.format(template, args); + } /** * This method returns the translated value for <i>key</i> or <i>def</i> if
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/FixingsKMChartService.java Mon Jun 25 15:53:34 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/FixingsKMChartService.java Mon Jun 25 15:59:47 2012 +0000 @@ -20,6 +20,8 @@ import de.intevation.flys.artifacts.model.fixings.QW; +import de.intevation.flys.artifacts.resources.Resources; + import de.intevation.flys.backend.SessionHolder; import de.intevation.flys.utils.Formatter; @@ -45,7 +47,6 @@ import org.apache.log4j.Logger; import org.jfree.chart.ChartFactory; -import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; import org.jfree.chart.LegendItemCollection; @@ -74,13 +75,43 @@ public static final int DEFAULT_WIDTH = 240; public static final int DEFAULT_HEIGHT = 180; - // TODO: i18n - public static final String [] Q_SECTOR_LABELS = { + public static final String [] I18N_Q_SECTOR_BOARDERS = { + "fix.km.chart.q.sector.border0", + "fix.km.chart.q.sector.border1", + "fix.km.chart.q.sector.border2" + }; + + public static final String [] DEFAULT_Q_SECTOR_BORDERS = { "(MNQ + MQ)/2", "(MQ + MHQ)/2", "HQ5" }; + public static final String I18N_CHART_LABEL_DATE = + "fix.km.chart.label.date"; + + public static final String DEFAULT_CHART_LABEL_DATE = + "yyyy/MM/dd"; + + public static final String I18N_CHART_TITLE = + "fix.km.chart.title"; + + public static final String DEFAULT_CHART_TITLE = + "Fixings {0} km {1,number,#.###}"; + + public static final String I18N_Q_AXIS = + "fix.km.chart.q.axis"; + + public static final String DEFAULT_Q_AXIS = + "Q [m\u00b3/s]"; + + public static final String I18N_W_AXIS = + "fix.km.chart.w.axis"; + + public static final String DEFAULT_W_AXIS = + "W [NN + m]"; + + public static final String DEFAULT_FORMAT = "png"; // TODO: Load fancy image from resources. @@ -217,8 +248,13 @@ double km, CallMeta callMeta ) { - // TODO: I18N - QWSeriesCollection dataset = new QWSeriesCollection(); + String labelFormat = Resources.getMsg( + callMeta, I18N_CHART_LABEL_DATE, DEFAULT_CHART_LABEL_DATE); + + QWSeriesCollection.LabelGenerator lg = + new QWSeriesCollection.DateFormatLabelGenerator(labelFormat); + + QWSeriesCollection dataset = new QWSeriesCollection(lg); double [] w = new double[1]; for (Pair<Fixing.Column, FixingsColumn> col: cols) { @@ -234,10 +270,19 @@ } } + String title = Resources.format( + callMeta, I18N_CHART_TITLE, DEFAULT_CHART_TITLE, river, km); + + String qAxis = Resources.getMsg( + callMeta, I18N_Q_AXIS, DEFAULT_Q_AXIS); + + String wAxis = Resources.getMsg( + callMeta, I18N_W_AXIS, DEFAULT_W_AXIS); + JFreeChart chart = ChartFactory.createXYLineChart( - "Fixierungen " + river + ": km " + km, // TODO: i18n - "Q [m\u00b3/s]", - "W [NN + m]", + title, + qAxis, + wAxis, null, PlotOrientation.VERTICAL, true, @@ -271,7 +316,7 @@ dataset.addLegendItems(lic); plot.setFixedLegendItems(lic); - applyQSectorMarkers(plot, river, km); + applyQSectorMarkers(plot, river, km, callMeta); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.white); @@ -284,9 +329,10 @@ } protected static void applyQSectorMarkers( - XYPlot plot, - String river, - double km + XYPlot plot, + String river, + double km, + CallMeta meta ) { GaugeFinderFactory ggf = GaugeFinderFactory.getInstance(); GaugeFinder gf = ggf.getGaugeFinder(river); @@ -307,10 +353,15 @@ log.debug(gr); } - for (int i = 0; i < Q_SECTOR_LABELS.length; ++i) { + for (int i = 0; i < I18N_Q_SECTOR_BOARDERS.length; ++i) { + String key = I18N_Q_SECTOR_BOARDERS[i]; + String def = DEFAULT_Q_SECTOR_BORDERS[i]; + String label = Resources.getMsg(meta, key, def); + Marker m = createQSectorMarker( gr.getSectorBorder(i), - Q_SECTOR_LABELS[i]); + label); + if (m != null) { plot.addDomainMarker(m); }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/QWSeriesCollection.java Mon Jun 25 15:53:34 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/QWSeriesCollection.java Mon Jun 25 15:59:47 2012 +0000 @@ -47,7 +47,11 @@ protected DateFormat format; public DateFormatLabelGenerator() { - this(new SimpleDateFormat("dd.MM.yyyy")); + this("dd.MM.yyyy"); + } + + public DateFormatLabelGenerator(String format) { + this(new SimpleDateFormat(format)); } public DateFormatLabelGenerator(DateFormat format) {
--- a/flys-artifacts/src/main/resources/messages.properties Mon Jun 25 15:53:34 2012 +0000 +++ b/flys-artifacts/src/main/resources/messages.properties Mon Jun 25 15:59:47 2012 +0000 @@ -359,3 +359,11 @@ fix.fitting.failed=Fitting failed fix.invalid.values=Invalid values fix.cannot.load.data=Cannot fetch data from database + +fix.km.chart.q.sector.border0=(MNQ + MQ)/2 +fix.km.chart.q.sector.border1=(MQ + MHQ)/2 +fix.km.chart.q.sector.border2=HQ5 +fix.km.chart.label.date=yyyy/MM/dd +fix.km.chart.title=Fixings {0} km {1,number,#.###} +fix.km.chart.q.axis=Q [m\u00b3/s] +fix.km.chart.w.axis=W [NN + m]
--- a/flys-artifacts/src/main/resources/messages_de.properties Mon Jun 25 15:53:34 2012 +0000 +++ b/flys-artifacts/src/main/resources/messages_de.properties Mon Jun 25 15:59:47 2012 +0000 @@ -360,3 +360,11 @@ fix.fitting.failed=Kurvenanpassung fehlgeschlagen fix.invalid.values=Ung\u00fcltige Werte fix.cannot.load.data=Daten konnten nicht aus der Datenbank geladen werden + +fix.km.chart.q.sector.border0=(MNQ + MQ)/2 +fix.km.chart.q.sector.border1=(MQ + MHQ)/2 +fix.km.chart.q.sector.border2=HQ5 +fix.km.chart.label.date=dd.MM.yyyy +fix.km.chart.title=Fixierungen {0} km {1,number,#.###} +fix.km.chart.q.axis=Q [m\u00b3/s] +fix.km.chart.w.axis=W [NN + m]
--- a/flys-artifacts/src/main/resources/messages_de_DE.properties Mon Jun 25 15:53:34 2012 +0000 +++ b/flys-artifacts/src/main/resources/messages_de_DE.properties Mon Jun 25 15:59:47 2012 +0000 @@ -359,3 +359,11 @@ fix.fitting.failed=Kurvenanpassung fehlgeschlagen fix.invalid.values=Ung\u00fcltige Werte fix.cannot.load.data=Daten konnten nicht aus der Datenbank geladen werden + +fix.km.chart.q.sector.border0=(MNQ + MQ)/2 +fix.km.chart.q.sector.border1=(MQ + MHQ)/2 +fix.km.chart.q.sector.border2=HQ5 +fix.km.chart.label.date=dd.MM.yyyy +fix.km.chart.title=Fixierungen {0} km {1,number,#.###} +fix.km.chart.q.axis=Q [m\u00b3/s] +fix.km.chart.w.axis=W [NN + m]
--- a/flys-artifacts/src/main/resources/messages_en.properties Mon Jun 25 15:53:34 2012 +0000 +++ b/flys-artifacts/src/main/resources/messages_en.properties Mon Jun 25 15:59:47 2012 +0000 @@ -359,3 +359,11 @@ fix.fitting.failed=Fitting failed fix.invalid.values=Invalid values fix.cannot.load.data=Cannot fetch data from database + +fix.km.chart.q.sector.border0=(MNQ + MQ)/2 +fix.km.chart.q.sector.border1=(MQ + MHQ)/2 +fix.km.chart.q.sector.border2=HQ5 +fix.km.chart.label.date=yyyy/MM/dd +fix.km.chart.title=Fixings {0} km {1,number,#.###} +fix.km.chart.q.axis=Q [m\u00b3/s] +fix.km.chart.w.axis=W [NN + m]