# HG changeset patch # User Ingo Weinzierl # Date 1323872251 0 # Node ID 3632150dbe0bac1516d7220e4e112a152652532d # Parent 07b176b14205d64a3293707a25e52e5c3740e37b Implemented a ChartSettings with relevant Sections and Attributes for charts (NOTE: Work still in progress). flys-artifacts/trunk@3418 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 07b176b14205 -r 3632150dbe0b flys-artifacts/ChangeLog --- 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 + + * 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 * src/main/java/de/intevation/flys/artifacts/CrossSectionArtifact.java: diff -r 07b176b14205 -r 3632150dbe0b flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.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 Ingo Weinzierl + */ +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 : diff -r 07b176b14205 -r 3632150dbe0b flys-artifacts/src/main/java/de/intevation/flys/exports/BooleanAttribute.java --- /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 Ingo Weinzierl + */ +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 + * type with value boolean. + * + * @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 : diff -r 07b176b14205 -r 3632150dbe0b flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSection.java --- /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 Ingo Weinzierl + */ +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 : diff -r 07b176b14205 -r 3632150dbe0b flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSettings.java --- /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 Ingo Weinzierl + */ +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 : diff -r 07b176b14205 -r 3632150dbe0b flys-artifacts/src/main/java/de/intevation/flys/exports/EmptySettings.java --- 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 settings 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")); } } diff -r 07b176b14205 -r 3632150dbe0b flys-artifacts/src/main/java/de/intevation/flys/exports/StringAttribute.java --- /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 Ingo Weinzierl + */ +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 + * type with value string. + * + * @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 : diff -r 07b176b14205 -r 3632150dbe0b flys-artifacts/src/main/java/de/intevation/flys/exports/VisibleAttribute.java --- /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 Ingo Weinzierl + */ +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 display 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 : diff -r 07b176b14205 -r 3632150dbe0b flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java --- 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 ChartSettings with a chart specific section + * but with no axes settings. + * + * @return an instance of ChartSettings. + */ + 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 :