changeset 2056:76eeb3b4358e

Added an ExportSection to ChartSettings which provides attributes for chart 'width' and 'height'. flys-artifacts/trunk@3547 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 27 Dec 2011 10:12:14 +0000
parents 3cec0575d655
children 49b7c2b1a6a7
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSettings.java flys-artifacts/src/main/java/de/intevation/flys/exports/ExportSection.java flys-artifacts/src/main/java/de/intevation/flys/exports/TypeSection.java flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java
diffstat 5 files changed, 241 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Dec 27 09:09:42 2011 +0000
+++ b/flys-artifacts/ChangeLog	Tue Dec 27 10:12:14 2011 +0000
@@ -1,3 +1,19 @@
+2011-12-27  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/exports/TypeSection.java: New. This
+	  Section defines some convinience methods to add/set string, integer,
+	  double and boolean values.
+
+	* src/main/java/de/intevation/flys/exports/ExportSection.java: New.
+	  Subclasses TypeSection. The ExportSection currently offers attributes
+	  'width' and 'height'.
+
+	* src/main/java/de/intevation/flys/exports/ChartSettings.java: Added
+	  getter/setter methods to support an ExportSection.
+
+	* src/main/java/de/intevation/flys/exports/XYChartGenerator.java: Create an
+	  ExportSection while initial ChartSettings creation.
+
 2011-12-27  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/XYChartGenerator.java: Added and
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSettings.java	Tue Dec 27 09:09:42 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSettings.java	Tue Dec 27 10:12:14 2011 +0000
@@ -23,6 +23,7 @@
 
     protected ChartSection  chartSection;
     protected LegendSection legendSection;
+    protected ExportSection exportSection;
     protected Section       axesSection;
 
 
@@ -90,6 +91,34 @@
 
 
     /**
+     * Sets the export section. Old export sections are removed.
+     *
+     * @param exportSection A new Section that stores export specific
+     * attributes.
+     */
+    public void setExportSection(ExportSection exportSection) {
+        ExportSection oldExportSection = getExportSection();
+
+        if (oldExportSection != null) {
+            removeSection(oldExportSection);
+        }
+
+        this.exportSection = exportSection;
+        addSection(exportSection);
+    }
+
+
+    /**
+     * Returns the Section that stores export specific attributes.
+     *
+     * @return the Section that stores export specific attributes.
+     */
+    public ExportSection getExportSection() {
+        return exportSection;
+    }
+
+
+    /**
      * Adds a Section for a new axis of the chart.
      *
      * @param axisSection The Section specific for a chart axis.
@@ -142,6 +171,7 @@
         parseAxes(chartSettings, settings);
         parseChart(chartSettings, settings);
         parseLegend(chartSettings, settings);
+        parseExport(chartSettings, settings);
 
         return chartSettings;
     }
@@ -231,5 +261,23 @@
 
         target.setLegendSection(section);
     }
+
+
+    protected static void parseExport(ChartSettings target, Node export) {
+        ExportSection section = new ExportSection();
+
+        String width  = XMLUtils.xpathString(export, "export/width", null);
+        String height = XMLUtils.xpathString(export, "export/height", null);
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("Found export width : '" + width + "'");
+            logger.debug("Found export height: '" + height + "'");
+        }
+
+        section.setWidth(Integer.valueOf(width.length() > 0 ? width : "-1"));
+        section.setHeight(Integer.valueOf(height.length() > 0 ? height : "-1"));
+
+        target.setExportSection(section);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ExportSection.java	Tue Dec 27 10:12:14 2011 +0000
@@ -0,0 +1,48 @@
+package de.intevation.flys.exports;
+
+import de.intevation.artifactdatabase.state.Attribute;
+import de.intevation.artifactdatabase.state.DefaultSection;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class ExportSection extends TypeSection {
+
+    public static final String WIDTH_ATTR  = "width";
+    public static final String HEIGHT_ATTR = "height";
+
+
+    public ExportSection() {
+        super("export");
+    }
+
+
+    public void setWidth(int width) {
+        if (width <= 0) {
+            return;
+        }
+
+        setIntegerValue(WIDTH_ATTR, width);
+    }
+
+
+    public Integer getWidth() {
+        return getIntegerValue(WIDTH_ATTR);
+    }
+
+
+    public void setHeight(int height) {
+        if (height <= 0) {
+            return;
+        }
+
+        setIntegerValue(HEIGHT_ATTR, height);
+    }
+
+
+    public Integer getHeight() {
+        return getIntegerValue(HEIGHT_ATTR);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/TypeSection.java	Tue Dec 27 10:12:14 2011 +0000
@@ -0,0 +1,113 @@
+package de.intevation.flys.exports;
+
+import de.intevation.artifactdatabase.state.Attribute;
+import de.intevation.artifactdatabase.state.DefaultSection;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class TypeSection extends DefaultSection {
+
+    public TypeSection(String key) {
+        super(key);
+    }
+
+
+    public void setStringValue(String key, String value) {
+        if (value == null || value.length() == 0) {
+            return;
+        }
+
+        Attribute attr = getAttribute(key);
+        if (attr == null) {
+            attr = new StringAttribute(key, value, true);
+            addAttribute(key, attr);
+        }
+        else {
+            attr.setValue(value);
+        }
+    }
+
+
+    public String getStringValue(String key) {
+        Attribute attr = getAttribute(key);
+
+        if (attr instanceof StringAttribute) {
+            return (String) attr.getValue();
+        }
+
+        return null;
+    }
+
+
+    public void setIntegerValue(String key, int value) {
+        Attribute attr = getAttribute(key);
+        if (attr == null) {
+            attr = new IntegerAttribute(key, value, true);
+            addAttribute(key, attr);
+        }
+        else {
+            attr.setValue(value);
+        }
+    }
+
+
+    public Integer getIntegerValue(String key) {
+        Attribute attr = getAttribute(key);
+
+        if (attr instanceof IntegerAttribute) {
+            return (Integer) attr.getValue();
+        }
+
+        return null;
+    }
+
+
+
+    public void setDoubleValue(String key, double value) {
+        Attribute attr = getAttribute(key);
+        if (attr == null) {
+            attr = new DoubleAttribute(key, value, true);
+            addAttribute(key, attr);
+        }
+        else {
+            attr.setValue(value);
+        }
+    }
+
+
+    public Double getDoubleValue(String key) {
+        Attribute attr = getAttribute(key);
+
+        if (attr instanceof DoubleAttribute) {
+            return (Double) attr.getValue();
+        }
+
+        return null;
+    }
+
+
+    public void setBooleanValue(String key, boolean value) {
+        Attribute attr = getAttribute(key);
+        if (attr == null) {
+            attr = new BooleanAttribute(key, value, true);
+            addAttribute(key, attr);
+        }
+        else {
+            attr.setValue(value);
+        }
+    }
+
+
+    public Boolean getBooleanValue(String key) {
+        Attribute attr = getAttribute(key);
+
+        if (attr instanceof BooleanAttribute) {
+            return (Boolean) attr.getValue();
+        }
+
+        return null;
+    }
+}
+// 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	Tue Dec 27 09:09:42 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Tue Dec 27 10:12:14 2011 +0000
@@ -1269,9 +1269,11 @@
 
         ChartSection  chartSection  = buildChartSection();
         LegendSection legendSection = buildLegendSection();
+        ExportSection exportSection = buildExportSection();
 
         settings.setChartSection(chartSection);
         settings.setLegendSection(legendSection);
+        settings.setExportSection(exportSection);
 
         List<AxisSection> axisSections = buildAxisSections();
         for (AxisSection axisSection: axisSections) {
@@ -1310,6 +1312,20 @@
 
 
     /**
+     * Creates a new <i>ExportSection</i> with default values <b>WIDTH=600</b>
+     * and <b>HEIGHT=400</b>.
+     *
+     * @return a new <i>ExportSection</i>.
+     */
+    protected ExportSection buildExportSection() {
+        ExportSection exportSection = new ExportSection();
+        exportSection.setWidth(600);
+        exportSection.setHeight(400);
+        return exportSection;
+    }
+
+
+    /**
      * Creates a list of Sections that contains all axes of the chart (including
      * X and Y axes).
      *

http://dive4elements.wald.intevation.org