diff 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
line wrap: on
line diff
--- 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);
             }

http://dive4elements.wald.intevation.org