changeset 3871:a65eb6d44122

i18n for area label (fix issue487). flys-artifacts/trunk@5504 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 18 Sep 2012 12:03:15 +0000
parents 0c16eace7b6c
children f0e940ebdbc6
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java flys-artifacts/src/main/java/de/intevation/flys/jfree/StableXYDifferenceRenderer.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 7 files changed, 57 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Sep 18 10:18:30 2012 +0000
+++ b/flys-artifacts/ChangeLog	Tue Sep 18 12:03:15 2012 +0000
@@ -1,3 +1,17 @@
+2012-09-18	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	i18n for area label (fix issue487).
+
+	* src/main/java/de/intevation/flys/jfree/StableXYDifferenceRenderer.java,
+	  src/main/java/de/intevation/flys/exports/ChartGenerator.java:
+	  Get internationalized label and numberformat, pass it to renderer,
+	  where its used.
+
+	* src/main/resources/messages.properties,
+	  src/main/resources/messages_de_DE.properties,
+	  src/main/resources/messages_en.properties,
+	  src/main/resources/messages_de.properties: Area label translations.
+
 2012-09-18	Christian Lins	<christian.lins@intevation.de>
 
 	* src/main/java/de/intevation/flys/collections/CollectionDescriptionHelper.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java	Tue Sep 18 10:18:30 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java	Tue Sep 18 12:03:15 2012 +0000
@@ -65,6 +65,9 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
+import de.intevation.flys.utils.Formatter;
+
+import java.text.NumberFormat;
 
 /**
  * The base class for chart creation. It should provide some basic things that
@@ -1669,6 +1672,12 @@
 
         area.applyTheme(dRenderer);
 
+        // i18n
+        dRenderer.setAreaLabelNumberFormat(Formatter.getFormatter(context.getMeta(), 2, 4));
+
+        dRenderer.setAreaLabelTemplate(Resources.getMsg(
+            context.getMeta(), "area.label.template", "Area=%sm2"));
+
         LegendItem legendItem = dRenderer.getLegendItem(idx, 0);
         if (legendItem != null) {
             legendItem.setLabelFont(legendFont);
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/StableXYDifferenceRenderer.java	Tue Sep 18 10:18:30 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/StableXYDifferenceRenderer.java	Tue Sep 18 12:03:15 2012 +0000
@@ -121,8 +121,11 @@
 
 import gnu.trove.TDoubleArrayList;
 
+import de.intevation.flys.artifacts.resources.Resources;
 import de.intevation.flys.artifacts.math.Linear;
 
+import java.text.NumberFormat;
+
 import org.apache.log4j.Logger;
 
 /**
@@ -179,6 +182,12 @@
     /** Font to draw label of calculated area with. */
     protected Font labelFont;
 
+    /** Template to create i18ned label for area. */
+    protected String areaLabelTamplate;
+
+    /** NumberFormat to use for area. */
+    protected NumberFormat areaLabelNumberFormat;
+
     protected int areaCalculationMode;
 
     protected double positiveArea;
@@ -260,6 +269,18 @@
         this.areaCalculationMode = areaCalculationMode;
     }
 
+
+    /** Set template to use to create area label (e.g. 'Area=%dm2'). */
+    public void setAreaLabelTemplate(String areaTemplate) {
+        this.areaLabelTamplate = areaTemplate;
+    }
+
+
+    public void setAreaLabelNumberFormat(NumberFormat nf) {
+        this.areaLabelNumberFormat = nf;
+    }
+
+
     public boolean isLabelArea() {
         return this.labelArea;
     }
@@ -880,8 +901,7 @@
         }
 
         // Find geometric middle, calculate area and paint a string with it here.
-        // TODO also i18n
-        if (pass == 1 && this.labelArea) {
+        if (pass == 1 && this.labelArea && areaLabelNumberFormat != null && areaLabelTamplate != null) {
             double center_x = centroid.getX();
             double center_y = centroid.getY();
             center_x = domainAxis.valueToJava2D(center_x, dataArea,
@@ -904,7 +924,8 @@
                 Color oldColor = g2.getColor();
                 Font oldFont = g2.getFont();
                 g2.setFont(labelFont);
-                String labelText = "Area= " + area + "m2";
+                String labelText = String.format(this.areaLabelTamplate,
+                    areaLabelNumberFormat.format(area));
                 if (labelBGColor != null) {
                     EnhancedLineAndShapeRenderer.drawTextBox(g2, labelText,
                         (float)center_x, (float)center_y, labelBGColor);
--- a/flys-artifacts/src/main/resources/messages.properties	Tue Sep 18 10:18:30 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages.properties	Tue Sep 18 12:03:15 2012 +0000
@@ -462,3 +462,6 @@
 
 load_diameter = Bedload Diameter
 bed_diameter = Bed Diameter
+
+area.label.template = Area = %s m\u00b3
+
--- a/flys-artifacts/src/main/resources/messages_de.properties	Tue Sep 18 10:18:30 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages_de.properties	Tue Sep 18 12:03:15 2012 +0000
@@ -465,3 +465,6 @@
 
 load_diameter = Geschiebedurchmesser
 bed_diameter = Sohldurchmesser
+
+area.label.template = Fl\u00e4che = %s m\u00b3
+
--- a/flys-artifacts/src/main/resources/messages_de_DE.properties	Tue Sep 18 10:18:30 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages_de_DE.properties	Tue Sep 18 12:03:15 2012 +0000
@@ -465,3 +465,5 @@
 load_diameter = Geschiebedurchmesser
 bed_diameter = Sohldurchmesser
 
+area.label.template = Fl\u00e4che = %s m\u00b3
+
--- a/flys-artifacts/src/main/resources/messages_en.properties	Tue Sep 18 10:18:30 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages_en.properties	Tue Sep 18 12:03:15 2012 +0000
@@ -463,3 +463,5 @@
 
 load_diameter = Bedload Diameter
 bed_diameter = Bed Diameter
+
+area.label.template = Area = %s m\u00b3

http://dive4elements.wald.intevation.org