diff flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java @ 1645:4a8251eae217

Bugfix: #68 Set number format of chart plot axes based on the CallMeta instance for each request. flys-artifacts/trunk@2832 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 27 Sep 2011 10:06:19 +0000
parents 0221451a24fe
children 69929c471646
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Tue Sep 27 10:00:29 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Tue Sep 27 10:06:19 2011 +0000
@@ -6,6 +6,8 @@
 
 import java.io.IOException;
 
+import java.text.NumberFormat;
+
 import org.apache.log4j.Logger;
 
 import org.jfree.chart.ChartFactory;
@@ -107,6 +109,7 @@
         addSubtitles(chart);
         adjustPlot(plot);
         adjustAxes(plot);
+        localizeAxes(plot);
 
         removeEmptyRangeAxes(plot);
 
@@ -335,6 +338,62 @@
     }
 
 
+    /**
+     * This method walks over all axes (domain and range) of <i>plot</i> and
+     * calls localizeDomainAxis() for domain axes or localizeRangeAxis() for
+     * range axes.
+     *
+     * @param plot The XYPlot.
+     */
+    private void localizeAxes(XYPlot plot) {
+        for (int i = 0, num = plot.getDomainAxisCount(); i < num; i++) {
+            ValueAxis axis = plot.getDomainAxis(i);
+
+            if (axis != null) {
+                localizeDomainAxis(axis);
+            }
+            else {
+                logger.warn("Domain axis at " + i + " is null.");
+            }
+        }
+
+        for (int i = 0, num = plot.getRangeAxisCount(); i < num; i++) {
+            ValueAxis axis = plot.getRangeAxis(i);
+
+            if (axis != null) {
+                localizeRangeAxis(axis);
+            }
+            else {
+                logger.warn("Range axis at " + i + " is null.");
+            }
+        }
+    }
+
+
+    /**
+     * Overrides the NumberFormat with the NumberFormat for the current locale
+     * that is provided by getLocale().
+     *
+     * @param domainAxis The domain axis that needs localization.
+     */
+    protected void localizeDomainAxis(ValueAxis domainAxis) {
+        NumberFormat nf = NumberFormat.getInstance(getLocale());
+        ((NumberAxis) domainAxis).setNumberFormatOverride(nf);
+    }
+
+
+    /**
+     * Overrides the NumberFormat with the NumberFormat for the current locale
+     * that is provided by getLocale().
+     *
+     * @param domainAxis The domain axis that needs localization.
+     */
+    protected void localizeRangeAxis(ValueAxis rangeAxis) {
+        NumberFormat nf = NumberFormat.getInstance(getLocale());
+        ((NumberAxis) rangeAxis).setNumberFormatOverride(nf);
+    }
+
+
     protected void applyThemes(XYPlot plot) {
         if (first != null) {
             applyThemes(plot, first, 0);

http://dive4elements.wald.intevation.org