aheinecke@7105: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde aheinecke@7105: * Software engineering by Intevation GmbH aheinecke@7105: * aheinecke@7105: * This file is Free Software under the GNU AGPL (>=v3) aheinecke@7105: * and comes with ABSOLUTELY NO WARRANTY! Check out the aheinecke@7105: * documentation coming with Dive4Elements River for details. aheinecke@7105: */ aheinecke@7105: aheinecke@7105: package org.dive4elements.river.exports; aheinecke@7105: aheinecke@7157: import org.dive4elements.river.artifacts.D4EArtifact; aheinecke@7157: import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; aheinecke@7157: import org.dive4elements.river.artifacts.access.RangeAccess; aheinecke@7157: import org.dive4elements.river.jfree.Bounds; aheinecke@7157: import org.dive4elements.river.jfree.DoubleBounds; aheinecke@7157: import org.dive4elements.river.themes.ThemeDocument; aheinecke@7157: aheinecke@7105: public class LongitudinalSectionGenerator2 extends DiagramGenerator aheinecke@7105: { aheinecke@7105: public static final String I18N_CHART_SHORT_SUBTITLE = aheinecke@7105: "chart.longitudinal.section.shortsubtitle"; aheinecke@7105: aheinecke@7105: public static final String I18N_CHART_LOCATION_SUBTITLE = aheinecke@7105: "chart.longitudinal.section.locsubtitle"; aheinecke@7105: aheinecke@7105: @Override aheinecke@7105: public String getDefaultChartSubtitle() { aheinecke@7105: double[] dist = getRange(); aheinecke@7105: aheinecke@7105: if (dist == null || dist.length != 2 || aheinecke@7105: Double.isNaN(dist[0]) || Double.isNaN(dist[1])) { teichmann@7118: Object [] args = new Object[] {getRiverName()}; aheinecke@7105: return msg(I18N_CHART_SHORT_SUBTITLE, "", args); teichmann@7118: } teichmann@7118: teichmann@7118: if (Math.abs(dist[0] - dist[1]) < 1E-5) { teichmann@7118: Object [] args = new Object[] {getRiverName(), dist[1]}; aheinecke@7105: return msg(I18N_CHART_LOCATION_SUBTITLE, "", args); aheinecke@7105: } teichmann@7118: aheinecke@7105: return super.getDefaultChartSubtitle(); aheinecke@7105: } aheinecke@7157: aheinecke@7157: /* We override doOut here to save the startkm and endkm in the aheinecke@7157: * context. Some facets will deliver different data because of aheinecke@7157: * that setting. It is mainly used in MINFO where it causes aheinecke@7157: * adaptive smoothing on the data if you are zoomed out do aheinecke@7157: * reduce the static in the curve. */ aheinecke@7157: @Override aheinecke@7157: public void doOut( aheinecke@7157: ArtifactAndFacet bundle, aheinecke@7157: ThemeDocument theme, aheinecke@7157: boolean visible aheinecke@7157: ) { aheinecke@7157: /* Aheinecke (25.09.2013): I do not understand why this has to be aheinecke@7157: * done so difficult and if it really must be done for every aheinecke@7157: * facet. At least it has to be done _before_ the super class aheinecke@7157: * actually does the output and accesses the facet data. aheinecke@7157: */ aheinecke@7157: D4EArtifact artifact = (D4EArtifact)bundle.getArtifact(); aheinecke@7157: aheinecke@7157: if (getXBounds(0) != null && getDomainAxisRange() != null) { aheinecke@7157: Bounds bounds = aheinecke@7157: calculateZoom(getXBounds(0), getDomainAxisRange()); aheinecke@7157: context.putContextValue("startkm", bounds.getLower()); aheinecke@7157: context.putContextValue("endkm", bounds.getUpper()); aheinecke@7157: } aheinecke@7157: else if (getXBounds(0) != null && getDomainAxisRange() == null) { aheinecke@7157: context.putContextValue("startkm", getXBounds(0).getLower()); aheinecke@7157: context.putContextValue("endkm", getXBounds(0).getUpper()); aheinecke@7157: } aheinecke@7157: else if (getXBounds(0) == null && getDomainAxisRange() == null) { aheinecke@7157: RangeAccess access = new RangeAccess(artifact); aheinecke@7168: if (access.hasFrom() && access.hasTo()) { aheinecke@7168: context.putContextValue("startkm", access.getFrom()); aheinecke@7168: context.putContextValue("endkm", access.getTo()); aheinecke@7168: } aheinecke@7157: } aheinecke@7157: else if (getXBounds(0) == null && getDomainAxisRange() != null){ aheinecke@7157: RangeAccess access = new RangeAccess(artifact); aheinecke@7168: if (access.hasFrom() && access.hasTo()) { aheinecke@7168: Bounds b = new DoubleBounds(access.getFrom(), access.getTo()); aheinecke@7168: Bounds bounds = aheinecke@7168: calculateZoom(b, getDomainAxisRange()); aheinecke@7168: context.putContextValue("startkm", bounds.getLower()); aheinecke@7168: context.putContextValue("endkm", bounds.getUpper()); aheinecke@7168: } aheinecke@7157: } aheinecke@7157: super.doOut(bundle, theme, visible); aheinecke@7157: } aheinecke@7105: } aheinecke@7105: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :