changeset 2047:0318fa6f0844

Make use of first attributes specified in the ChartSettings. NOTE: work is still in progress. flys-artifacts/trunk@3535 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 23 Dec 2011 08:57:25 +0000
parents 2ae0627f956e
children 3157a78e6494
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java flys-artifacts/src/main/java/de/intevation/flys/exports/ATExporter.java flys-artifacts/src/main/java/de/intevation/flys/exports/AbstractExporter.java flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/OutGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/ReportGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java
diffstat 11 files changed, 259 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Dec 23 08:51:28 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Dec 23 08:57:25 2011 +0000
@@ -1,3 +1,27 @@
+2011-12-23  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/exports/OutGenerator.java: Added a
+	  setSettings(Settings) method.
+
+	* src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java:
+	  Call OutGenerator.setSettings() before calling doOut() for each Facet.
+
+	* src/main/java/de/intevation/flys/exports/ChartGenerator.java: Implemented
+	  setSettings() and added convinience methods to access chart specific
+	  settings.
+
+	* src/main/java/de/intevation/flys/exports/MapGenerator.java,
+	  src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java,
+	  src/main/java/de/intevation/flys/exports/AbstractExporter.java,
+	  src/main/java/de/intevation/flys/exports/ATExporter.java,
+	  src/main/java/de/intevation/flys/exports/ReportGenerator.java: Implemented
+	  setSettings().
+
+	* src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java,
+	  src/main/java/de/intevation/flys/exports/XYChartGenerator.java: Make use
+	  of the attributes specified in the Settings: the title, subtitle,
+	  displayGrid and displayLegend settings are functional now.
+
 2011-12-23  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/ChartSettings.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Fri Dec 23 08:51:28 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Fri Dec 23 08:57:25 2011 +0000
@@ -328,6 +328,7 @@
         Settings settings = output.getSettings();
 
         generator.init(format, out, context);
+        generator.setSettings(settings);
         prepareMasterArtifact(generator, context);
 
         try {
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ATExporter.java	Fri Dec 23 08:51:28 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ATExporter.java	Fri Dec 23 08:57:25 2011 +0000
@@ -89,8 +89,20 @@
      *
      * @return an instance of <i>EmptySettings</i>.
      */
+    @Override
     public Settings getSettings() {
         return new EmptySettings();
     }
+
+
+    /**
+     * This method is not implemented!
+     *
+     * @param settings A settings object.
+     */
+    @Override
+    public void setSettings(Settings settings) {
+        // do nothing here
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/AbstractExporter.java	Fri Dec 23 08:51:28 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/AbstractExporter.java	Fri Dec 23 08:57:25 2011 +0000
@@ -230,5 +230,14 @@
     public Settings getSettings() {
         return new EmptySettings();
     }
+
+
+    /**
+     * This method is not implemented. Override it in subclasses if those need a
+     * <i>Settings</i> object.
+     */
+    public void setSettings(Settings settings) {
+        // do nothing
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java	Fri Dec 23 08:51:28 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java	Fri Dec 23 08:57:25 2011 +0000
@@ -78,6 +78,9 @@
     /** The artifact that is used to decorate the chart with meta information.*/
     protected Artifact master;
 
+    /** The settings that should be used during output creation.*/
+    protected Settings settings;
+
 
     public void init(Document request, OutputStream out, CallContext context) {
         logger.debug("ChartGenerator.init");
@@ -93,6 +96,98 @@
     }
 
 
+    @Override
+    public void setSettings(Settings settings) {
+        this.settings = settings;
+    }
+
+
+    /**
+     * Returns the chart title provided by <i>settings</i>.
+     *
+     * @param settings A ChartSettings object.
+     *
+     * @return the title provided by <i>settings</i> or null if no
+     * <i>ChartSection</i> is provided by <i>settings</i>.
+     *
+     * @throws NullPointerException if <i>settings</i> is null.
+     */
+    public String getChartTitle(ChartSettings settings) {
+        ChartSection cs = settings.getChartSection();
+        return cs != null ? cs.getTitle() : null;
+    }
+
+
+    /**
+     * Returns the chart subtitle provided by <i>settings</i>.
+     *
+     * @param settings A ChartSettings object.
+     *
+     * @return the subtitle provided by <i>settings</i> or null if no
+     * <i>ChartSection</i> is provided by <i>settings</i>.
+     *
+     * @throws NullPointerException if <i>settings</i> is null.
+     */
+    public String getChartSubtitle(ChartSettings settings) {
+        ChartSection cs = settings.getChartSection();
+        return cs != null ? cs.getSubtitle() : null;
+    }
+
+
+    /**
+     * Returns a boolean object that determines if the chart grid should be
+     * visible or not. This information needs to be provided by <i>settings</i>,
+     * otherweise the default is true.
+     *
+     * @param settings A ChartSettings object.
+     *
+     * @return true, if the chart grid should be visible otherwise false.
+     *
+     * @throws NullPointerException if <i>settings</i> is null.
+     */
+    public boolean isGridVisible(ChartSettings settings) {
+        ChartSection     cs = settings.getChartSection();
+        Boolean displayGrid = cs.getDisplayGrid();
+
+        return displayGrid != null ? displayGrid : true;
+    }
+
+
+    /**
+     * Returns a boolean object that determines if the chart legend should be
+     * visible or not. This information needs to be provided by <i>settings</i>,
+     * otherwise the default is true.
+     *
+     * @param settings A ChartSettings object.
+     *
+     * @return true, if the chart legend should be visible otherwise false.
+     *
+     * @throws NullPointerException if <i>settings</i> is null.
+     */
+    public boolean isLegendVisible(ChartSettings settings) {
+        LegendSection      ls = settings.getLegendSection();
+        Boolean displayLegend = ls.getVisibility();
+
+        return displayLegend != null ? displayLegend : true;
+    }
+
+
+    /**
+     * Returns the legend font size specified in <i>settings</i> or null if no
+     * <i>LegendSection</i> is provided by <i>settings</i>.
+     *
+     * @param settings A ChartSettings object.
+     *
+     * @return the legend font size or null.
+     *
+     * @throws NullPointerException if <i>settings</i> is null.
+     */
+    public Integer getLegendFontSize(ChartSettings settings) {
+        LegendSection ls = settings.getLegendSection();
+        return ls != null ? ls.getFontSize() : null;
+    }
+
+
     protected Locale getLocale() {
         CallMeta           meta = context.getMeta();
         PreferredLocale[] prefs = meta.getLanguages();
@@ -295,7 +390,22 @@
      * @return an instance of <i>EmptySettings</i>.
      */
     public Settings getSettings() {
-        return new EmptySettings();
+        return settings != null ? settings : new EmptySettings();
+    }
+
+
+    /**
+     * Returns the <i>settings</i> as <i>ChartSettings</i>.
+     *
+     * @return the <i>settings</i> as <i>ChartSettings</i> or null, if
+     * <i>settings</i> is not an instance of <i>ChartSettings</i>.
+     */
+    public ChartSettings getChartSettings() {
+        if (settings instanceof ChartSettings) {
+            return (ChartSettings) settings;
+        }
+
+        return null;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java	Fri Dec 23 08:51:28 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java	Fri Dec 23 08:57:25 2011 +0000
@@ -151,12 +151,25 @@
 
 
     /**
-     * Returns an instance of <i>EmptySettings</i> currently!
+     * A proxy method which calls <i>generator</i>.getSettings() and returns its
+     * return value.
      *
-     * @return an instance of <i>EmptySettings</i>.
+     * @return a Settings object provided by <i>generator</i>.
      */
+    @Override
     public Settings getSettings() {
-        return new EmptySettings();
+        return generator.getSettings();
+    }
+
+
+    /**
+     * A proxy method which calls <i>generator</i>.setSettings().
+     *
+     * @param settings A settings object for the <i>generator</i>.
+     */
+    @Override
+    public void setSettings(Settings settings) {
+        generator.setSettings(settings);
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Fri Dec 23 08:51:28 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Fri Dec 23 08:57:25 2011 +0000
@@ -125,15 +125,35 @@
 
 
     /**
-     * Get internationalized title for chart.
+     * Returns a title for the chart from ChartSettings object
+     * if this object is not null or creates a default title.
+     *
+     * @return a title.
      */
+    @Override
     public String getChartTitle() {
+        ChartSettings chartSettings = getChartSettings();
+        if (chartSettings != null) {
+            return getChartTitle(chartSettings);
+        }
+
         return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT);
     }
 
 
+    /**
+     * Returns a subtitle for the chart from ChartSettings object
+     * if this object is not null or creates a default title.
+     *
+     * @return a title.
+     */
     @Override
     protected String getChartSubtitle() {
+        ChartSettings chartSettings = getChartSettings();
+        if (chartSettings != null) {
+            return getChartSubtitle(chartSettings);
+        }
+
         double[] dist = getRange();
 
         Object[] args = new Object[] {
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java	Fri Dec 23 08:51:28 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java	Fri Dec 23 08:57:25 2011 +0000
@@ -40,6 +40,8 @@
 
     protected Artifact master;
 
+    protected Settings settings;
+
     protected Document request;
 
     protected OutputStream out;
@@ -291,8 +293,15 @@
      *
      * @return an instance of <i>EmptySettings</i>.
      */
+    @Override
     public Settings getSettings() {
         return new EmptySettings();
     }
+
+
+    @Override
+    public void setSettings(Settings settings) {
+        this.settings = settings;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/OutGenerator.java	Fri Dec 23 08:51:28 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/OutGenerator.java	Fri Dec 23 08:57:25 2011 +0000
@@ -57,6 +57,15 @@
     void generate() throws IOException;
 
     /**
+     * This method is used to set a <i>Settings</i> object for the <i>Output</i>
+     * that is produced by this <i>OutGenerator</i>.
+     *
+     * @param settings The <i>Settings</i> that might be used while
+     * <i>Output</i> creation.
+     */
+    void setSettings(Settings settings);
+
+    /**
      * Returns the Settings for the Output produced by this OutGenerator.
      *
      * @return the Settings for the Output produced by this OutGenerator.
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ReportGenerator.java	Fri Dec 23 08:51:28 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ReportGenerator.java	Fri Dec 23 08:57:25 2011 +0000
@@ -72,5 +72,14 @@
     public Settings getSettings() {
         return new EmptySettings();
     }
+
+
+    /**
+     * This method is not implemented. Override it in subclasses if those need a
+     * <i>Settings</i> object.
+     */
+    public void setSettings(Settings settings) {
+        // do nothing
+    }
 }
 // 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	Fri Dec 23 08:51:28 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Fri Dec 23 08:57:25 2011 +0000
@@ -205,23 +205,39 @@
 
     /**
      * This method is used to determine, if the chart's legend is visible or
-     * not. <b>Note: this method always returns true.</b>
+     * not. If a <i>settings</i> instance is set, this instance determines the
+     * visibility otherwise, this method returns true as default if no
+     * <i>settings</i> is set.
      *
      * @return true, if the legend should be visible, otherwise false.
      */
     protected boolean isLegendVisible() {
+        ChartSettings chartSettings = getChartSettings();
+        if (chartSettings != null) {
+            return isLegendVisible(chartSettings);
+        }
+
         return true;
     }
 
 
     /**
-     * This method is used to determine the font size of the chart's legend.
-     * <b>Note: this method always returns 12.</b>
+     * This method is used to determine the font size of the chart's legend. If
+     * a <i>settings</i> instance is set, this instance determines the font
+     * size, otherwise this method returns 12 as default if no <i>settings</i>
+     * is set or if it doesn't provide a legend font size.
      *
-     * @return 12.
+     * @return a legend font size.
      */
     protected int getLegendFontSize() {
-        return 12;
+        Integer fontSize = null;
+
+        ChartSettings chartSettings = getChartSettings();
+        if (chartSettings != null) {
+            fontSize = getLegendFontSize(chartSettings);
+        }
+
+        return fontSize != null ? fontSize : 12;
     }
 
 
@@ -324,7 +340,7 @@
             getYAxisLabel(),
             null,
             PlotOrientation.VERTICAL,
-            true,
+            isLegendVisible(),
             false,
             false);
 
@@ -705,6 +721,8 @@
             return;
         }
 
+        int fontSize = getLegendFontSize();
+
         LegendItemCollection lic = new LegendItemCollection();
         LegendItemCollection old = plot.getFixedLegendItems();
 
@@ -717,6 +735,7 @@
 
             Color color   = themeAccess.parseLineColorField();
             int lineWidth = themeAccess.parseLineWidth();
+
             lic.add(new LegendItem(fa.getLabel(), color));
 
             for (XYTextAnnotation ta: fa.getAnnotations()) {
@@ -776,13 +795,16 @@
             new float[] { 3.0f },
             0.0f);
 
+        ChartSettings      cs = getChartSettings();
+        boolean isGridVisible = cs != null ? isGridVisible(cs) : true;
+
         plot.setDomainGridlineStroke(gridStroke);
         plot.setDomainGridlinePaint(DEFAULT_GRID_COLOR);
-        plot.setDomainGridlinesVisible(true);
+        plot.setDomainGridlinesVisible(isGridVisible);
 
         plot.setRangeGridlineStroke(gridStroke);
         plot.setRangeGridlinePaint(DEFAULT_GRID_COLOR);
-        plot.setRangeGridlinesVisible(true);
+        plot.setRangeGridlinesVisible(isGridVisible);
 
         plot.setAxisOffset(new RectangleInsets(0d, 0d, 0d, 0d));
     }
@@ -1018,10 +1040,14 @@
      * @return an instance of <i>ChartSettings</i>.
      */
     public Settings getSettings() {
+        if (this.settings != null) {
+            return this.settings;
+        }
+
         ChartSettings settings = new ChartSettings();
 
-        Section chartSection  = buildChartSection();
-        Section legendSection = buildLegendSection();
+        ChartSection  chartSection  = buildChartSection();
+        LegendSection legendSection = buildLegendSection();
 
         settings.setChartSection(chartSection);
         settings.setLegendSection(legendSection);
@@ -1040,7 +1066,7 @@
      *
      * @return a new <i>ChartSection</i>.
      */
-    protected Section buildChartSection() {
+    protected ChartSection buildChartSection() {
         ChartSection chartSection = new ChartSection();
         chartSection.setTitle(getChartTitle());
         chartSection.setSubtitle(getChartSubtitle());
@@ -1054,7 +1080,7 @@
      *
      * @return a new <i>LegendSection</i>.
      */
-    protected Section buildLegendSection() {
+    protected LegendSection buildLegendSection() {
         LegendSection legendSection = new LegendSection();
         legendSection.setVisibility(isLegendVisible());
         legendSection.setFontSize(getLegendFontSize());

http://dive4elements.wald.intevation.org