changeset 1991:0bd7c3cf0af1

Added axis sections into charts Settings. flys-artifacts/trunk@3427 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 15 Dec 2011 17:10:42 +0000
parents 5c1e7c1e9e09
children e1c9f28e2675
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java
diffstat 4 files changed, 117 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Dec 15 15:58:56 2011 +0000
+++ b/flys-artifacts/ChangeLog	Thu Dec 15 17:10:42 2011 +0000
@@ -1,3 +1,19 @@
+2011-12-15  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/exports/AxisSection.java: Added methods
+	  to set the axis label and id.
+
+	* src/main/java/de/intevation/flys/exports/XYChartGenerator.java: Improved
+	  the ChartSettings that will now contain a set of AxisSections. The new
+	  buildAxisSections() method in this class is not implemented and needs to
+	  be implemented by subclasses.
+
+	* src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java:
+	  Override buildAxisSections() of XYChartGenerator to create an AxisSection 
+	  for each axis that is able to be displayed in this sort of chart. In
+	  addition, there is a new method getYAxisLabel(int) that returns the label
+	  for a specific Y axis.
+
 2011-12-15  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/IntegerAttribute.java: New.
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java	Thu Dec 15 15:58:56 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java	Thu Dec 15 17:10:42 2011 +0000
@@ -14,8 +14,44 @@
  */
 public class AxisSection extends DefaultSection {
 
-    public AxisSection(String id) {
-        super(id);
+    public static final String IDENTIFIER_ATTR = "id";
+    public static final String LABEL_ATTR      = "label";
+
+
+    public AxisSection() {
+        super("axis");
+    }
+
+
+    public void setIdentifier(String identifier) {
+        if (identifier == null || identifier.length() == 0) {
+            return;
+        }
+
+        Attribute attr = getAttribute(IDENTIFIER_ATTR);
+        if (attr == null) {
+            attr = new StringAttribute(IDENTIFIER_ATTR, identifier, false);
+            addAttribute(IDENTIFIER_ATTR, attr);
+        }
+        else {
+            attr.setValue(identifier);
+        }
+    }
+
+
+    public void setLabel(String label) {
+        if (label == null) {
+            return;
+        }
+
+        Attribute attr = getAttribute(LABEL_ATTR);
+        if (attr == null) {
+            attr = new StringAttribute(LABEL_ATTR, label, true);
+            addAttribute(LABEL_ATTR, attr);
+        }
+        else {
+            attr.setValue(label);
+        }
     }
 
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Thu Dec 15 15:58:56 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Thu Dec 15 17:10:42 2011 +0000
@@ -1,6 +1,8 @@
 package de.intevation.flys.exports;
 
 import java.awt.Font;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.log4j.Logger;
 
@@ -14,6 +16,7 @@
 import org.w3c.dom.Document;
 
 import de.intevation.artifactdatabase.state.ArtifactAndFacet;
+import de.intevation.artifactdatabase.state.Section;
 import de.intevation.artifactdatabase.state.Facet;
 
 import de.intevation.flys.artifacts.FLYSArtifact;
@@ -191,16 +194,8 @@
     @Override
     protected NumberAxis createYAxis(int index) {
         Font labelFont = new Font("Tahoma", Font.BOLD, 14);
-        String label = "default";
-        if (index == YAXIS.W.idx) {
-            label = getWAxisLabel();
-        }
-        else if (index == YAXIS.Q.idx) {
-            label = msg(getQAxisLabelKey(), getQAxisDefaultLabel());
-        }
-        else if (index == YAXIS.D.idx) {
-            label = msg(I18N_WDIFF_YAXIS_LABEL, I18N_WDIFF_YAXIS_LABEL_DEFAULT);
-        }
+        String label   = getYAxisLabel(index);
+
         NumberAxis axis = new NumberAxis(label);
         // "Q" Axis shall include 0.
         if (index == YAXIS.Q.idx) {
@@ -213,6 +208,24 @@
         return axis;
     }
 
+
+    protected String getYAxisLabel(int index) {
+        String label = "default";
+
+        if (index == YAXIS.W.idx) {
+            label = getWAxisLabel();
+        }
+        else if (index == YAXIS.Q.idx) {
+            label = msg(getQAxisLabelKey(), getQAxisDefaultLabel());
+        }
+        else if (index == YAXIS.D.idx) {
+            label = msg(I18N_WDIFF_YAXIS_LABEL, I18N_WDIFF_YAXIS_LABEL_DEFAULT);
+        }
+
+        return label;
+    }
+
+
     /**
      * Get default value for the second Y-Axis' label (if no translation was
      * found).
@@ -450,5 +463,28 @@
             ? prefix + "(" + name +")"
             : name;
     }
+
+
+    @Override
+    protected List<Section> buildAxisSections() {
+        List<Section> axisSections = new ArrayList<Section>();
+
+        for (YAXIS axis: YAXIS.values()) {
+            String identifier = axis.toString();
+
+            AxisSection axisSection = new AxisSection();
+            axisSection.setIdentifier(identifier);
+            axisSection.setLabel(getYAxisLabel(axis.idx));
+
+            // TODO font-size
+            // TODO fixation
+            // TODO lower
+            // TODO upper
+
+            axisSections.add(axisSection);
+        }
+
+        return axisSections;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Thu Dec 15 15:58:56 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Thu Dec 15 17:10:42 2011 +0000
@@ -885,6 +885,11 @@
         settings.setChartSection(chartSection);
         settings.setLegendSection(legendSection);
 
+        List<Section> axisSections = buildAxisSections();
+        for (Section axisSection: axisSections) {
+            settings.addAxisSection(axisSection);
+        }
+
         return settings;
     }
 
@@ -914,5 +919,17 @@
         legendSection.setFontSize(getLegendFontSize());
         return legendSection;
     }
+
+
+    /**
+     * Creates new Sections for chart axes. Subclasses of this ChartGenerator
+     * should override this method to include all necessary axes in that
+     * concrete chart.
+     *
+     * @return an empty list.
+     */
+    protected List<Section> buildAxisSections() {
+        return new ArrayList<Section>();
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org