changeset 7046:50b9959330de

issue971: Bring a formatter in (a bad) place.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 18 Sep 2013 18:40:52 +0200
parents 1f6c0915a58d
children b5e9b8b5c8d6
files artifacts/src/main/java/org/dive4elements/river/exports/ChartExportHelper.java
diffstat 1 files changed, 20 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ChartExportHelper.java	Wed Sep 18 14:15:14 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/ChartExportHelper.java	Wed Sep 18 18:40:52 2013 +0200
@@ -28,6 +28,9 @@
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.UnsupportedEncodingException;
+
+import java.text.NumberFormat;
+
 import org.jfree.chart.ChartRenderingInfo;
 
 import javax.imageio.ImageIO;
@@ -47,6 +50,8 @@
 
 import org.dive4elements.artifacts.common.utils.XMLUtils;
 
+import org.dive4elements.river.utils.Formatter;
+
 
 /**
  * This class is a helper class which supports some methods to export charts
@@ -309,7 +314,7 @@
                 Comparable seriesKey = data.getSeriesKey(j);
                 log.debug("series key: " + seriesKey.toString());
                 writeCSVHeader(writer, seriesKey.toString());
-                writeCSVData(writer, data);
+                writeCSVData(writer, data, context);
             }
         }
         try {
@@ -329,15 +334,25 @@
     }
 
 
-    protected static void writeCSVData(CSVWriter writer, XYDataset data) {
+    protected static void writeCSVData(CSVWriter writer, XYDataset data, CallContext context) {
         int series = data.getSeriesCount();
+        // TODO: Instantiate at other place, use
+        // better formatter.
+        NumberFormat numberFormat = Formatter.getWaterlevelW(context);
         for (int i = 0; i < series; i++) {
             int items = data.getItemCount(i);
             for (int j = 0; j < items; j++) {
                 log.debug("write data: " + data.getX(i, j) + ", " + data.getY(i, j));
-                writer.writeNext(new String[] {
-                    data.getX(i, j).toString(),
-                    data.getY(i, j).toString()});
+                try {
+                    writer.writeNext(new String[] {
+                        numberFormat.format(data.getX(i, j)),
+                        numberFormat.format(data.getY(i, j))});
+                }
+                catch (NumberFormatException nfe) {
+                    writer.writeNext(new String[] {
+                        data.getX(i, j).toString(),
+                        data.getY(i, j).toString()});
+                }
             }
         }
     }

http://dive4elements.wald.intevation.org