diff gnv-artifacts/src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java @ 315:63f8b3fb7d9a

Localization of chart axis with locale which fits best to server and browser settings. gnv-artifacts/trunk@373 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 26 Nov 2009 08:47:44 +0000
parents 19fbd03544ea
children 22a6493e8460
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java	Thu Nov 26 08:45:04 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java	Thu Nov 26 08:47:44 2009 +0000
@@ -1,5 +1,7 @@
 package de.intevation.gnv.chart;
 
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.Locale;
@@ -9,6 +11,8 @@
 import org.jfree.chart.ChartTheme;
 import org.jfree.chart.ChartFactory;
 import org.jfree.chart.JFreeChart;
+import org.jfree.chart.axis.Axis;
+import org.jfree.chart.axis.DateAxis;
 import org.jfree.chart.plot.XYPlot;
 import org.jfree.chart.plot.PlotOrientation;
 import org.jfree.data.general.Series;
@@ -26,6 +30,8 @@
 extends      AbstractXYLineChart
 {
 
+    private static final String DATE_FORMAT = "dd-MMM";
+
     private static Logger log = Logger.getLogger(TimeSeriesChart.class);
 
 
@@ -152,6 +158,20 @@
     }
 
 
+    protected void localizeDomainAxis(Axis axis, Locale locale) {
+        if (locale == null)
+            return;
+
+        log.debug(
+            "Set language of axis [" + axis.getLabel() + "] " +
+            "to " + locale.toString()
+        );
+
+        DateFormat format = new SimpleDateFormat(DATE_FORMAT, locale);
+        ((DateAxis) axis).setDateFormatOverride(format);
+    }
+
+
     protected String createSeriesName(
         String breakPoint1,
         String breakPoint2,
@@ -164,4 +184,4 @@
             "m";
     }
 }
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org