Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/AbstractSInfoProcessor.java @ 8884:7a8c12706834
Work on SINFO-FlowDepth
author | gernotbelger |
---|---|
date | Tue, 13 Feb 2018 14:53:23 +0100 |
parents | |
children | cc86b0f9b3c3 |
line wrap: on
line source
/* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde * Software engineering by * Björnsen Beratende Ingenieure GmbH * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt * * This file is Free Software under the GNU AGPL (>=v3) * and comes with ABSOLUTELY NO WARRANTY! Check out the * documentation coming with Dive4Elements River for details. */ package org.dive4elements.river.artifacts.sinfo.flowdepth; import java.util.Map; import java.util.Set; import org.apache.log4j.Logger; import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; import org.dive4elements.artifacts.CallContext; import org.dive4elements.river.exports.DiagramGenerator; import org.dive4elements.river.exports.StyledSeriesBuilder; import org.dive4elements.river.exports.process.DefaultProcessor; import org.dive4elements.river.jfree.StyledXYSeries; import org.dive4elements.river.themes.ThemeDocument; /** * Abstraction for some processor implementation within S-INFO. Probably this abstraction could also be used for other * cases as well. * * @author Gernot Belger * */ abstract class AbstractSInfoProcessor extends DefaultProcessor { private final static Logger log = Logger.getLogger(AbstractSInfoProcessor.class); private String yAxisLabel; private final Set<String> handled_facet_types; private final String i18n_axis_label; public AbstractSInfoProcessor(final String i18n_axis_label, final Set<String> handled_facet_types) { this.i18n_axis_label = i18n_axis_label; this.handled_facet_types = handled_facet_types; } @Override public final void doOut(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) { final CallContext context = generator.getCallContext(); final Map<String, String> metaData = bundle.getFacet().getMetaData(); final StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme); series.putMetaData(metaData, bundle.getArtifact(), context); this.yAxisLabel = metaData.get("Y"); final String facetName = bundle.getFacetName(); final FlowDepthCalculationResult data = (FlowDepthCalculationResult) bundle.getData(context); if (data == null) { // Check has been here before so we keep it for security reasons // this should never happen though. log.error("Data is null for facet: " + facetName); return; } final double[][] points = generatePoints(data, facetName); StyledSeriesBuilder.addPoints(series, points, true); generator.addAxisSeries(series, this.axisName, visible); } /** * Override to implement, call super as last line for default case. */ protected double[][] generatePoints(@SuppressWarnings("unused") final FlowDepthCalculationResult data, final String facetName) { final String error = String.format("Unknown facet name: %s", facetName); log.error(error); throw new UnsupportedOperationException(error); } @Override public final boolean canHandle(final String facettype) { return this.handled_facet_types.contains(facettype); } @Override public final String getAxisLabel(final DiagramGenerator generator) { if (this.yAxisLabel != null && !this.yAxisLabel.isEmpty()) { // REMARK/UNINTENDED: yAxisLabel may also be a resolved message (side-effect of StyledXYSeries#putMetadata), // and cannot be resolved, so we need to give the resolved value as default // FIXME: In other implementations (i.e. FlowVelocityProcessor), an explicit (German) default label is given here, // probably the English version will also show German (CHECK) return generator.msg(this.yAxisLabel, this.yAxisLabel); } return generator.msg(this.i18n_axis_label, "MISSING"); } }