Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceYearGenerator.java @ 5831:bd047b71ab37
Repaired internal references
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:06:39 +0200 |
parents | flys-artifacts/src/main/java/de/intevation/flys/exports/minfo/BedDifferenceYearGenerator.java@a6dc4c232da2 |
children |
comparison
equal
deleted
inserted
replaced
5830:160f53ee0870 | 5831:bd047b71ab37 |
---|---|
1 package org.dive4elements.river.exports.minfo; | |
2 | |
3 import org.apache.log4j.Logger; | |
4 import org.jfree.data.xy.XYSeries; | |
5 import org.w3c.dom.Document; | |
6 | |
7 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; | |
8 import org.dive4elements.artifactdatabase.state.Facet; | |
9 import org.dive4elements.river.artifacts.model.FacetTypes; | |
10 import org.dive4elements.river.artifacts.model.WKms; | |
11 import org.dive4elements.river.artifacts.model.minfo.BedDiffYearResult; | |
12 import org.dive4elements.river.artifacts.model.minfo.BedDifferencesResult; | |
13 import org.dive4elements.river.artifacts.model.minfo.MorphologicWidth; | |
14 import org.dive4elements.river.exports.StyledSeriesBuilder; | |
15 import org.dive4elements.river.exports.fixings.FixChartGenerator; | |
16 import org.dive4elements.river.exports.process.KMIndexProcessor; | |
17 import org.dive4elements.river.exports.process.Processor; | |
18 import org.dive4elements.river.exports.process.WOutProcessor; | |
19 import org.dive4elements.river.jfree.Bounds; | |
20 import org.dive4elements.river.jfree.DoubleBounds; | |
21 import org.dive4elements.river.jfree.FLYSAnnotation; | |
22 import org.dive4elements.river.jfree.StyledXYSeries; | |
23 import org.dive4elements.river.utils.DataUtil; | |
24 | |
25 | |
26 public class BedDifferenceYearGenerator | |
27 extends FixChartGenerator | |
28 implements FacetTypes | |
29 { | |
30 public enum YAXIS { | |
31 D(0), M(1), H(2), dW(3), W(4); | |
32 | |
33 protected int idx; | |
34 | |
35 private YAXIS(int c) { | |
36 idx = c; | |
37 } | |
38 } | |
39 | |
40 /** The logger that is used in this generator. */ | |
41 private static Logger logger = Logger.getLogger(BedDifferenceYearGenerator.class); | |
42 | |
43 public static final String I18N_CHART_TITLE = "chart.beddifference.year.title"; | |
44 public static final String I18N_XAXIS_LABEL = "chart.beddifference.xaxis.label"; | |
45 public static final String I18N_YAXIS_LABEL = "chart.beddifference.yaxis.label.diff"; | |
46 public static final String I18N_SECOND_YAXIS_LABEL = "chart.beddifference.yaxis.label.morph"; | |
47 public static final String I18N_THIRD_YAXIS_LABEL = "chart.beddifference.yaxis.label.heights"; | |
48 | |
49 public static final String I18N_CHART_TITLE_DEFAULT = "Sohlenhöhen Differenz"; | |
50 public static final String I18N_XAXIS_LABEL_DEFAULT = "Fluss-Km"; | |
51 public static final String I18N_YAXIS_LABEL_DEFAULT = "delta S [m]"; | |
52 public static final String I18N_SECOND_YAXIS_LABEL_DEFAULT = "Breite [m]"; | |
53 public static final String I18N_THIRD_YAXIS_LABEL_DEFAULT = "Höhe [m]"; | |
54 public static final String I18N_DW_YAXIS_LABEL_DEFAULT = | |
55 "delta W [cm]"; | |
56 public static final String I18N_DW_YAXIS_LABEL = | |
57 "chart.fixings.longitudinalsection.yaxis.label"; | |
58 private static final String I18N_W_YAXIS_LABEL = | |
59 "chart.longitudinal.section.yaxis.label"; | |
60 private static final String I18N_W_YAXIS_LABEL_DEFAULT = "W [NN + m]"; | |
61 | |
62 @Override | |
63 protected YAxisWalker getYAxisWalker() { | |
64 return new YAxisWalker() { | |
65 | |
66 @Override | |
67 public int length() { | |
68 return YAXIS.values().length; | |
69 } | |
70 | |
71 @Override | |
72 public String getId(int idx) { | |
73 YAXIS[] yaxes = YAXIS.values(); | |
74 return yaxes[idx].toString(); | |
75 } | |
76 }; | |
77 } | |
78 | |
79 @Override | |
80 public void doOut(ArtifactAndFacet bundle, Document attr, boolean visible) { | |
81 String name = bundle.getFacetName(); | |
82 | |
83 logger.debug("doOut: " + name); | |
84 | |
85 if (name == null) { | |
86 logger.error("No facet name for doOut(). No output generated!"); | |
87 return; | |
88 } | |
89 | |
90 Facet facet = bundle.getFacet(); | |
91 | |
92 if (facet == null) { | |
93 return; | |
94 } | |
95 | |
96 if (getXBounds(0) != null && getDomainAxisRange() != null) { | |
97 Bounds bounds = | |
98 calculateZoom(getXBounds(0), getDomainAxisRange()); | |
99 context.putContextValue("startkm", bounds.getLower()); | |
100 context.putContextValue("endkm", bounds.getUpper()); | |
101 } | |
102 else if (getXBounds(0) != null && getDomainAxisRange() == null) { | |
103 context.putContextValue("startkm", getXBounds(0).getLower()); | |
104 context.putContextValue("endkm", getXBounds(0).getUpper()); | |
105 } | |
106 else if (getXBounds(0) == null && getDomainAxisRange() == null) { | |
107 BedDifferencesResult data = (BedDifferencesResult)bundle.getData(context); | |
108 context.putContextValue("startkm", data.getKms().min()); | |
109 context.putContextValue("endkm", data.getKms().max()); | |
110 } | |
111 else if (getXBounds(0) == null && getDomainAxisRange() != null){ | |
112 BedDifferencesResult data = (BedDifferencesResult)bundle.getData(context); | |
113 Bounds b = new DoubleBounds(data.getKms().min(), data.getKms().max()); | |
114 Bounds bounds = | |
115 calculateZoom(b, getDomainAxisRange()); | |
116 context.putContextValue("startkm", bounds.getLower()); | |
117 context.putContextValue("endkm", bounds.getUpper()); | |
118 } | |
119 Processor processor = new KMIndexProcessor(); | |
120 Processor woutp = new WOutProcessor(); | |
121 if (name.equals(BED_DIFFERENCE_YEAR)) { | |
122 doBedDifferenceYearOut( | |
123 (BedDiffYearResult) bundle.getData(context), | |
124 bundle, attr, visible); | |
125 } | |
126 else if (name.equals(BED_DIFFERENCE_MORPH_WIDTH)) { | |
127 doBedDifferenceMorphWidthOut( | |
128 (BedDiffYearResult) bundle.getData(context), | |
129 bundle, attr, visible); | |
130 } | |
131 else if (name.equals(BED_DIFFERENCE_YEAR_HEIGHT1)) { | |
132 doBedDifferenceHeightsOut( | |
133 (BedDiffYearResult)bundle.getData(context), | |
134 bundle, attr, visible, 0); | |
135 } | |
136 else if (name.equals(BED_DIFFERENCE_YEAR_HEIGHT2)) { | |
137 doBedDifferenceHeightsOut( | |
138 (BedDiffYearResult)bundle.getData(context), | |
139 bundle, attr, visible, 1); | |
140 } | |
141 else if (name.equals(BED_DIFFERENCE_YEAR_FILTERED)) { | |
142 doBedDifferenceYearOut( | |
143 (BedDiffYearResult) bundle.getData(context), | |
144 bundle, attr, visible); | |
145 } | |
146 else if (name.equals(BED_DIFFERENCE_YEAR_HEIGHT1_FILTERED)) { | |
147 doBedDifferenceHeightsOut( | |
148 (BedDiffYearResult)bundle.getData(context), | |
149 bundle, attr, visible, 0); | |
150 } | |
151 else if (name.equals(BED_DIFFERENCE_YEAR_HEIGHT2_FILTERED)) { | |
152 doBedDifferenceHeightsOut( | |
153 (BedDiffYearResult)bundle.getData(context), | |
154 bundle, attr, visible, 1); | |
155 } | |
156 else if (name.equals(MORPHOLOGIC_WIDTH)) { | |
157 doMorphologicWidthOut( | |
158 (MorphologicWidth)bundle.getData(context), | |
159 bundle, | |
160 attr, | |
161 visible, | |
162 0); | |
163 } | |
164 else if (processor.canHandle(name)) { | |
165 processor.doOut(this, bundle, attr, visible, YAXIS.dW.idx); | |
166 } | |
167 else if (name.equals(LONGITUDINAL_ANNOTATION)) { | |
168 doAnnotations( | |
169 (FLYSAnnotation) bundle.getData(context), | |
170 bundle, | |
171 attr, | |
172 visible); | |
173 } | |
174 else if (woutp.canHandle(name)) { | |
175 woutp.doOut(this, bundle, attr, visible, YAXIS.W.idx); | |
176 } | |
177 else if (name.equals(W_DIFFERENCES)) { | |
178 doWDifferencesOut( | |
179 (WKms) bundle.getData(context), | |
180 bundle, | |
181 attr, | |
182 visible); | |
183 } | |
184 else { | |
185 logger.warn("Unknown facet name " + name); | |
186 } | |
187 } | |
188 | |
189 private void doMorphologicWidthOut( | |
190 MorphologicWidth data, | |
191 ArtifactAndFacet bundle, | |
192 Document attr, | |
193 boolean visible, | |
194 int i) { | |
195 XYSeries series = new StyledXYSeries(bundle.getFacetDescription(), attr); | |
196 StyledSeriesBuilder.addPoints(series, data.getAsArray(), true); | |
197 | |
198 addAxisSeries(series, YAXIS.M.idx, visible); | |
199 } | |
200 | |
201 private void doBedDifferenceHeightsOut( | |
202 BedDiffYearResult data, | |
203 ArtifactAndFacet bundle, | |
204 Document attr, | |
205 boolean visible, | |
206 int idx) { | |
207 logger.debug("doBedDifferenceYearOut()"); | |
208 | |
209 XYSeries series = new StyledXYSeries(bundle.getFacetDescription(), attr); | |
210 if (idx == 0) { | |
211 StyledSeriesBuilder.addPoints(series, data.getHeights1Data(), true); | |
212 } | |
213 else { | |
214 StyledSeriesBuilder.addPoints(series, data.getHeights2Data(), true); | |
215 } | |
216 | |
217 addAxisSeries(series, YAXIS.H.idx, visible); | |
218 } | |
219 | |
220 @Override | |
221 protected String getDefaultChartTitle() { | |
222 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); | |
223 } | |
224 | |
225 @Override | |
226 protected String getDefaultXAxisLabel() { | |
227 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); | |
228 } | |
229 | |
230 @Override | |
231 protected String getDefaultYAxisLabel(int pos) { | |
232 String label = "default"; | |
233 if (pos == YAXIS.D.idx) { | |
234 label = msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); | |
235 } | |
236 else if (pos == YAXIS.M.idx) { | |
237 label = msg(I18N_SECOND_YAXIS_LABEL, I18N_SECOND_YAXIS_LABEL_DEFAULT); | |
238 } | |
239 else if (pos == YAXIS.H.idx) { | |
240 label = msg(I18N_THIRD_YAXIS_LABEL, I18N_THIRD_YAXIS_LABEL_DEFAULT); | |
241 } | |
242 else if (pos == YAXIS.dW.idx) { | |
243 label = msg(I18N_DW_YAXIS_LABEL, I18N_DW_YAXIS_LABEL_DEFAULT); | |
244 } | |
245 else if (pos == YAXIS.W.idx) { | |
246 return msg(I18N_W_YAXIS_LABEL, I18N_W_YAXIS_LABEL_DEFAULT); | |
247 } | |
248 | |
249 return label; | |
250 } | |
251 | |
252 protected void doBedDifferenceYearOut(BedDiffYearResult data, | |
253 ArtifactAndFacet aandf, Document theme, boolean visible) { | |
254 logger.debug("doBedDifferenceYearOut()"); | |
255 | |
256 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); | |
257 StyledSeriesBuilder.addPoints(series, data.getDifferencesData(), true); | |
258 | |
259 addAxisSeries(series, YAXIS.D.idx, visible); | |
260 } | |
261 | |
262 protected void doBedDifferenceMorphWidthOut(BedDiffYearResult data, | |
263 ArtifactAndFacet aandf, Document theme, boolean visible) { | |
264 logger.debug("doBedDifferencesMorphWidthOut()"); | |
265 | |
266 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); | |
267 StyledSeriesBuilder.addPoints(series, data.getMorphWidthData(), true); | |
268 | |
269 addAxisSeries(series, YAXIS.M.idx, visible); | |
270 } | |
271 | |
272 protected void doWDifferencesOut( | |
273 WKms wkms, | |
274 ArtifactAndFacet aandf, | |
275 Document theme, | |
276 boolean visible | |
277 ) { | |
278 if (wkms == null) { | |
279 logger.warn("No data to add to WDifferencesChart."); | |
280 return; | |
281 } | |
282 | |
283 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); | |
284 StyledSeriesBuilder.addPoints(series, wkms); | |
285 | |
286 addAxisSeries(series, YAXIS.D.idx, visible); | |
287 if (DataUtil.guessWaterIncreasing(wkms.allWs())) { | |
288 setInverted(true); | |
289 } | |
290 } | |
291 } |