8884
|
1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
|
2 * Software engineering by |
|
3 * Björnsen Beratende Ingenieure GmbH |
|
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt |
|
5 * |
|
6 * This file is Free Software under the GNU AGPL (>=v3) |
|
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
|
8 * documentation coming with Dive4Elements River for details. |
|
9 */ |
|
10 |
|
11 package org.dive4elements.river.artifacts.sinfo.flowdepth; |
|
12 |
|
13 import java.util.Map; |
|
14 import java.util.Set; |
|
15 |
|
16 import org.apache.log4j.Logger; |
|
17 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; |
|
18 import org.dive4elements.artifacts.CallContext; |
|
19 import org.dive4elements.river.exports.DiagramGenerator; |
|
20 import org.dive4elements.river.exports.StyledSeriesBuilder; |
|
21 import org.dive4elements.river.exports.process.DefaultProcessor; |
|
22 import org.dive4elements.river.jfree.StyledXYSeries; |
|
23 import org.dive4elements.river.themes.ThemeDocument; |
|
24 |
|
25 /** |
|
26 * Abstraction for some processor implementation within S-INFO. Probably this abstraction could also be used for other |
|
27 * cases as well. |
|
28 * |
|
29 * @author Gernot Belger |
|
30 * |
|
31 */ |
|
32 abstract class AbstractSInfoProcessor extends DefaultProcessor { |
|
33 |
|
34 private final static Logger log = Logger.getLogger(AbstractSInfoProcessor.class); |
|
35 |
|
36 private String yAxisLabel; |
|
37 |
|
38 private final Set<String> handled_facet_types; |
|
39 |
|
40 private final String i18n_axis_label; |
|
41 |
|
42 public AbstractSInfoProcessor(final String i18n_axis_label, final Set<String> handled_facet_types) { |
|
43 this.i18n_axis_label = i18n_axis_label; |
|
44 this.handled_facet_types = handled_facet_types; |
|
45 } |
|
46 |
|
47 @Override |
|
48 public final void doOut(final DiagramGenerator generator, final ArtifactAndFacet bundle, final ThemeDocument theme, final boolean visible) { |
|
49 |
|
50 final CallContext context = generator.getCallContext(); |
|
51 final Map<String, String> metaData = bundle.getFacet().getMetaData(); |
|
52 |
|
53 final StyledXYSeries series = new StyledXYSeries(bundle.getFacetDescription(), theme); |
|
54 series.putMetaData(metaData, bundle.getArtifact(), context); |
|
55 |
|
56 this.yAxisLabel = metaData.get("Y"); |
|
57 |
|
58 final String facetName = bundle.getFacetName(); |
|
59 final FlowDepthCalculationResult data = (FlowDepthCalculationResult) bundle.getData(context); |
|
60 if (data == null) { |
|
61 // Check has been here before so we keep it for security reasons |
|
62 // this should never happen though. |
|
63 log.error("Data is null for facet: " + facetName); |
|
64 return; |
|
65 } |
|
66 |
|
67 final double[][] points = generatePoints(data, facetName); |
|
68 |
|
69 StyledSeriesBuilder.addPoints(series, points, true); |
|
70 generator.addAxisSeries(series, this.axisName, visible); |
|
71 } |
|
72 |
|
73 /** |
|
74 * Override to implement, call super as last line for default case. |
|
75 */ |
|
76 protected double[][] generatePoints(@SuppressWarnings("unused") final FlowDepthCalculationResult data, final String facetName) { |
|
77 final String error = String.format("Unknown facet name: %s", facetName); |
|
78 log.error(error); |
|
79 throw new UnsupportedOperationException(error); |
|
80 } |
|
81 |
|
82 @Override |
|
83 public final boolean canHandle(final String facettype) { |
|
84 return this.handled_facet_types.contains(facettype); |
|
85 } |
|
86 |
|
87 @Override |
|
88 public final String getAxisLabel(final DiagramGenerator generator) { |
|
89 if (this.yAxisLabel != null && !this.yAxisLabel.isEmpty()) { |
|
90 // REMARK/UNINTENDED: yAxisLabel may also be a resolved message (side-effect of StyledXYSeries#putMetadata), |
|
91 // and cannot be resolved, so we need to give the resolved value as default |
|
92 // FIXME: In other implementations (i.e. FlowVelocityProcessor), an explicit (German) default label is given here, |
|
93 // probably the English version will also show German (CHECK) |
|
94 return generator.msg(this.yAxisLabel, this.yAxisLabel); |
|
95 } |
|
96 return generator.msg(this.i18n_axis_label, "MISSING"); |
|
97 } |
|
98 } |