Mercurial > dive4elements > river
changeset 1990:5c1e7c1e9e09
Improved the ChartSettings returned by charts - it now contains a legend specific section.
flys-artifacts/trunk@3426 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 15 Dec 2011 15:58:56 +0000 |
parents | 156304542edf |
children | 0bd7c3cf0af1 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/BooleanAttribute.java flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSettings.java flys-artifacts/src/main/java/de/intevation/flys/exports/IntegerAttribute.java flys-artifacts/src/main/java/de/intevation/flys/exports/LegendSection.java flys-artifacts/src/main/java/de/intevation/flys/exports/StringAttribute.java flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java |
diffstat | 7 files changed, 185 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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 <ingo@intevation.de> + + * 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 <ingo@intevation.de> * src/main/java/de/intevation/flys/exports/XYChartGenerator.java: Introduced
--- 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;
--- 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.
--- /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 <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +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 + * <i>type</i> with value <i>integer</i>. + * + * @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 :
--- /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 <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +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 :
--- 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;
--- 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. <b>Note: this method always returns true.</b> + * + * @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. + * <b>Note: this method always returns 12.</b> + * + * @return 12. + */ + protected int getLegendFontSize() { + return 12; + } + + + /** * This method is used to determine if the resulting chart should display * grid lines or not. <b>Note: this method always returns true!</b> * @@ -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 <i>ChartSection</i>. + * + * @return a new <i>ChartSection</i>. + */ + 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 <i>LegendSection</i>. + * + * @return a new <i>LegendSection</i>. + */ + 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 :