view flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FlowVelocityState.java @ 4641:f3325079dacc

Improve the up and down arrows in the theme navigation panel Don't stretch the arrow icons and fit to their actual size. Also put the up buttons on the left and the down buttons on the right.
author Björn Ricks <bjoern.ricks@intevation.de>
date Tue, 04 Dec 2012 16:16:43 +0100
parents bb267a0aa8c2
children d0b9b77fff9f
line wrap: on
line source
package de.intevation.flys.artifacts.states;

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

import org.apache.log4j.Logger;

import de.intevation.artifactdatabase.state.Facet;

import de.intevation.artifacts.CallContext;

import de.intevation.flys.artifacts.FLYSArtifact;
import de.intevation.flys.artifacts.access.FlowVelocityAccess;
import de.intevation.flys.artifacts.model.CalculationResult;
import de.intevation.flys.artifacts.model.DataFacet;
import de.intevation.flys.artifacts.model.FacetTypes;
import de.intevation.flys.artifacts.model.FlowVelocityCalculation;
import de.intevation.flys.artifacts.model.FlowVelocityData;
import de.intevation.flys.artifacts.model.FlowVelocityFacet;
import de.intevation.flys.artifacts.resources.Resources;


/* State in which flow velocities can/will be calculated. */
public class FlowVelocityState extends DefaultState implements FacetTypes {

    private static Logger logger = Logger.getLogger(FlowVelocityState.class);

    public static final String I18N_MAINCHANNEL_FACET =
        "facet.flow_velocity.mainchannel";

    public static final String I18N_TOTALCHANNEL_FACET =
        "facet.flow_velocity.totalchannel";

    public static final String I18N_TAU_FACET =
        "facet.flow_velocity.tauchannel";

    public static final String I18N_DISCHARGE_FACET =
        "facet.flow_velocity.discharge";


    @Override
    public Object computeAdvance(
        FLYSArtifact artifact,
        String       hash,
        CallContext  context,
        List<Facet>  facets,
        Object       old
    ) {
        logger.debug("FlowVelocityState.computeAdvance");

        List<Facet> newFacets = new ArrayList<Facet>();

        FlowVelocityAccess access = new FlowVelocityAccess(artifact);

        CalculationResult res = old instanceof CalculationResult
            ? (CalculationResult) old
            : new FlowVelocityCalculation().calculate(access);

        if (facets == null || res == null) {
            return res;
        }

        FlowVelocityData[] data = (FlowVelocityData[]) res.getData();

        logger.debug("Calculated " + data.length + " FlowVelocityData objects");

        String id  = getID();
        int    idx = 0;

        for (FlowVelocityData d: data) {
            if (d.getType().equals("main")) {
                newFacets.add(new FlowVelocityFacet(
                    idx,
                    FLOW_VELOCITY_MAINCHANNEL,
                    buildMainChannelName(artifact, context, d),
                    ComputeType.ADVANCE,
                    id,
                    hash
                ));

                newFacets.add(new FlowVelocityFacet(
                    idx,
                    FLOW_VELOCITY_TAU,
                    buildTauName(artifact, context, d),
                    ComputeType.ADVANCE,
                    id,
                    hash
                ));
            }
            else if (d.getType().equals("total")) {
                newFacets.add(new FlowVelocityFacet(
                    idx,
                    FLOW_VELOCITY_TOTALCHANNEL,
                    buildTotalChannelName(artifact, context, d),
                    ComputeType.ADVANCE,
                    id,
                    hash
                ));
            }
            else if(d.getType().equals("main_total")) {
                 newFacets.add(new FlowVelocityFacet(
                    idx,
                    FLOW_VELOCITY_MAINCHANNEL,
                    buildMainChannelName(artifact, context, d),
                    ComputeType.ADVANCE,
                    id,
                    hash
                ));
                newFacets.add(new FlowVelocityFacet(
                    idx,
                    FLOW_VELOCITY_TAU,
                    buildTauName(artifact, context, d),
                    ComputeType.ADVANCE,
                    id,
                    hash
                ));
                newFacets.add(new FlowVelocityFacet(
                    idx,
                    FLOW_VELOCITY_TOTALCHANNEL,
                    buildTotalChannelName(artifact, context, d),
                    ComputeType.ADVANCE,
                    id,
                    hash
                ));
            }

            newFacets.add(new FlowVelocityFacet(
                idx,
                FLOW_VELOCITY_DISCHARGE,
                buildDischargeName(artifact, context, d),
                ComputeType.ADVANCE,
                id,
                hash
            ));

            idx++;
        }

        Facet csv = new DataFacet(
            CSV, "CSV data", ComputeType.ADVANCE, hash, id);

        // TODO ADD PDF FACET

        newFacets.add(csv);

        logger.debug("Created " + newFacets.size() + " new Facets.");

        facets.addAll(newFacets);

        return res;
    }


    protected String buildFacetName(
        FLYSArtifact     flys,
        CallContext      cc,
        FlowVelocityData data,
        String           resourceId
    ) {
        Object[] args = new Object[] {
            data.getZone()
        };

        return Resources.getMsg(
            cc.getMeta(),
            resourceId,
            resourceId,
            args);
    }


    protected String buildMainChannelName(
        FLYSArtifact     flys,
        CallContext      cc,
        FlowVelocityData data
    ) {
        return buildFacetName(flys, cc, data, I18N_MAINCHANNEL_FACET);
    }


    protected String buildTotalChannelName(
        FLYSArtifact     flys,
        CallContext      cc,
        FlowVelocityData data
    ) {
        return buildFacetName(flys, cc, data, I18N_TOTALCHANNEL_FACET);
    }


    protected String buildDischargeName(
        FLYSArtifact     flys,
        CallContext      cc,
        FlowVelocityData data
    ) {
        return buildFacetName(flys, cc, data, I18N_DISCHARGE_FACET);
    }

    protected String buildTauName(
        FLYSArtifact     flys,
        CallContext      cc,
        FlowVelocityData data
    ) {
        return buildFacetName(flys, cc, data, I18N_TAU_FACET);
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org