[PATCH 2 of 3] issue971: Bring a formatter in (a bad) place
Wald Commits
scm-commit at wald.intevation.org
Thu Sep 19 09:06:41 CEST 2013
# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1379522452 -7200
# Node ID 50b9959330de00b5c2e0b7c51838e7c6a724cfd1
# Parent 1f6c0915a58d08c47362dbed703a5f5c8aec34ef
issue971: Bring a formatter in (a bad) place.
diff -r 1f6c0915a58d -r 50b9959330de artifacts/src/main/java/org/dive4elements/river/exports/ChartExportHelper.java
--- 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()});
+ }
}
}
}
More information about the Dive4elements-commits
mailing list