view flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionGenerator.java @ 4255:670e98f5a441

Fixed leak while merging facets. The ThemeList that is used by OutputHelper to sort the Facets for an Output now uses a list to store the ManagedFacets. The correct order is made up by sorting the List using Collections.sort() function of the Java JDK. Therfore, the ManagedFacet class implements the Comparable interface. The return value of its compareTo(other) method depends on the value of the 'position' field.
author Ingo Weinzierl <weinzierl.ingo@googlemail.com>
date Thu, 25 Oct 2012 14:01:46 +0200
parents 1fcaeced48f2
children 9425b7c51b73
line wrap: on
line source
package de.intevation.flys.exports;

import org.apache.log4j.Logger;

import org.jfree.data.xy.XYSeries;

import org.w3c.dom.Document;

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

import de.intevation.flys.artifacts.model.FacetTypes;
import de.intevation.flys.artifacts.model.WQCKms;
import de.intevation.flys.artifacts.model.WQKms;
import de.intevation.flys.artifacts.model.WKms;

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



/**
 * An OutGenerator that generates discharge longitudinal section curves.
 *
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class DischargeLongitudinalSectionGenerator
extends      LongitudinalSectionGenerator
implements   FacetTypes
{
    private static Logger logger =
        Logger.getLogger(DischargeLongitudinalSectionGenerator.class);


    public DischargeLongitudinalSectionGenerator() {
        super();
    }


    @Override
    public void doOut(
        ArtifactAndFacet artifactFacet,
        Document         attr,
        boolean          visible
    ) {
        logger.debug("DischargeLongitudinalSectionGenerator.doOut");

        String name = artifactFacet.getFacetName();

        if (name == null) {
            return;
        }

        Facet facet = artifactFacet.getFacet();

        if (IS.WQ_KM(name)) {
            doWOut(
                (WQKms) artifactFacet.getData(context),
                artifactFacet,
                attr,
                visible);
        }
        else if (name.equals(DISCHARGE_LONGITUDINAL_Q)) {
            doQOut(
                (WQKms) artifactFacet.getData(context),
                artifactFacet,
                attr,
                visible);
        }
        else if (name.equals(DISCHARGE_LONGITUDINAL_C)) {
            doCorrectedWOut(
                (WQCKms) artifactFacet.getData(context),
                facet,
                attr,
                visible);
        }
        else if (IS.W_KM(name)) {
            doWOut(
                (WKms) artifactFacet.getData(context),
                artifactFacet,
                attr, visible);
        }
        else if (name.equals(LONGITUDINAL_ANNOTATION)) {
            doAnnotations((FLYSAnnotation) artifactFacet.getData(context),
                 artifactFacet, attr, visible);
        }
        else if (FacetTypes.IS.MANUALPOINTS(name)) {
            doPoints(artifactFacet.getData(context),
                artifactFacet,
                attr, visible, YAXIS.W.idx);
        }
        else {
            logger.warn("Unknown facet name: " + name);
        }
    }


    /**
     * Adds a new series for the corrected W curve.
     *
     * @param wqckms The object that contains the corrected W values.
     * @param theme The theme that contains styling information.
     */
    protected void doCorrectedWOut(
        WQCKms   wqckms,
        Facet    facet,
        Document theme,
        boolean  visible
    ) {
        logger.debug("DischargeLongitudinalSectionGenerator.doCorrectedWOut");

        int size = wqckms.size();

        if (size > 0) {
            XYSeries series = new StyledXYSeries(
                facet.getDescription(),
                theme);

            for (int i = 0; i < size; i++) {
                series.add(wqckms.getKm(i), wqckms.getC(i));
            }

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

        if (wqckms.guessWaterIncreasing()) {
            setInverted(true);
        }
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org