view artifacts/src/main/java/org/dive4elements/river/exports/LongitudinalSectionGenerator2.java @ 8165:cfb3a4d0c637

Added new diagramm generator for Q symmetry.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 29 Aug 2014 16:21:31 +0200
parents 43f18dc56c5a
children a83d519155ab
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();
        String parts = "";
        if (subTitleParts != null && !subTitleParts.isEmpty()) {
             for (String p : subTitleParts) {
                 parts += ", " + p;
             }
        }
        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) + parts;
        }

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

        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();
        Object ctxV = context.getContextValue("bounds_defined");
        if (ctxV != null && (Boolean)ctxV) {
            super.doOut(bundle, theme, visible);
            return;
        }
        if (getXBounds(0) != null && getDomainAxisRange() != null) {
            Bounds bounds =
                calculateZoom(getXBounds(0), getDomainAxisRange());
            context.putContextValue("startkm", bounds.getLower());
            context.putContextValue("endkm", bounds.getUpper());
            context.putContextValue("bounds_defined", true);
        }
        else if (getXBounds(0) != null && getDomainAxisRange() == null) {
            context.putContextValue("startkm", getXBounds(0).getLower());
            context.putContextValue("endkm", getXBounds(0).getUpper());
            context.putContextValue("bounds_defined", true);
        }
        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());
                context.putContextValue("bounds_defined", true);
            }
        }
        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());
                context.putContextValue("bounds_defined", true);
            }
        }
        super.doOut(bundle, theme, visible);
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org