# HG changeset patch # User Felix Wolfsteller # Date 1346158031 0 # Node ID f84854eba0b372f8aef7137c450a004860866388 # Parent 68beaa8277513f2c0c0051cd73ed05c3ba7eddb0 Preparations for logo inclusion in charts. flys-artifacts/trunk@5278 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 68beaa827751 -r f84854eba0b3 flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java Tue Aug 28 11:45:23 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java Tue Aug 28 12:47:11 2012 +0000 @@ -752,6 +752,8 @@ chartSection.setTitle(getChartTitle()); chartSection.setSubtitle(getChartSubtitle()); chartSection.setDisplayGrid(isGridVisible()); + // TODO default to: "none" + chartSection.setDisplayLogo(showLogo()); return chartSection; } @@ -1028,6 +1030,30 @@ } + /** Return the logo id from settings. */ + protected String showLogo(ChartSettings chartSettings) { + if (chartSettings != null) { + ChartSection cs = chartSettings.getChartSection(); + String logo = cs.getDisplayLogo(); + + return logo; + } + // TODO "none" instead of null? + return null; + } + + + /** + * This method is used to determine if a logo should be added to the plot. + * + * @return logo name (null if none). + */ + protected String showLogo() { + ChartSettings chartSettings = getChartSettings(); + return showLogo(chartSettings); + } + + /** * This method is used to determine the font size of the chart's legend. If * a settings instance is set, this instance determines the font diff -r 68beaa827751 -r f84854eba0b3 flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSection.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSection.java Tue Aug 28 11:45:23 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSection.java Tue Aug 28 12:47:11 2012 +0000 @@ -10,6 +10,7 @@ public static final String TITLE_ATTR = "title"; public static final String SUBTITLE_ATTR = "subtitle"; public static final String DISPLAYGRID_ATTR = "display-grid"; + public static final String DISPLAYLOGO_ATTR = "display-logo"; public ChartSection() { @@ -37,7 +38,17 @@ } - public void setDisplayGird(boolean displayGrid) { + public String getDisplayLogo() { + return getStringValue(DISPLAYLOGO_ATTR); + } + + + public void setDisplayLogo(String logo) { + setChoiceStringValue(DISPLAYLOGO_ATTR, logo, "logo"); + } + + + public void setDisplayGrid(boolean displayGrid) { setBooleanValue(DISPLAYGRID_ATTR, displayGrid); } diff -r 68beaa827751 -r f84854eba0b3 flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSettings.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSettings.java Tue Aug 28 11:45:23 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSettings.java Tue Aug 28 12:47:11 2012 +0000 @@ -224,22 +224,29 @@ } + /** + * From document chart create ChartSection and populate it with attributes. + * Give this object to target as chartsection. + */ protected static void parseChart(ChartSettings target, Node chart) { ChartSection chartSection = new ChartSection(); String title = XMLUtils.xpathString(chart, "chart/title", null); String sub = XMLUtils.xpathString(chart, "chart/subtitle", null); String grid = XMLUtils.xpathString(chart, "chart/display-grid", null); + String logo = XMLUtils.xpathString(chart, "chart/display-logo", null); if (logger.isDebugEnabled()) { logger.debug("Found chart title: '" + title + "'"); logger.debug("Found chart subtitle: '" + sub + "'"); logger.debug("Found chart grid: '" + grid + "'"); + logger.debug("Found chart logo: '" + logo + "'"); } chartSection.setTitle(title); chartSection.setSubtitle(sub); chartSection.setDisplayGrid(Boolean.valueOf(grid)); + chartSection.setDisplayLogo(logo); target.setChartSection(chartSection); } diff -r 68beaa827751 -r f84854eba0b3 flys-artifacts/src/main/java/de/intevation/flys/exports/ChoiceStringAttribute.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChoiceStringAttribute.java Tue Aug 28 12:47:11 2012 +0000 @@ -0,0 +1,45 @@ +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 ChoiceStringAttribute extends StringAttribute { + + /** Indicator which type of choice is dealt with. */ + protected String choiceType; + + + public ChoiceStringAttribute(String name, + String value, + boolean visible, + String choiceType) { + super(name, value, visible); + this.choiceType = choiceType; + } + + + /** + * 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(); + + Element ele = (Element) super.toXML(parent); + ele.setAttribute("type", "string"); + ele.setAttribute("choice", choiceType); + + return ele; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 68beaa827751 -r f84854eba0b3 flys-artifacts/src/main/java/de/intevation/flys/exports/TypeSection.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/TypeSection.java Tue Aug 28 11:45:23 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/TypeSection.java Tue Aug 28 12:47:11 2012 +0000 @@ -1,5 +1,7 @@ package de.intevation.flys.exports; +import org.apache.log4j.Logger; + import de.intevation.artifactdatabase.state.Attribute; import de.intevation.artifactdatabase.state.DefaultSection; @@ -9,11 +11,29 @@ */ public class TypeSection extends DefaultSection { + private static final Logger logger = Logger.getLogger(TypeSection.class); + public TypeSection(String key) { super(key); } + public void setChoiceStringValue(String key, String value, String choiceType) { + if (value == null || value.length() == 0) { + return; + } + + Attribute attr = getAttribute(key); + if (attr == null) { + attr = new ChoiceStringAttribute(key, value, true, choiceType); + addAttribute(key, attr); + } + else { + attr.setValue(value); + } + } + + public void setStringValue(String key, String value) { if (value == null || value.length() == 0) { return; @@ -37,6 +57,8 @@ return (String) attr.getValue(); } + logger.debug("attribute " + key + " not found in typesection.getString"); + return null; }