changeset 3017:296b067e17e6

i18n and format for line labels. flys-artifacts/trunk@4582 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 05 Jun 2012 12:35:49 +0000
parents 75e83b02bb9d
children fb07f936b5ad
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java flys-artifacts/src/main/java/de/intevation/flys/utils/Formatter.java
diffstat 3 files changed, 37 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Jun 05 12:08:47 2012 +0000
+++ b/flys-artifacts/ChangeLog	Tue Jun 05 12:35:49 2012 +0000
@@ -1,3 +1,12 @@
+2012-06-05	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/utils/Formatter.java:
+          (getMeterFormat): New.
+	  Doc.
+
+	* src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java:
+	  i18n and formatting for line labels.
+
 2012-06-05	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java	Tue Jun 05 12:08:47 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java	Tue Jun 05 12:35:49 2012 +0000
@@ -1,6 +1,7 @@
 package de.intevation.flys.exports;
 
 import java.util.List;
+import java.text.NumberFormat;
 
 import org.apache.log4j.Logger;
 
@@ -26,6 +27,7 @@
 import de.intevation.flys.geom.Lines;
 
 import de.intevation.flys.utils.ThemeUtil;
+import de.intevation.flys.utils.Formatter;
 
 
 /**
@@ -224,16 +226,22 @@
         // DO NOT SORT DATA! This destroys the gaps indicated by NaNs.
         StyledXYSeries series = new StyledXYSeries(seriesName, false, theme);
 
-        // TODO i18n for all the label text and number format.
         if (ThemeUtil.parseShowWidth(theme)) {
-            series.setLabel(series.getLabel() + ", b=" + lines.width + "m");
+            NumberFormat nf = nf = Formatter.getMeterFormat(this.context);
+            series.setLabel(series.getLabel() + ", b=" +
+                nf.format(lines.width) + "m");
         }
         if (ThemeUtil.parseShowLevel(theme) && lines.points.length >0
             && lines.points[1].length > 0) {
-            series.setLabel(series.getLabel() + ", W=" + lines.points[1][0] + "NN+m");
+            NumberFormat nf = nf = Formatter.getMeterFormat(this.context);
+            series.setLabel(series.getLabel() + ", W=" +
+                nf.format(lines.points[1][0]) + "NN+m");
         }
         if (ThemeUtil.parseShowMiddleHeight(theme) && lines.width != 0) {
-            series.setLabel(series.getLabel() + ",H=" + lines.area / lines.width + "m : " + lines.area + "/" + lines.width);    
+            NumberFormat nf = nf = Formatter.getMeterFormat(this.context);
+            series.setLabel(series.getLabel() + ",H=" +
+                nf.format(lines.area / lines.width) + "m");
+                // : " + lines.area + "/" + lines.width);    
         }
 
         StyledSeriesBuilder.addPoints(series, lines.points, false);
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/Formatter.java	Tue Jun 05 12:08:47 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/Formatter.java	Tue Jun 05 12:35:49 2012 +0000
@@ -76,6 +76,14 @@
     public static final int FIX_DELTA_W_DELTA_W_MIN_DIGITS = 3;
     public static final int FIX_DELTA_W_DELTA_W_MAX_DIGITS = 3;
 
+    /**
+     * Creates a localised NumberFormatter with given range of decimal digits.
+     * @param m CallMeta to find the locale.
+     * @param min minimum number of decimal ("fraction") digits.
+     * @param max maximum number of decimal ("fraction") digits.
+     * @return A NumberFormat. Use #format(NUMBER) to get String representation
+     *         of NUMBER.
+     */
     public static NumberFormat getFormatter(CallMeta m, int min, int max){
         Locale       locale = Resources.getLocale(m);
         NumberFormat nf     = NumberFormat.getInstance(locale);
@@ -347,5 +355,13 @@
             FIX_DELTA_W_DELTA_W_MIN_DIGITS,
             FIX_DELTA_W_DELTA_W_MAX_DIGITS);
     }
+
+    public static NumberFormat getMeterFormat(CallContext context) {
+        return getFormatter(
+            context,
+            0,
+            2);
+    
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org