view flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java @ 1944:21a4d2c677a1

Changed doOut signature, side effect from blackboard feature (to come). flys-artifacts/trunk@3334 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 30 Nov 2011 10:10:42 +0000
parents f07d64d5cbe1
children 65f9d707caff
line wrap: on
line source
package de.intevation.flys.exports;

import java.util.List;
import java.util.ArrayList;

import org.apache.log4j.Logger;

import org.w3c.dom.Document;

import org.jfree.chart.annotations.XYTextAnnotation;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.xy.XYSeries;

import de.intevation.artifacts.Artifact;

import de.intevation.artifactdatabase.state.ArtifactAndFacet;
import de.intevation.artifactdatabase.state.Facet;

import de.intevation.flys.artifacts.FLYSArtifact;
import de.intevation.flys.artifacts.model.FacetTypes;
import de.intevation.flys.artifacts.model.WQKms;

import de.intevation.flys.jfree.FLYSAnnotation;
import de.intevation.flys.jfree.StickyAxisAnnotation;


/**
 * An OutGenerator that generates discharge curves.
 *
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class ComputedDischargeCurveGenerator
extends      DischargeCurveGenerator
implements   FacetTypes
{
    /** The logger used in this generator. */
    private static Logger logger =
        Logger.getLogger(ComputedDischargeCurveGenerator.class);

    public static final String I18N_CHART_TITLE =
        "chart.computed.discharge.curve.title";

    public static final String I18N_CHART_SUBTITLE =
        "chart.computed.discharge.curve.subtitle";

    public static final String I18N_YAXIS_LABEL =
        "chart.computed.discharge.curve.yaxis.label";

    public static final String I18N_CHART_TITLE_DEFAULT = "Abflusskurve";
    public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]";
    public static final String I18N_MAINVALUES_Q_LABEL = "Q (Haupt- und Extremwerte)";
    public static final String I18N_MAINVALUES_W_LABEL = "W (Haupt- und Extremwerte)";


    /** Trivial Constructor. */
    public ComputedDischargeCurveGenerator () {
        super();
    }


    @Override
    protected String getChartTitle() {
        return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT);
    }


    @Override
    protected void addSubtitles(JFreeChart chart) {
        double[] dist = getRange();

        Object[] args = new Object[] {
            getRiverName(),
            dist[0]
        };

        String subtitle = msg(I18N_CHART_SUBTITLE, "", args);
        chart.addSubtitle(new TextTitle(subtitle));
    }


    @Override
    protected String getYAxisLabel() {
        return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT);
    }


    @Override
    public void doOut(
        ArtifactAndFacet artifactFacet,
        Document         attr,
        boolean          visible
    ) {
        String name = artifactFacet.getFacetName();

        logger.debug("ComputedDischargeCurveGenerator.doOut: " + name);

        if (name == null) {
            logger.warn("Broken facet in computed discharge out generation.");
            return;
        }

        Facet facet = artifactFacet.getFacet();

        if (name.equals(COMPUTED_DISCHARGE_Q)) {
            doQOut((WQKms) artifactFacet.getData(context), facet, attr, visible);
        }
        else if (name.equals(STATIC_WQ)) {
            doWQOut(artifactFacet.getData(context), facet, attr, visible);
        }
        else if (name.equals(STATIC_WQ_ANNOTATIONS)) {
            doWQAnnotations(artifactFacet.getData(context), facet, attr, visible);
        }
        else if (name.equals(COMPUTED_DISCHARGE_MAINVALUES_Q)
                || name.equals(MAINVALUES_Q)
                || name.equals(COMPUTED_DISCHARGE_MAINVALUES_W)
                || name.equals(MAINVALUES_W)
        ) {
            doAnnotations((FLYSAnnotation)
                artifactFacet.getData(context), facet, attr, visible);
        }
        else if (name.equals(STATIC_WKMS_INTERPOL)) {
            doWAnnotations(artifactFacet.getData(context), facet, attr, visible);
        }
        else {
            logger.warn("Unknown facet type for computed discharge: " + name);
            return;
        }
    }

    /**
     * Add WQ Data to plot.
     */
    protected void doWQOut(
        Object   wqkms,
        Facet    facet,
        Document theme,
        boolean  visible
    ) {
        double [][] data = (double [][]) wqkms;

        XYSeries series = new StyledXYSeries(facet.getDescription(), theme);
        StyledSeriesBuilder.addPoints(series, data);

        addAxisSeries(series, YAXIS.W.idx, visible);
    }


    /**
     * Add Q-Series to plot.
     * @param wqkms actual data
     * @param theme theme to use.
     */
    protected void doQOut(
        WQKms    wqkms,
        Facet    facet,
        Document theme,
        boolean  visible
    ) {
        XYSeries series = new StyledXYSeries(facet.getDescription(), theme);
        StyledSeriesBuilder.addPointsQW(series, wqkms);

        addAxisSeries(series, YAXIS.W.idx, visible);
    }


    /**
     * Add WQ-Annotations to plot.
     * @param wqkms actual data
     * @param theme theme to use.
     */
    protected void doWQAnnotations(
        Object   wqkms,
        Facet    facet,
        Document theme,
        boolean  visible
    ) {
        List<XYTextAnnotation> xy = new ArrayList<XYTextAnnotation>();
        double [][] data = (double [][]) wqkms;
        for (int i = 0; i< data[0].length; i++) {
            xy.add(new StickyAxisAnnotation(facet.getDescription(),
                (float) data[0][i], StickyAxisAnnotation.SimpleAxis.X_AXIS));
            xy.add(new StickyAxisAnnotation(facet.getDescription(),
                (float) data[1][i], StickyAxisAnnotation.SimpleAxis.Y_AXIS));
        }

        doAnnotations(new FLYSAnnotation(facet.getDescription(), xy),
            facet, theme, visible);
    }


    /**
     * Add W-Annotations to plot.
     * @param wqkms actual data
     * @param theme theme to use.
     */
    protected void doWAnnotations(
        Object   wqkms,
        Facet    facet,
        Document theme,
        boolean  visible
    ) {
        List<XYTextAnnotation> xy = new ArrayList<XYTextAnnotation>();
        double [][] data = (double [][]) wqkms;
        for (int i = 0; i< data[0].length; i++) {
            xy.add(new StickyAxisAnnotation(facet.getDescription(),
                (float) data[1][i], StickyAxisAnnotation.SimpleAxis.Y_AXIS));
        }

        doAnnotations(new FLYSAnnotation(facet.getDescription(), xy),
            facet, theme, visible);
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org