changeset 1092:0eb585cd3882

Added limited themeing-support for MainValues. flys-artifacts/trunk@2595 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 26 Aug 2011 12:44:12 +0000
parents 7230e087ef8b
children 139e7df1787c
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/themes.xml flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java
diffstat 3 files changed, 73 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Aug 26 12:42:12 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Aug 26 12:44:12 2011 +0000
@@ -1,3 +1,13 @@
+2011-08-26  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	Added limited themeing-support for MainValues.
+
+	* doc/conf/themes.xml:
+	  Added Q/W-MainValues themes.
+
+	* src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java:
+	  Added limited theming support, add legend entry for main values.
+
 2011-08-26  Ingo Weinzierl <ingo@intevation.de>
 
 	* doc/conf/conf.xml: Added a configuration node that points to the directory
--- a/flys-artifacts/doc/conf/themes.xml	Fri Aug 26 12:42:12 2011 +0000
+++ b/flys-artifacts/doc/conf/themes.xml	Fri Aug 26 12:44:12 2011 +0000
@@ -46,6 +46,18 @@
         </fields>
     </theme>
 
+    <theme name="ComputedDischargeCurveQ">
+        <fields>
+            <field name="linecolor" type="Color" display="Farbe" default="200, 0, 15"/>
+        </fields>
+    </theme>
+
+    <theme name="ComputedDischargeCurveW">
+        <fields>
+            <field name="linecolor" type="Color" display="Farbe" default="0, 215, 0"/>
+        </fields>
+    </theme>
+
 
     <!--
         Duration Curves
@@ -146,5 +158,7 @@
         <mapping from="discharge_longitudinal_section.w" to="DischargeLongitudinalSectionW"/>
         <mapping from="discharge_longitudinal_section.c" to="DischargeLongitudinalSectionC"/>
         <mapping from="discharge_longitudinal_section.q" to="DischargeLongitudinalSectionQ"/>
+        <mapping from="computed_discharge_curve.mainvalues.q" to="ComputedDischargeCurveQ"/>
+        <mapping from="computed_discharge_curve.mainvalues.w" to="ComputedDischargeCurveW"/>
     </mappings>
 </themes>
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java	Fri Aug 26 12:42:12 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java	Fri Aug 26 12:44:12 2011 +0000
@@ -6,12 +6,13 @@
 
 import org.w3c.dom.Document;
 
+import java.awt.Color;
 import org.jfree.chart.JFreeChart;
+import org.jfree.chart.annotations.XYAnnotation;
 import org.jfree.chart.title.TextTitle;
+import org.jfree.chart.plot.XYPlot;
 import org.jfree.data.xy.XYSeries;
-import org.jfree.chart.axis.ValueAxis;
-import org.jfree.chart.plot.XYPlot;
-import org.jfree.chart.annotations.XYAnnotation;
+import org.jfree.data.xy.XYSeriesCollection;
 
 import de.intevation.artifacts.Artifact;
 
@@ -24,6 +25,8 @@
 
 import de.intevation.flys.jfree.StickyAxisAnnotation;
 
+import de.intevation.flys.utils.ThemeUtil;
+
 
 /**
  * An OutGenerator that generates discharge curves.
@@ -50,11 +53,15 @@
 
     public static final String I18N_CHART_TITLE_DEFAULT = "Abflusskurve";
     public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]";
+    public static final String I18N_MAINVALUES_Q_LABEL = "Q (Haupt- und Extremwerte)";
+    public static final String I18N_MAINVALUES_W_LABEL = "W (Haupt- und Extremwerte)";
 
     /** List of Annotations (specifically, Main Values). */
     protected List<XYAnnotation> annotations;
 
-    // TODO Add pseudodataseries for having mainvalue-text in legend.
+    /** Pseudo-Dataseries to have a legend for annotations. */
+    protected XYSeriesCollection pseudoAnnotationData = null;
+
     // TODO Let theme pass through to annotations-facets.
 
 
@@ -126,15 +133,26 @@
      */
     protected void doMainValueWAnnotations(Object o, Document theme) {
         logger.debug("ComputedDischargeCurveGenerator set W MainValues.");
+        if (pseudoAnnotationData == null) {
+            pseudoAnnotationData = new XYSeriesCollection();
+        }
+
+        Color color = ThemeUtil.parseLineColorField(theme);
+        if (color == null) {
+            color = Color.black;
+        }
+
         List<NamedDouble> mainValuesW = (List<NamedDouble>) o;
         for (NamedDouble mv: mainValuesW) {
             float pos = (float) mv.getValue();
             String text = mv.getName();
             StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos,
                     StickyAxisAnnotation.SimpleAxis.Y_AXIS);
-            logger.debug("Adding W: " + text + " : " + pos);
+            ta.setPaint(color);
             this.annotations.add(ta);
         }
+        String label = msg(I18N_MAINVALUES_W_LABEL, I18N_MAINVALUES_W_LABEL, null);
+        pseudoAnnotationData.addSeries(new StyledXYSeries(label, theme));
     }
 
     
@@ -143,13 +161,26 @@
      */
     protected void doMainValueQAnnotations(Object o, Document theme) {
         logger.debug("ComputedDischargeCurveGenerator set Q MainValues.");
+
+        Color color = ThemeUtil.parseLineColorField(theme);
+        if (color == null) {
+            color = Color.black;
+        }
+
+        if (pseudoAnnotationData == null) {
+            pseudoAnnotationData = new XYSeriesCollection();
+        }
+
         List<NamedDouble> mainValuesQ = (List<NamedDouble>) o;
         for (NamedDouble mv: mainValuesQ) {
             float pos = (float) mv.getValue();
             String text = mv.getName();
             StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos);
+            ta.setPaint(color);
             this.annotations.add(ta);
         }
+        String label = msg(I18N_MAINVALUES_Q_LABEL, I18N_MAINVALUES_Q_LABEL, null);
+        pseudoAnnotationData.addSeries(new StyledXYSeries(label, theme));
     }
 
 
@@ -196,7 +227,19 @@
         addFirstAxisSeries(series);
     }
 
-
+    /**
+     * Add datasets to plot.
+     * @param plot plot to add datasets to.
+     * @todo merge with LongitudinalSectionGenerator/superclass.
+     */
+    @Override
+    protected void addDatasets(XYPlot plot) {
+        super.addDatasets(plot);
+        if (pseudoAnnotationData != null) {
+            plot.setDataset(2, pseudoAnnotationData);
+        }
+    }
+        
     protected String getSeriesName(WQKms wqkms) {
         Object[] args = new Object[] {
             getRiverName(),

http://dive4elements.wald.intevation.org