diff gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java @ 839:ac5988f27714

Added the time interval into the subtitle of timeseries charts (issue152). gnv-artifacts/trunk@948 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 19 Apr 2010 14:19:19 +0000
parents e91ebe3696ec
children 47280aff0eb7
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java	Mon Apr 19 12:31:02 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java	Mon Apr 19 14:19:19 2010 +0000
@@ -3,8 +3,13 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -198,6 +203,7 @@
             "ODV",
             "ISO-8859-1");
 
+
     /**
      * Constructor
      */
@@ -1050,14 +1056,49 @@
 
 
     /**
-     * Creates and returns the subtitle of a chart.
+     * Creates and returns the subtitle of a chart. The subtitle in this class
+     * contains the station and the time interval.
      *
      * @param locale The Locale used to adjust the language of the subtitle.
      * @param uuid The UUID of the current artifact.
      * @return the selected feature.
      */
     protected String createChartSubtitle(Locale locale, String uuid) {
-        return getSelectedFeatureName(uuid);
+        String subtitle = "";
+        subtitle       += getSelectedFeatureName(uuid);
+
+        InputData data = inputData.get(timeIntervalValueName);
+        if (data != null){
+            Object describeData = data.getObject();
+            if (describeData instanceof MinMaxDescribeData) {
+                MinMaxDescribeData tmp = (MinMaxDescribeData) describeData;
+
+                DateFormat format = DateFormat.getDateTimeInstance(
+                    DateFormat.MEDIUM, DateFormat.SHORT, locale);
+
+                String lDateStr = (String) tmp.getMinValue();
+                String rDateStr = (String) tmp.getMaxValue();
+
+                try {
+                    Date lDate = srcFormat.parse(lDateStr);
+                    Date rDate = srcFormat.parse(rDateStr);
+
+                    String interval = format.format(lDate);
+                    interval       += " - ";
+                    interval       += format.format(rDate);
+
+                    if (subtitle != null && subtitle.length() > 0)
+                        subtitle += ", ";
+
+                    subtitle += interval;
+                }
+                catch (ParseException pe) {
+                    log.error(pe, pe);
+                }
+            }
+        }
+
+        return subtitle;
     }
 
 

http://dive4elements.wald.intevation.org