view artifacts/src/main/java/org/dive4elements/river/artifacts/common/AbstractExportContext.java @ 9425:3f49835a00c3

Extended CrossSectionFacet so it may fetch different data from within the artifact result. Also allows to have acces to the potentially already computed artifact result via its normal computation cache.
author gernotbelger
date Fri, 17 Aug 2018 15:31:02 +0200
parents 5ce50640688c
children e60584f2a531
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.common;

import java.text.NumberFormat;

import org.dive4elements.artifacts.CallContext;
import org.dive4elements.river.artifacts.resources.Resources;
import org.dive4elements.river.utils.Formatter;

/**
 * @author Domenico Nardi Tironi
 */
public abstract class AbstractExportContext implements IExportContext {

    private NumberFormat qFormat = null;

    private NumberFormat flowDepthFormat = null;
    private NumberFormat floodDurationFormat = null;
    private NumberFormat salixScenFormat = null;
    private NumberFormat kmFormat = null;

    /** The CallContext object. */
    private final CallContext context;

    private final AbstractCalculationResults<?> results;

    public AbstractExportContext(final CallContext context, final AbstractCalculationResults<?> results) {
        this.context = context;
        this.results = results;
    }

    protected final CallContext getContext() {
        return this.context;
    }

    @Override
    public final <RESULTS extends AbstractCalculationResults<?>> RESULTS getResults() {
        @SuppressWarnings("unchecked")
        final RESULTS resultsCast = (RESULTS) this.results;
        return resultsCast;
    }

    // copy from AbstractExporter TODO merge with ExportContextPDF
    protected NumberFormat getKmFormatter() {

        if (this.kmFormat == null)
            this.kmFormat = Formatter.getWaterlevelKM(getContext());

        return this.kmFormat;
    }

    public NumberFormat getQFormatter() {
        if (this.qFormat == null)
            this.qFormat = Formatter.getWaterlevelQ(this.context);

        return this.qFormat;
    }

    public final NumberFormat getFlowDepthFormatter() {
        if (this.flowDepthFormat == null)
            this.flowDepthFormat = Formatter.getFlowDepth(this.context);

        return this.flowDepthFormat;
    }

    public final NumberFormat getFloodDurationFormatter() {

        if (this.floodDurationFormat == null)
            this.floodDurationFormat = Formatter.getIntegerFormatter(this.context);
        return this.floodDurationFormat;
    }

    public final NumberFormat getSalixScenFormatter() {
        if (this.salixScenFormat == null)
            this.salixScenFormat = Formatter.getSalixLine(this.context);

        return this.salixScenFormat;
    }

    protected String msg(final String key) {
        return Resources.getMsg(this.context.getMeta(), key, key);
    }

    public final String msg(final String key, final Object... args) {
        return Resources.getMsg(this.context.getMeta(), key, key, args);
    }

    @Override
    public final String formatRowValue(final ResultRow row, final IResultType type) {
        return row.exportValue(this.context, type);
    }
}

http://dive4elements.wald.intevation.org