teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5994: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.exports; felix@1151: felix@6596: import org.apache.log4j.Logger; felix@6596: felix@6596: import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; felix@6596: import org.dive4elements.artifactdatabase.state.Facet; felix@6596: teichmann@5831: import org.dive4elements.river.artifacts.model.FacetTypes; teichmann@5831: import org.dive4elements.river.artifacts.model.WKms; felix@1151: felix@6597: import org.dive4elements.river.exports.process.BedDiffYearProcessor; felix@6597: import org.dive4elements.river.exports.process.BedDiffHeightYearProcessor; felix@6597: import org.dive4elements.river.exports.process.BedheightProcessor; felix@6597: import org.dive4elements.river.exports.process.Processor; teichmann@6905: import org.dive4elements.river.themes.ThemeDocument; felix@6597: christian@3409: import org.jfree.chart.JFreeChart; christian@3409: import org.jfree.chart.plot.XYPlot; christian@3409: felix@1151: felix@1151: /** felix@1151: * An OutGenerator that generates w differences curves. felix@1151: */ felix@1151: public class WDifferencesCurveGenerator felix@1151: extends LongitudinalSectionGenerator felix@1151: implements FacetTypes felix@1151: { felix@6596: /** The logger that is used in this generator. */ felix@6596: private static Logger logger = Logger.getLogger(WDifferencesCurveGenerator.class); felix@6596: felix@1953: public enum YAXIS { felix@1953: W(0), felix@1953: D(1), felix@1933: Q(2); felix@1933: protected int idx; felix@1933: private YAXIS(int c) { felix@1933: idx = c; felix@1933: } felix@1933: } felix@1933: felix@1701: /** Key for internationalized title of WDiff charts. */ felix@1701: public final static String I18N_WDIFF_TITLE = "chart.w_differences.title"; felix@1701: felix@1701: /** Default for internationalized title (when no translation found). */ felix@1701: public final static String I18N_WDIFF_TITLE_DEFAULT = "Differences"; felix@1701: felix@1701: public final static String I18N_WDIFF_SUBTITLE = felix@1701: "chart.w_differences.subtitle"; felix@1701: felix@1151: ingo@2000: @Override ingo@2000: protected YAxisWalker getYAxisWalker() { ingo@2000: return new YAxisWalker() { ingo@2000: @Override ingo@2000: public int length() { ingo@2000: return YAXIS.values().length; ingo@2000: } ingo@2000: ingo@2000: @Override ingo@2000: public String getId(int idx) { ingo@2000: YAXIS[] yaxes = YAXIS.values(); ingo@2000: return yaxes[idx].toString(); ingo@2000: } ingo@2000: }; ingo@2000: } ingo@2000: ingo@2000: felix@1700: /** felix@1700: * Get internationalized title for chart. felix@1755: * @return internationalized Chart title. felix@1700: */ felix@1755: @Override ingo@2048: public String getDefaultChartTitle() { felix@1701: return msg(I18N_WDIFF_TITLE, I18N_WDIFF_TITLE_DEFAULT); felix@1700: } felix@1151: felix@1151: ingo@1989: @Override ingo@2048: protected String getDefaultChartSubtitle() { ingo@1989: return getRiverName(); ingo@1989: } ingo@1989: ingo@1989: felix@1151: /** felix@1700: * Gets key to look up internationalized String for the charts subtitle. felix@1700: * @return key to look up translated subtitle. felix@1700: */ felix@1700: @Override felix@1700: protected String getChartSubtitleKey() { felix@1701: return I18N_WDIFF_SUBTITLE; felix@1700: } felix@1700: felix@1700: felix@6597: /** Handle additional facets (beddifferences). */ felix@6597: @Override teichmann@6905: public void doOut(ArtifactAndFacet bundle, ThemeDocument attr, boolean visible) { felix@6597: super.doOut(bundle, attr, visible); felix@6597: felix@6597: String name = bundle.getFacetName(); felix@6597: logger.debug("doOut: " + name); felix@6597: felix@6597: if (name == null) { felix@6597: logger.error("No facet name for doOut(). No output generated!"); felix@6597: return; felix@6597: } felix@6597: felix@6597: Facet facet = bundle.getFacet(); felix@6597: felix@6597: if (facet == null) { felix@6597: return; felix@6597: } felix@6597: felix@6597: Processor bedp = new BedheightProcessor(); felix@6597: Processor bdyProcessor = new BedDiffYearProcessor(); felix@6597: Processor bdhyProcessor = new BedDiffHeightYearProcessor(); felix@6597: felix@6597: if (bedp.canHandle(name)) { felix@6597: bedp.doOut(this, bundle, attr, visible, YAXIS.W.idx); felix@6597: } felix@6597: else if (bdyProcessor.canHandle(name)) { felix@6597: bdyProcessor.doOut(this, bundle, attr, visible, YAXIS.W.idx); felix@6597: } felix@6597: else if (bdhyProcessor.canHandle(name)) { felix@6597: bdhyProcessor.doOut(this, bundle, attr, visible, YAXIS.W.idx); felix@6597: } felix@6597: else { felix@6597: logger.warn("WDifferencesCurveGenerator.doOut: unknown facet type " + name); felix@6597: } felix@6597: } felix@6597: felix@6597: felix@1700: /** felix@6597: * Sets the zero base line visible. felix@1170: */ felix@1170: @Override felix@1170: public JFreeChart generateChart() { felix@1170: JFreeChart chart = super.generateChart(); felix@1170: if (chart != null && chart.getPlot() != null) { felix@1170: XYPlot plot = (XYPlot) chart.getPlot(); felix@1170: plot.setRangeZeroBaselineVisible(true); felix@1170: } felix@1170: return chart; felix@1170: } felix@1170: felix@1943: felix@1170: /** felix@1151: * Get name of series (displayed in legend). felix@1151: * @return name of the series. felix@1151: */ felix@1151: protected String getSeriesName(WKms wqkms, String mode) { felix@1151: String name = wqkms.getName(); felix@1151: String prefix = (name != null && name.indexOf(mode) >= 0) felix@1151: ? null felix@1151: : mode; felix@1151: felix@1151: return (prefix != null && prefix.length() > 0) felix@1151: ? prefix + "(" + name +")" felix@1151: : name; felix@1151: } felix@1151: } felix@1151: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :