aheinecke@7155: /* Copyright (C) 2013 by Bundesanstalt für Gewässerkunde aheinecke@7155: * Software engineering by Intevation GmbH aheinecke@7155: * aheinecke@7155: * This file is Free Software under the GNU AGPL (>=v3) aheinecke@7155: * and comes with ABSOLUTELY NO WARRANTY! Check out the aheinecke@7155: * documentation coming with Dive4Elements River for details. aheinecke@7155: */ aheinecke@7155: aheinecke@7155: package org.dive4elements.river.exports.process; aheinecke@7155: rrenkert@7892: import java.util.Map; rrenkert@7892: aheinecke@7155: import org.apache.log4j.Logger; aheinecke@7155: aheinecke@7155: import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; aheinecke@7155: import org.dive4elements.artifacts.CallContext; aheinecke@7155: import org.dive4elements.river.artifacts.model.FacetTypes; aheinecke@7155: import org.dive4elements.river.exports.DiagramGenerator; aheinecke@7155: import org.dive4elements.river.exports.StyledSeriesBuilder; aheinecke@7155: import org.dive4elements.river.jfree.StyledXYSeries; aheinecke@7155: import org.dive4elements.river.themes.ThemeDocument; aheinecke@7164: aheinecke@7162: import org.dive4elements.river.model.FlowVelocityMeasurementValue.FastFlowVelocityMeasurementValue; aheinecke@7155: import org.dive4elements.river.artifacts.model.FlowVelocityData; aheinecke@7155: aheinecke@7155: public class FlowVelocityProcessor extends DefaultProcessor { aheinecke@7155: teichmann@8202: private final static Logger log = aheinecke@7155: Logger.getLogger(FlowVelocityProcessor.class); aheinecke@7155: aheinecke@7155: public static final String I18N_AXIS_LABEL = aheinecke@7155: "chart.flow_velocity.section.yaxis.label"; aheinecke@7155: public static final String I18N_AXIS_LABEL_DEFAULT = aheinecke@7155: "Geschwindigkeit v [m/s]"; rrenkert@7892: rrenkert@7892: protected String yAxisLabel; rrenkert@7892: aheinecke@7155: @Override aheinecke@7155: public void doOut( aheinecke@7155: DiagramGenerator generator, aheinecke@7155: ArtifactAndFacet bundle, aheinecke@7155: ThemeDocument theme, aheinecke@7155: boolean visible) { aheinecke@7155: CallContext context = generator.getCallContext(); rrenkert@7892: Map metaData = bundle.getFacet().getMetaData(); tom@8856: StyledXYSeries series = new StyledXYSeries( tom@8856: bundle.getFacetDescription(), tom@8856: theme); rrenkert@7892: series.putMetaData(metaData, bundle.getArtifact(), context); rrenkert@7892: yAxisLabel = metaData.get("Y"); aheinecke@7162: String facetName = bundle.getFacetName(); aheinecke@7162: Object data = bundle.getData(context); aheinecke@7155: if (data == null) { aheinecke@7162: // Check has been here before so we keep it for security reasons aheinecke@7162: // this should never happen though. teichmann@8202: log.error("Data is null for facet: " + facetName); aheinecke@7155: return; aheinecke@7155: } aheinecke@7155: double [][] points; aheinecke@7155: aheinecke@7155: if (facetName.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL) || tom@8856: facetName.equals( tom@8856: FacetTypes.FLOW_VELOCITY_TOTALCHANNEL_FILTERED) tom@8856: ) { aheinecke@7162: FlowVelocityData fData = (FlowVelocityData) data; aheinecke@7162: points = fData.getTotalChannelPoints(); aheinecke@7155: } else if (facetName.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL) || tom@8856: facetName.equals( tom@8856: FacetTypes.FLOW_VELOCITY_MAINCHANNEL_FILTERED) tom@8856: ) { aheinecke@7162: FlowVelocityData fData = (FlowVelocityData) data; aheinecke@7162: points = fData.getMainChannelPoints(); // I hate facets! aheinecke@7162: } else if (facetName.equals(FacetTypes.FLOW_VELOCITY_MEASUREMENT)) { aheinecke@7162: FastFlowVelocityMeasurementValue fData = aheinecke@7162: (FastFlowVelocityMeasurementValue) data; aheinecke@7162: points = new double[][] {{fData.getStation()},{fData.getV()}}; aheinecke@7155: } else { teichmann@8202: log.error("Unknown facet name: " + facetName); aheinecke@7155: return; aheinecke@7155: } aheinecke@7155: StyledSeriesBuilder.addPoints(series, points, true); aheinecke@7155: generator.addAxisSeries(series, axisName, visible); aheinecke@7155: } aheinecke@7155: aheinecke@7155: @Override aheinecke@7155: public boolean canHandle(String facettype) { tom@8856: return facettype.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL_FILTERED) tom@8856: || facettype.equals(FacetTypes.FLOW_VELOCITY_MAINCHANNEL) tom@8856: || facettype.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL_FILTERED) tom@8856: || facettype.equals(FacetTypes.FLOW_VELOCITY_TOTALCHANNEL) tom@8856: || facettype.equals(FacetTypes.FLOW_VELOCITY_MEASUREMENT); aheinecke@7155: } aheinecke@7155: aheinecke@7155: @Override aheinecke@7155: public String getAxisLabel(DiagramGenerator generator) { rrenkert@7892: if (yAxisLabel != null && !yAxisLabel.isEmpty()) { gernotbelger@8853: // FIXME/UNINTENDED: yAxisLabel is probably a resolved message (side-effect of StyledXYSeries#putMetadata), gernotbelger@8853: // and cannot be resolved again. gernotbelger@8853: // An explicit (German) default label is therefore given here, probably the English version will also show German (CHECK) rrenkert@7892: return generator.msg(yAxisLabel, I18N_AXIS_LABEL_DEFAULT); rrenkert@7892: } aheinecke@7155: return generator.msg( aheinecke@7155: I18N_AXIS_LABEL, aheinecke@7155: I18N_AXIS_LABEL_DEFAULT); aheinecke@7155: } aheinecke@7155: }