# HG changeset patch # User Ingo Weinzierl # Date 1324630645 0 # Node ID 0318fa6f0844fc15ba637df96703085dab596b25 # Parent 2ae0627f956eae4673c703c1e3334b23c399ec55 Make use of first attributes specified in the ChartSettings. NOTE: work is still in progress. flys-artifacts/trunk@3535 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 2ae0627f956e -r 0318fa6f0844 flys-artifacts/ChangeLog --- 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 + + * 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 * src/main/java/de/intevation/flys/exports/ChartSettings.java, diff -r 2ae0627f956e -r 0318fa6f0844 flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.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 { diff -r 2ae0627f956e -r 0318fa6f0844 flys-artifacts/src/main/java/de/intevation/flys/exports/ATExporter.java --- 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 EmptySettings. */ + @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 : diff -r 2ae0627f956e -r 0318fa6f0844 flys-artifacts/src/main/java/de/intevation/flys/exports/AbstractExporter.java --- 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 + * Settings object. + */ + public void setSettings(Settings settings) { + // do nothing + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 2ae0627f956e -r 0318fa6f0844 flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java --- 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 settings. + * + * @param settings A ChartSettings object. + * + * @return the title provided by settings or null if no + * ChartSection is provided by settings. + * + * @throws NullPointerException if settings is null. + */ + public String getChartTitle(ChartSettings settings) { + ChartSection cs = settings.getChartSection(); + return cs != null ? cs.getTitle() : null; + } + + + /** + * Returns the chart subtitle provided by settings. + * + * @param settings A ChartSettings object. + * + * @return the subtitle provided by settings or null if no + * ChartSection is provided by settings. + * + * @throws NullPointerException if settings 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 settings, + * otherweise the default is true. + * + * @param settings A ChartSettings object. + * + * @return true, if the chart grid should be visible otherwise false. + * + * @throws NullPointerException if settings 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 settings, + * otherwise the default is true. + * + * @param settings A ChartSettings object. + * + * @return true, if the chart legend should be visible otherwise false. + * + * @throws NullPointerException if settings 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 settings or null if no + * LegendSection is provided by settings. + * + * @param settings A ChartSettings object. + * + * @return the legend font size or null. + * + * @throws NullPointerException if settings 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 EmptySettings. */ public Settings getSettings() { - return new EmptySettings(); + return settings != null ? settings : new EmptySettings(); + } + + + /** + * Returns the settings as ChartSettings. + * + * @return the settings as ChartSettings or null, if + * settings is not an instance of ChartSettings. + */ + 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 : diff -r 2ae0627f956e -r 0318fa6f0844 flys-artifacts/src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java --- 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 EmptySettings currently! + * A proxy method which calls generator.getSettings() and returns its + * return value. * - * @return an instance of EmptySettings. + * @return a Settings object provided by generator. */ + @Override public Settings getSettings() { - return new EmptySettings(); + return generator.getSettings(); + } + + + /** + * A proxy method which calls generator.setSettings(). + * + * @param settings A settings object for the generator. + */ + @Override + public void setSettings(Settings settings) { + generator.setSettings(settings); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 2ae0627f956e -r 0318fa6f0844 flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java --- 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[] { diff -r 2ae0627f956e -r 0318fa6f0844 flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java --- 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 EmptySettings. */ + @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 : diff -r 2ae0627f956e -r 0318fa6f0844 flys-artifacts/src/main/java/de/intevation/flys/exports/OutGenerator.java --- 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 Settings object for the Output + * that is produced by this OutGenerator. + * + * @param settings The Settings that might be used while + * Output 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. diff -r 2ae0627f956e -r 0318fa6f0844 flys-artifacts/src/main/java/de/intevation/flys/exports/ReportGenerator.java --- 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 + * Settings object. + */ + public void setSettings(Settings settings) { + // do nothing + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 2ae0627f956e -r 0318fa6f0844 flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java --- 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. Note: this method always returns true. + * not. If a settings instance is set, this instance determines the + * visibility otherwise, this method returns true as default if no + * settings 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. - * Note: this method always returns 12. + * 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 + * size, otherwise this method returns 12 as default if no settings + * 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 ChartSettings. */ 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 ChartSection. */ - protected Section buildChartSection() { + protected ChartSection buildChartSection() { ChartSection chartSection = new ChartSection(); chartSection.setTitle(getChartTitle()); chartSection.setSubtitle(getChartSubtitle()); @@ -1054,7 +1080,7 @@ * * @return a new LegendSection. */ - protected Section buildLegendSection() { + protected LegendSection buildLegendSection() { LegendSection legendSection = new LegendSection(); legendSection.setVisibility(isLegendVisible()); legendSection.setFontSize(getLegendFontSize());