# HG changeset patch # User Ingo Weinzierl # Date 1323964736 0 # Node ID 5c1e7c1e9e09fc8761e23c6142114b236a49a47b # Parent 156304542edf40b307d5c94f33fcddbedd7aa189 Improved the ChartSettings returned by charts - it now contains a legend specific section. flys-artifacts/trunk@3426 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 156304542edf -r 5c1e7c1e9e09 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Thu Dec 15 12:05:06 2011 +0000 +++ b/flys-artifacts/ChangeLog Thu Dec 15 15:58:56 2011 +0000 @@ -1,3 +1,23 @@ +2011-12-15 Ingo Weinzierl + + * src/main/java/de/intevation/flys/exports/IntegerAttribute.java: New. + Concrete subclass of a DefaultAttribute for storing integer values. + + * src/main/java/de/intevation/flys/exports/LegendSection.java: New. A + concrete Section subclass to store legend specific attributes. + + * src/main/java/de/intevation/flys/exports/BooleanAttribute.java, + src/main/java/de/intevation/flys/exports/StringAttribute.java: Removed + needless import of org.w3c.dom.Attr. + + * src/main/java/de/intevation/flys/exports/ChartSettings.java: ChartSettings + is able to store a Section for legends now. + + * src/main/java/de/intevation/flys/exports/XYChartGenerator.java: Added + methods to retrieve the font size of legends and if the legend should be + visible or not. In addition, the ChartSettings returned by this instance + will now contain a LegendSection as well. + 2011-12-15 Ingo Weinzierl * src/main/java/de/intevation/flys/exports/XYChartGenerator.java: Introduced diff -r 156304542edf -r 5c1e7c1e9e09 flys-artifacts/src/main/java/de/intevation/flys/exports/BooleanAttribute.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/BooleanAttribute.java Thu Dec 15 12:05:06 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/BooleanAttribute.java Thu Dec 15 15:58:56 2011 +0000 @@ -1,6 +1,5 @@ package de.intevation.flys.exports; -import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; diff -r 156304542edf -r 5c1e7c1e9e09 flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSettings.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSettings.java Thu Dec 15 12:05:06 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSettings.java Thu Dec 15 15:58:56 2011 +0000 @@ -11,6 +11,7 @@ public class ChartSettings extends DefaultSettings { protected Section chartSection; + protected Section legendSection; protected Section axesSection; @@ -50,6 +51,34 @@ /** + * Sets the legend section. Old legend sections are removed. + * + * @param legendSection A new Section that stores legend specific + * attributes. + */ + public void setLegendSection(Section legendSection) { + Section oldLegendSection = getLegendSection(); + + if (oldLegendSection != null) { + removeSection(oldLegendSection); + } + + this.legendSection = legendSection; + addSection(legendSection); + } + + + /** + * Returns the Section that stores legend specific attributes. + * + * @return the Section that stores legend specific attributes. + */ + public Section getLegendSection() { + return legendSection; + } + + + /** * Adds a Section for a new axis of the chart. * * @param axisSection The Section specific for a chart axis. diff -r 156304542edf -r 5c1e7c1e9e09 flys-artifacts/src/main/java/de/intevation/flys/exports/IntegerAttribute.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/IntegerAttribute.java Thu Dec 15 15:58:56 2011 +0000 @@ -0,0 +1,37 @@ +package de.intevation.flys.exports; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + + +/** + * @author Ingo Weinzierl + */ +public class IntegerAttribute extends VisibleAttribute { + + + public IntegerAttribute(String name, int value, boolean visible) { + super(name, value, visible); + } + + + /** + * Calls VisibleAttribute.toXML() and appends afterwards an attribute + * type with value integer. + * + * @param parent The parent Node. + * + * @return the new Node that represents this Attribute. + */ + @Override + public Node toXML(Node parent) { + Document owner = parent.getOwnerDocument(); + + Element ele = (Element) super.toXML(parent); + ele.setAttribute("type", "integer"); + + return ele; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 156304542edf -r 5c1e7c1e9e09 flys-artifacts/src/main/java/de/intevation/flys/exports/LegendSection.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LegendSection.java Thu Dec 15 15:58:56 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 LegendSection extends DefaultSection { + + public static final String VISIBILITY_ATTR = "visibility"; + public static final String FONTSIZE_ATTR = "font-size"; + + + public LegendSection() { + super("legend"); + } + + + public void setFontSize(int fontSize) { + if (fontSize <= 0) { + return; + } + + Attribute attr = getAttribute(FONTSIZE_ATTR); + if (attr == null) { + attr = new IntegerAttribute(FONTSIZE_ATTR, fontSize, true); + addAttribute(FONTSIZE_ATTR, attr); + } + else { + attr.setValue(fontSize); + } + } + + + public void setVisibility(boolean visibility) { + Attribute attr = getAttribute(VISIBILITY_ATTR); + if (attr == null) { + attr = new BooleanAttribute(VISIBILITY_ATTR, visibility, true); + addAttribute(VISIBILITY_ATTR, attr); + } + else { + attr.setValue(visibility); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 156304542edf -r 5c1e7c1e9e09 flys-artifacts/src/main/java/de/intevation/flys/exports/StringAttribute.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/StringAttribute.java Thu Dec 15 12:05:06 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/StringAttribute.java Thu Dec 15 15:58:56 2011 +0000 @@ -1,6 +1,5 @@ package de.intevation.flys.exports; -import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; diff -r 156304542edf -r 5c1e7c1e9e09 flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Thu Dec 15 12:05:06 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Thu Dec 15 15:58:56 2011 +0000 @@ -38,6 +38,7 @@ import org.jfree.ui.RectangleInsets; import de.intevation.artifactdatabase.state.Facet; +import de.intevation.artifactdatabase.state.Section; import de.intevation.artifactdatabase.state.Settings; import de.intevation.flys.exports.ChartExportHelper; @@ -158,6 +159,28 @@ /** + * This method is used to determine, if the chart's legend is visible or + * not. Note: this method always returns true. + * + * @return true, if the legend should be visible, otherwise false. + */ + protected boolean isLegendVisible() { + return true; + } + + + /** + * This method is used to determine the font size of the chart's legend. + * Note: this method always returns 12. + * + * @return 12. + */ + protected int getLegendFontSize() { + return 12; + } + + + /** * This method is used to determine if the resulting chart should display * grid lines or not. Note: this method always returns true! * @@ -856,14 +879,40 @@ public Settings getSettings() { ChartSettings settings = new ChartSettings(); + Section chartSection = buildChartSection(); + Section legendSection = buildLegendSection(); + + settings.setChartSection(chartSection); + settings.setLegendSection(legendSection); + + return settings; + } + + + /** + * Creates a new ChartSection. + * + * @return a new ChartSection. + */ + protected Section buildChartSection() { ChartSection chartSection = new ChartSection(); chartSection.setTitle(getChartTitle()); chartSection.setSubtitle(getChartSubtitle()); chartSection.setDisplayGird(isGridVisible()); + return chartSection; + } - settings.setChartSection(chartSection); - return settings; + /** + * Creates a new LegendSection. + * + * @return a new LegendSection. + */ + protected Section buildLegendSection() { + LegendSection legendSection = new LegendSection(); + legendSection.setVisibility(isLegendVisible()); + legendSection.setFontSize(getLegendFontSize()); + return legendSection; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :