aheinecke@7153: /* Copyright (C) 2013 by Bundesanstalt für Gewässerkunde aheinecke@7153: * Software engineering by Intevation GmbH aheinecke@7153: * aheinecke@7153: * This file is Free Software under the GNU AGPL (>=v3) aheinecke@7153: * and comes with ABSOLUTELY NO WARRANTY! Check out the aheinecke@7153: * documentation coming with Dive4Elements River for details. aheinecke@7153: */ aheinecke@7153: aheinecke@7153: package org.dive4elements.river.exports.process; aheinecke@7153: aheinecke@7153: import java.util.Set; aheinecke@7153: aheinecke@7153: import org.apache.log4j.Logger; aheinecke@7153: import org.jfree.data.xy.XYSeries; aheinecke@7153: import org.dive4elements.river.artifacts.D4EArtifact; aheinecke@7153: aheinecke@7153: import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; aheinecke@7153: import org.dive4elements.artifacts.CallContext; aheinecke@7153: import org.dive4elements.river.artifacts.access.SedimentLoadAccess; aheinecke@7153: import org.dive4elements.river.artifacts.model.FacetTypes; aheinecke@7153: import org.dive4elements.river.exports.DiagramGenerator; aheinecke@7153: import org.dive4elements.river.exports.StyledSeriesBuilder; aheinecke@7153: import org.dive4elements.river.jfree.StyledXYSeries; aheinecke@7153: import org.dive4elements.river.themes.ThemeDocument; aheinecke@7153: aheinecke@7153: import org.dive4elements.river.artifacts.model.minfo.SedimentLoad; aheinecke@7153: import org.dive4elements.river.artifacts.model.minfo.SedimentLoadFraction; aheinecke@7153: aheinecke@7153: public class SedimentLoadProcessor extends DefaultProcessor { aheinecke@7153: aheinecke@7153: private final static Logger logger = aheinecke@7153: Logger.getLogger(SedimentLoadProcessor.class); aheinecke@7153: aheinecke@7153: public static final String I18N_YAXIS_LABEL_1 = aheinecke@7153: "chart.sedimentload.ls.yaxis.label.tpera"; aheinecke@7153: public static final String I18N_YAXIS_LABEL_2 = aheinecke@7153: "chart.sedimentload.ls.yaxis.label.m3pera"; aheinecke@7153: public static final String I18N_YAXIS_LABEL_DEFAULT_1 = "[t/a]"; aheinecke@7153: public static final String I18N_YAXIS_LABEL_DEFAULT_2 = "[m\u00b3/a]"; aheinecke@7153: aheinecke@7153: @Override aheinecke@7153: public void doOut( aheinecke@7153: DiagramGenerator generator, aheinecke@7153: ArtifactAndFacet bundle, aheinecke@7153: ThemeDocument theme, aheinecke@7153: boolean visible) { aheinecke@7153: CallContext context = generator.getCallContext(); aheinecke@7153: XYSeries series = new StyledXYSeries(bundle.getFacetDescription(), aheinecke@7153: theme); aheinecke@7153: Object data = bundle.getData(context); aheinecke@7153: String facetName = bundle.getFacetName(); aheinecke@7153: double [][] points; aheinecke@7153: aheinecke@7153: if (FacetTypes.IS.SEDIMENT_LOAD(facetName)) { aheinecke@7153: points = (double[][]) data; aheinecke@7153: } else if (FacetTypes.IS.SEDIMENT_LOAD_UNKNOWN(facetName)) { aheinecke@7153: SedimentLoad load = (SedimentLoad) data; aheinecke@7153: Set kms = load.getKms(); aheinecke@7153: points = new double[2][kms.size()]; aheinecke@7153: int counter = 0; aheinecke@7153: for (Double km: kms) { aheinecke@7153: SedimentLoadFraction fraction = load.getFraction(km); aheinecke@7153: points[0][counter] = km; aheinecke@7153: points[1][counter] = fraction.getUnknown(); aheinecke@7153: counter++; aheinecke@7153: } aheinecke@7153: } else { aheinecke@7153: logger.error("Unknown facet name: " + facetName); aheinecke@7153: return; aheinecke@7153: } aheinecke@7153: StyledSeriesBuilder.addPoints(series, points, true); aheinecke@7153: aheinecke@7153: generator.addAxisSeries(series, axisName, visible); aheinecke@7153: } aheinecke@7153: aheinecke@7153: @Override aheinecke@7153: public boolean canHandle(String facettype) { aheinecke@7153: return FacetTypes.IS.SEDIMENT_LOAD(facettype) || aheinecke@7153: FacetTypes.IS.SEDIMENT_LOAD_UNKNOWN(facettype); aheinecke@7153: } aheinecke@7153: aheinecke@7153: @Override aheinecke@7153: public String getAxisLabel(DiagramGenerator generator) { aheinecke@7153: SedimentLoadAccess slaccess = aheinecke@7153: new SedimentLoadAccess((D4EArtifact) generator.getMaster()); aheinecke@7153: String unit = slaccess.getUnit(); aheinecke@7153: if (unit != null && unit.equals("m3_per_a")) { aheinecke@7153: return generator.msg(I18N_YAXIS_LABEL_2, I18N_YAXIS_LABEL_DEFAULT_2); aheinecke@7153: } aheinecke@7153: else { aheinecke@7153: return generator.msg(I18N_YAXIS_LABEL_1, I18N_YAXIS_LABEL_DEFAULT_1); aheinecke@7153: } aheinecke@7153: } aheinecke@7153: }