Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/process/SedimentLoadProcessor.java @ 7153:fdf2d31b8955
Add SedimentLoadProcessor
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Wed, 25 Sep 2013 17:40:43 +0200 |
parents | |
children | e7690ed60b4c |
comparison
equal
deleted
inserted
replaced
7152:8c169743f4d0 | 7153:fdf2d31b8955 |
---|---|
1 /* Copyright (C) 2013 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 | |
9 package org.dive4elements.river.exports.process; | |
10 | |
11 import java.util.List; | |
12 import java.util.Set; | |
13 | |
14 import org.apache.log4j.Logger; | |
15 import org.jfree.data.xy.XYSeries; | |
16 import org.dive4elements.river.artifacts.D4EArtifact; | |
17 | |
18 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; | |
19 import org.dive4elements.artifacts.CallContext; | |
20 import org.dive4elements.river.artifacts.access.SedimentLoadAccess; | |
21 import org.dive4elements.river.artifacts.model.FacetTypes; | |
22 import org.dive4elements.river.exports.DiagramGenerator; | |
23 import org.dive4elements.river.exports.StyledSeriesBuilder; | |
24 import org.dive4elements.river.jfree.StyledXYSeries; | |
25 import org.dive4elements.river.themes.ThemeDocument; | |
26 | |
27 import org.dive4elements.river.artifacts.model.minfo.SedimentLoad; | |
28 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadFraction; | |
29 | |
30 public class SedimentLoadProcessor extends DefaultProcessor { | |
31 | |
32 private final static Logger logger = | |
33 Logger.getLogger(SedimentLoadProcessor.class); | |
34 | |
35 public static final String I18N_YAXIS_LABEL_1 = | |
36 "chart.sedimentload.ls.yaxis.label.tpera"; | |
37 public static final String I18N_YAXIS_LABEL_2 = | |
38 "chart.sedimentload.ls.yaxis.label.m3pera"; | |
39 public static final String I18N_YAXIS_LABEL_DEFAULT_1 = "[t/a]"; | |
40 public static final String I18N_YAXIS_LABEL_DEFAULT_2 = "[m\u00b3/a]"; | |
41 | |
42 @Override | |
43 public void doOut( | |
44 DiagramGenerator generator, | |
45 ArtifactAndFacet bundle, | |
46 ThemeDocument theme, | |
47 boolean visible) { | |
48 CallContext context = generator.getCallContext(); | |
49 XYSeries series = new StyledXYSeries(bundle.getFacetDescription(), | |
50 theme); | |
51 Object data = bundle.getData(context); | |
52 String facetName = bundle.getFacetName(); | |
53 double [][] points; | |
54 | |
55 if (FacetTypes.IS.SEDIMENT_LOAD(facetName)) { | |
56 points = (double[][]) data; | |
57 } else if (FacetTypes.IS.SEDIMENT_LOAD_UNKNOWN(facetName)) { | |
58 SedimentLoad load = (SedimentLoad) data; | |
59 Set<Double> kms = load.getKms(); | |
60 points = new double[2][kms.size()]; | |
61 int counter = 0; | |
62 for (Double km: kms) { | |
63 SedimentLoadFraction fraction = load.getFraction(km); | |
64 points[0][counter] = km; | |
65 points[1][counter] = fraction.getUnknown(); | |
66 counter++; | |
67 } | |
68 } else { | |
69 logger.error("Unknown facet name: " + facetName); | |
70 return; | |
71 } | |
72 StyledSeriesBuilder.addPoints(series, points, true); | |
73 | |
74 generator.addAxisSeries(series, axisName, visible); | |
75 } | |
76 | |
77 @Override | |
78 public boolean canHandle(String facettype) { | |
79 return FacetTypes.IS.SEDIMENT_LOAD(facettype) || | |
80 FacetTypes.IS.SEDIMENT_LOAD_UNKNOWN(facettype); | |
81 } | |
82 | |
83 @Override | |
84 public String getAxisLabel(DiagramGenerator generator) { | |
85 SedimentLoadAccess slaccess = | |
86 new SedimentLoadAccess((D4EArtifact) generator.getMaster()); | |
87 String unit = slaccess.getUnit(); | |
88 if (unit != null && unit.equals("m3_per_a")) { | |
89 return generator.msg(I18N_YAXIS_LABEL_2, I18N_YAXIS_LABEL_DEFAULT_2); | |
90 } | |
91 else { | |
92 return generator.msg(I18N_YAXIS_LABEL_1, I18N_YAXIS_LABEL_DEFAULT_1); | |
93 } | |
94 } | |
95 } | |
96 | |
97 | |
98 |