Mercurial > dive4elements > river
changeset 1986:3632150dbe0b
Implemented a ChartSettings with relevant Sections and Attributes for charts (NOTE: Work still in progress).
flys-artifacts/trunk@3418 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 14 Dec 2011 14:17:31 +0000 |
parents | 07b176b14205 |
children | 382e38164200 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java flys-artifacts/src/main/java/de/intevation/flys/exports/BooleanAttribute.java flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSection.java flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSettings.java flys-artifacts/src/main/java/de/intevation/flys/exports/EmptySettings.java flys-artifacts/src/main/java/de/intevation/flys/exports/StringAttribute.java flys-artifacts/src/main/java/de/intevation/flys/exports/VisibleAttribute.java flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java |
diffstat | 9 files changed, 340 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Wed Dec 14 12:16:24 2011 +0000 +++ b/flys-artifacts/ChangeLog Wed Dec 14 14:17:31 2011 +0000 @@ -1,3 +1,22 @@ +2011-12-14 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/exports/BooleanAttribute.java, + src/main/java/de/intevation/flys/exports/VisibleAttribute.java, + src/main/java/de/intevation/flys/exports/StringAttribute.java: New. + Concrete subclasses of a DefaultAttribute. + + * src/main/java/de/intevation/flys/exports/ChartSettings.java, + src/main/java/de/intevation/flys/exports/AxisSection.java, + src/main/java/de/intevation/flys/exports/ChartSection.java: + Implementations for chart settings. WORK IN PROGRESS! + + * src/main/java/de/intevation/flys/exports/XYChartGenerator.java: Override + the getSettings() method. The implementation here returns a ChartSettings + instance. + + * src/main/java/de/intevation/flys/exports/EmptySettings.java: Modified the + node name of the settings ("art:settings" -> "settings"). + 2011-12-14 Felix Wolfsteller <felix.wolfsteller@intevation.de> * src/main/java/de/intevation/flys/artifacts/CrossSectionArtifact.java:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java Wed Dec 14 14:17:31 2011 +0000 @@ -0,0 +1,35 @@ +package de.intevation.flys.exports; + + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +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 AxisSection extends DefaultSection { + + public AxisSection(String id) { + super(id); + } + + + @Override + public void toXML(Node parent) { + Document owner = parent.getOwnerDocument(); + Element axis = owner.createElement("axis"); + + parent.appendChild(axis); + + for (String key: getKeys()) { + Attribute attr = getAttribute(key); + attr.toXML(axis); + } + } +} +// 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/BooleanAttribute.java Wed Dec 14 14:17:31 2011 +0000 @@ -0,0 +1,40 @@ +package de.intevation.flys.exports; + +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class BooleanAttribute extends VisibleAttribute { + + + public BooleanAttribute(String name, boolean value, boolean visible) { + super(name, value, visible); + } + + + /** + * Calls VisibleAttribute.toXML() and appends afterwards an attribute + * <i>type</i> with value <i>boolean</i>. + * + * @param parent The parent Node. + * + * @return the new Node that represents this Attribute. + */ + @Override + public Node toXML(Node parent) { + Document owner = parent.getOwnerDocument(); + Node node = super.toXML(parent); + + Attr attr = owner.createAttribute("type"); + attr.setValue("boolean"); + + node.appendChild(attr); + + return node; + } +} +// 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/ChartSection.java Wed Dec 14 14:17:31 2011 +0000 @@ -0,0 +1,65 @@ +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 ChartSection extends DefaultSection { + + public static final String TITLE_ATTR = "title"; + public static final String SUBTITLE_ATTR = "subtitle"; + public static final String DISPLAYGRID_ATTR = "display-grid"; + + + public ChartSection() { + super("chart"); + } + + + public void setTitle(String title) { + if (title == null || title.length() == 0) { + return; + } + + Attribute attr = getAttribute(TITLE_ATTR); + if (attr == null) { + attr = new StringAttribute(TITLE_ATTR, title, true); + addAttribute(TITLE_ATTR, attr); + } + else { + attr.setValue(title); + } + } + + + public void setSubtitle(String subtitle) { + if (subtitle == null || subtitle.length() == 0) { + return; + } + + Attribute attr = getAttribute(SUBTITLE_ATTR); + if (attr == null) { + attr = new StringAttribute(SUBTITLE_ATTR, subtitle, true); + addAttribute(SUBTITLE_ATTR, attr); + } + else { + attr.setValue(subtitle); + } + } + + + public void setDisplayGird(boolean displayGrid) { + Attribute attr = getAttribute(DISPLAYGRID_ATTR); + if (attr == null) { + attr = new BooleanAttribute(DISPLAYGRID_ATTR, displayGrid, true); + addAttribute(DISPLAYGRID_ATTR, attr); + } + else { + attr.setValue(displayGrid); + } + } +} +// 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/ChartSettings.java Wed Dec 14 14:17:31 2011 +0000 @@ -0,0 +1,63 @@ +package de.intevation.flys.exports; + +import de.intevation.artifactdatabase.state.DefaultSection; +import de.intevation.artifactdatabase.state.DefaultSettings; +import de.intevation.artifactdatabase.state.Section; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class ChartSettings extends DefaultSettings { + + protected Section chartSection; + protected Section axesSection; + + + public ChartSettings() { + super(); + + axesSection = new DefaultSection("axes"); + addSection(axesSection); + } + + + /** + * Sets the chart section. Old chart sections are removed. + * + * @param chartSection A new Section that stores chart specific attributes. + */ + public void setChartSection(Section chartSection) { + Section oldChartSection = getChartSection(); + + if (oldChartSection != null) { + removeSection(oldChartSection); + } + + this.chartSection = chartSection; + addSection(chartSection); + } + + + /** + * Returns the Section that stores chart specific attributes. + * + * @return the Section that stores chart specific attributes. + */ + public Section getChartSection() { + return chartSection; + } + + + /** + * Adds a Section for a new axis of the chart. + * + * @param axisSection The Section specific for a chart axis. + */ + public void addAxisSection(Section axisSection) { + if (axisSection != null) { + axesSection.addSubsection(axisSection); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/EmptySettings.java Wed Dec 14 12:16:24 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/EmptySettings.java Wed Dec 14 14:17:31 2011 +0000 @@ -56,6 +56,15 @@ /** + * This method has no function. It is not implemented! + */ + @Override + public void removeSection(Section section) { + // do nothing + } + + + /** * This method creates an empty <i>settings</i> DOM node. * * @param parent A parent DOM node. @@ -63,6 +72,6 @@ @Override public void toXML(Node parent) { Document owner = parent.getOwnerDocument(); - parent.appendChild(owner.createElement("art:settings")); + parent.appendChild(owner.createElement("settings")); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/StringAttribute.java Wed Dec 14 14:17:31 2011 +0000 @@ -0,0 +1,40 @@ +package de.intevation.flys.exports; + +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class StringAttribute extends VisibleAttribute { + + + public StringAttribute(String name, String value, boolean visible) { + super(name, value, visible); + } + + + /** + * Calls VisibleAttribute.toXML() and appends afterwards an attribute + * <i>type</i> with value <i>string</i>. + * + * @param parent The parent Node. + * + * @return the new Node that represents this Attribute. + */ + @Override + public Node toXML(Node parent) { + Document owner = parent.getOwnerDocument(); + Node node = super.toXML(parent); + + Attr attr = owner.createAttribute("type"); + attr.setValue("string"); + + node.appendChild(attr); + + return node; + } +} +// 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/VisibleAttribute.java Wed Dec 14 14:17:31 2011 +0000 @@ -0,0 +1,45 @@ +package de.intevation.flys.exports; + +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +import de.intevation.artifactdatabase.state.DefaultAttribute; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class VisibleAttribute extends DefaultAttribute { + + protected boolean visible; + + + public VisibleAttribute(String name, Object value, boolean visible) { + super(name, value); + this.visible = visible; + } + + + /** + * This implementation of Attribute calls DefaultAttribute.toXML() first. + * After this, a new Attr <i>display</i> is added to the resulting Node. + * + * @param parent The parent Node. + * + * @return a new Node that represents this Attribute. + */ + @Override + public Node toXML(Node parent) { + Document owner = parent.getOwnerDocument(); + Node node = super.toXML(parent); + + Attr attr = owner.createAttribute("display"); + attr.setValue(String.valueOf(visible)); + + node.appendChild(attr); + + return node; + } +} +// 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 Wed Dec 14 12:16:24 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Wed Dec 14 14:17:31 2011 +0000 @@ -38,6 +38,7 @@ import org.jfree.ui.RectangleInsets; import de.intevation.artifactdatabase.state.Facet; +import de.intevation.artifactdatabase.state.Settings; import de.intevation.flys.exports.ChartExportHelper; import de.intevation.flys.jfree.FLYSAnnotation; @@ -821,5 +822,27 @@ annotations.setLabel(facet.getDescription()); addAnnotations(annotations, visible); } + + + /** + * Returns an instance of <i>ChartSettings</i> with a chart specific section + * but with no axes settings. + * + * @return an instance of <i>ChartSettings</i>. + */ + public Settings getSettings() { + ChartSettings settings = new ChartSettings(); + + ChartSection chartSection = new ChartSection(); + // XXX Before we can do this, the FLYSArtifactCollection needs to call + // doOut() for each facet. + //chartSection.setTitle(getChartTitle()); + //chartSection.setSubtitle("TODO SUBTITLE"); + //chartSection.setDisplayGird(true); + + settings.setChartSection(chartSection); + + return settings; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :