# HG changeset patch # User Ingo Weinzierl # Date 1324980734 0 # Node ID 76eeb3b4358ebf5e2690f975c23601051d1f7a77 # Parent 3cec0575d6555068a2ddde4fb61075a90da8cb7b Added an ExportSection to ChartSettings which provides attributes for chart 'width' and 'height'. flys-artifacts/trunk@3547 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 3cec0575d655 -r 76eeb3b4358e flys-artifacts/ChangeLog --- 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 + + * 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 * src/main/java/de/intevation/flys/exports/XYChartGenerator.java: Added and diff -r 3cec0575d655 -r 76eeb3b4358e flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSettings.java --- 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 : diff -r 3cec0575d655 -r 76eeb3b4358e flys-artifacts/src/main/java/de/intevation/flys/exports/ExportSection.java --- /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 Ingo Weinzierl + */ +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 : diff -r 3cec0575d655 -r 76eeb3b4358e flys-artifacts/src/main/java/de/intevation/flys/exports/TypeSection.java --- /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 Ingo Weinzierl + */ +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 : diff -r 3cec0575d655 -r 76eeb3b4358e flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java --- 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 axisSections = buildAxisSections(); for (AxisSection axisSection: axisSections) { @@ -1310,6 +1312,20 @@ /** + * Creates a new ExportSection with default values WIDTH=600 + * and HEIGHT=400. + * + * @return a new ExportSection. + */ + 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). *