view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractSInfoProcessor.java @ 8916:5d5d0051723f

Working on outputmodes of tkh calculation
author gernotbelger
date Wed, 28 Feb 2018 18:55:39 +0100
parents artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/AbstractSInfoProcessor.java@cc86b0f9b3c3
children 5294114b1df4
line wrap: on
line source
/* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
 * Software engineering by
 *  Björnsen Beratende Ingenieure GmbH
 *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
 *
 * 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.artifacts.sinfo.common;

import java.util.Set;

import org.apache.log4j.Logger;
import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
import org.dive4elements.river.exports.DiagramGenerator;
import org.dive4elements.river.exports.process.DefaultProcessor;
import org.dive4elements.river.themes.ThemeDocument;

/**
 * Abstraction for some processor implementation within S-INFO. Probably this abstraction could also be used for other
 * cases as well.
 *
 * @author Gernot Belger
 *
 */
public abstract class AbstractSInfoProcessor extends DefaultProcessor {

    private final static Logger log = Logger.getLogger(AbstractSInfoProcessor.class);

    private String yAxisLabel;

    private final Set<String> handled_facet_types;

    private final String i18n_axis_label;

    public AbstractSInfoProcessor(final String i18n_axis_label, final Set<String> handled_facet_types) {
        this.i18n_axis_label = i18n_axis_label;
        this.handled_facet_types = handled_facet_types;
    }

    @Override
    public final void doOut(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) {
        try {
            this.yAxisLabel = generateSeries(generator, bundle, theme, visible);
        }
        catch (final Exception e) {
            log.error(e.getMessage(), e);
        }
    }

    /**
     * @return The axis label
     */
    protected abstract String generateSeries(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible);

    @Override
    public final boolean canHandle(final String facettype) {
        return this.handled_facet_types.contains(facettype);
    }

    @Override
    public final String getAxisLabel(final DiagramGenerator generator) {
        if (this.yAxisLabel != null && !this.yAxisLabel.isEmpty()) {
            // REMARK/UNINTENDED: yAxisLabel may also be a resolved message (side-effect of StyledXYSeries#putMetadata),
            // and cannot be resolved, so we need to give the resolved value as default
            // FIXME: In other implementations (i.e. FlowVelocityProcessor), an explicit (German) default label is given here,
            // probably the English version will also show German (CHECK)
            return generator.msg(this.yAxisLabel, this.yAxisLabel);
        }
        return generator.msg(this.i18n_axis_label, "MISSING");
    }
}

http://dive4elements.wald.intevation.org