view artifacts/src/main/java/org/dive4elements/river/exports/LongitudinalSectionGenerator2.java @ 7597:fca46ce8e4f5

(issue1225) Implement Magic labels. There is now a new value in the chartsettings "Suggested Label" which is hidden in the property editor. A suggested label is the label that combines the label's of all processors that wrote data to an axis. This suggested label is set as the label when the user has not overwritten the label.
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 25 Nov 2013 14:58:14 +0100
parents 81416a62fa57
children ad4a3980092f
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
 * Software engineering by Intevation GmbH
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */

package org.dive4elements.river.exports;

import org.dive4elements.river.artifacts.D4EArtifact;
import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
import org.dive4elements.river.artifacts.access.RangeAccess;
import org.dive4elements.river.jfree.Bounds;
import org.dive4elements.river.jfree.DoubleBounds;
import org.dive4elements.river.themes.ThemeDocument;

public class LongitudinalSectionGenerator2 extends DiagramGenerator
{
    public static final String I18N_CHART_SHORT_SUBTITLE =
        "chart.longitudinal.section.shortsubtitle";

    public static final String I18N_CHART_LOCATION_SUBTITLE =
        "chart.longitudinal.section.locsubtitle";

    @Override
    public String getDefaultChartSubtitle() {
        double[] dist = getRange();

        if (dist == null || dist.length != 2 ||
                Double.isNaN(dist[0]) || Double.isNaN(dist[1])) {
            Object [] args = new Object[] {getRiverName()};
            return msg(I18N_CHART_SHORT_SUBTITLE, "", args);
        }

        if (Math.abs(dist[0] - dist[1]) < 1E-5) {
            Object [] args = new Object[] {getRiverName(), dist[1]};
            return msg(I18N_CHART_LOCATION_SUBTITLE, "", args);
        }

        return super.getDefaultChartSubtitle();
    }

    /* We override doOut here to save the startkm and endkm in the
     * context. Some facets will deliver different data because of
     * that setting. It is mainly used in MINFO where it causes
     * adaptive smoothing on the data if you are zoomed out do
     * reduce the static in the curve. */
    @Override
    public void doOut(
        ArtifactAndFacet bundle,
        ThemeDocument    theme,
        boolean          visible
    ) {
        /* Aheinecke (25.09.2013): I do not understand why this has to be
         * done so difficult and if it really must be done for every
         * facet. At least it has to be done _before_ the super class
         * actually does the output and accesses the facet data.
         */
        D4EArtifact artifact = (D4EArtifact)bundle.getArtifact();

        if (getXBounds(0) != null && getDomainAxisRange() != null) {
            Bounds bounds =
                calculateZoom(getXBounds(0), getDomainAxisRange());
            context.putContextValue("startkm", bounds.getLower());
            context.putContextValue("endkm", bounds.getUpper());
        }
        else if (getXBounds(0) != null && getDomainAxisRange() == null) {
            context.putContextValue("startkm", getXBounds(0).getLower());
            context.putContextValue("endkm", getXBounds(0).getUpper());
        }
        else if (getXBounds(0) == null && getDomainAxisRange() == null) {
            RangeAccess access = new RangeAccess(artifact);
            if (access.hasFrom() && access.hasTo()) {
                context.putContextValue("startkm", access.getFrom());
                context.putContextValue("endkm", access.getTo());
            }
        }
        else if (getXBounds(0) == null && getDomainAxisRange() != null){
            RangeAccess access = new RangeAccess(artifact);
            if (access.hasFrom() && access.hasTo()) {
                Bounds b = new DoubleBounds(access.getFrom(), access.getTo());
                Bounds bounds =
                    calculateZoom(b, getDomainAxisRange());
                context.putContextValue("startkm", bounds.getLower());
                context.putContextValue("endkm", bounds.getUpper());
            }
        }
        super.doOut(bundle, theme, visible);
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org