Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/MiddleBedHeightGenerator.java @ 2715:250a370c377d
Added chart generator for middle bed height charts.
flys-artifacts/trunk@4441 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 18 May 2012 11:58:38 +0000 |
parents | |
children | b2ea89a665bc |
comparison
equal
deleted
inserted
replaced
2714:2952f6dee5cf | 2715:250a370c377d |
---|---|
1 package de.intevation.flys.exports; | |
2 | |
3 import org.apache.log4j.Logger; | |
4 | |
5 import org.jfree.data.xy.XYSeries; | |
6 | |
7 import org.w3c.dom.Document; | |
8 | |
9 import de.intevation.artifactdatabase.state.ArtifactAndFacet; | |
10 import de.intevation.artifactdatabase.state.Facet; | |
11 | |
12 import de.intevation.flys.artifacts.FLYSArtifact; | |
13 | |
14 import de.intevation.flys.artifacts.model.FacetTypes; | |
15 import de.intevation.flys.artifacts.model.MiddleBedHeightData; | |
16 | |
17 import de.intevation.flys.jfree.FLYSAnnotation; | |
18 import de.intevation.flys.jfree.StyledXYSeries; | |
19 | |
20 import de.intevation.flys.utils.FLYSUtils; | |
21 | |
22 | |
23 /** | |
24 * An OutGenerator that generates middle bed height charts. | |
25 * | |
26 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
27 */ | |
28 public class MiddleBedHeightGenerator | |
29 extends XYChartGenerator | |
30 implements FacetTypes | |
31 { | |
32 public enum YAXIS { | |
33 H(0); | |
34 protected int idx; | |
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(MiddleBedHeightGenerator.class); | |
42 | |
43 /** Key to look up internationalized String for annotations label. */ | |
44 public static final String I18N_ANNOTATIONS_LABEL = | |
45 "chart.bedheight_middle.annotations.label"; | |
46 | |
47 public static final String I18N_CHART_TITLE = | |
48 "chart.bedheight_middle.section.title"; | |
49 | |
50 public static final String I18N_CHART_SUBTITLE = | |
51 "chart.bedheight_middle.section.subtitle"; | |
52 | |
53 public static final String I18N_CHART_SHORT_SUBTITLE = | |
54 "chart.bedheight_middle.section.shortsubtitle"; | |
55 | |
56 public static final String I18N_XAXIS_LABEL = | |
57 "chart.bedheight_middle.section.xaxis.label"; | |
58 | |
59 public static final String I18N_YAXIS_LABEL = | |
60 "chart.bedheight_middle.section.yaxis.label"; | |
61 | |
62 public static final String I18N_CHART_TITLE_DEFAULT = "Mittlere Sohlöhe"; | |
63 public static final String I18N_XAXIS_LABEL_DEFAULT = "km"; | |
64 public static final String I18N_YAXIS_LABEL_DEFAULT = "mittlere Sohlhöhen [müNN]"; | |
65 | |
66 | |
67 | |
68 @Override | |
69 protected YAxisWalker getYAxisWalker() { | |
70 return new YAxisWalker() { | |
71 @Override | |
72 public int length() { | |
73 return YAXIS.values().length; | |
74 } | |
75 | |
76 @Override | |
77 public String getId(int idx) { | |
78 YAXIS[] yaxes = YAXIS.values(); | |
79 return yaxes[idx].toString(); | |
80 } | |
81 }; | |
82 } | |
83 | |
84 | |
85 /** | |
86 * Returns the default title for this chart. | |
87 * | |
88 * @return the default title for this chart. | |
89 */ | |
90 @Override | |
91 public String getDefaultChartTitle() { | |
92 Object[] args = new Object[] { | |
93 getRiverName() | |
94 }; | |
95 | |
96 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT, args); | |
97 } | |
98 | |
99 | |
100 /** | |
101 * Get internationalized label for the x axis. | |
102 */ | |
103 @Override | |
104 protected String getDefaultXAxisLabel() { | |
105 FLYSArtifact flys = (FLYSArtifact) master; | |
106 | |
107 return msg( | |
108 I18N_XAXIS_LABEL, | |
109 I18N_XAXIS_LABEL_DEFAULT, | |
110 new Object[] { FLYSUtils.getRiver(flys).getName() }); | |
111 } | |
112 | |
113 | |
114 @Override | |
115 protected String getDefaultYAxisLabel(int index) { | |
116 String label = "default"; | |
117 | |
118 if (index == YAXIS.H.idx) { | |
119 label = getHAxisLabel(); | |
120 } | |
121 | |
122 return label; | |
123 } | |
124 | |
125 | |
126 /** | |
127 * Get internationalized label for the y axis. | |
128 */ | |
129 protected String getHAxisLabel() { | |
130 FLYSArtifact flys = (FLYSArtifact) master; | |
131 | |
132 return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); | |
133 } | |
134 | |
135 | |
136 /** | |
137 * Produce output. | |
138 * @param facet current facet. | |
139 * @param attr theme for facet | |
140 */ | |
141 public void doOut( | |
142 ArtifactAndFacet artifactAndFacet, | |
143 Document attr, | |
144 boolean visible | |
145 ) { | |
146 String name = artifactAndFacet.getFacetName(); | |
147 | |
148 logger.debug("MiddleBedHeightGenerator.doOut: " + name); | |
149 | |
150 if (name == null) { | |
151 logger.error("No facet name for doOut(). No output generated!"); | |
152 return; | |
153 } | |
154 | |
155 Facet facet = artifactAndFacet.getFacet(); | |
156 | |
157 if (facet == null) { | |
158 return; | |
159 } | |
160 | |
161 if (name.equals(MIDDLE_BED_HEIGHT_SINGLE) || name.equals(MIDDLE_BED_HEIGHT_EPOCH)) { | |
162 doHeightOut( | |
163 (MiddleBedHeightData) artifactAndFacet.getData(context), | |
164 artifactAndFacet, | |
165 attr, | |
166 visible); | |
167 } | |
168 else if (name.equals(MIDDLE_BED_HEIGHT_ANNOTATION)) { | |
169 doAnnotations( | |
170 (FLYSAnnotation) artifactAndFacet.getData(context), | |
171 artifactAndFacet, | |
172 attr, | |
173 visible); | |
174 } | |
175 else if (FacetTypes.IS.AREA(name)) { | |
176 doArea( | |
177 artifactAndFacet.getData(context), | |
178 artifactAndFacet, | |
179 attr, | |
180 visible); | |
181 } | |
182 else if (FacetTypes.IS.MANUALPOINTS(name)) { | |
183 doPoints( | |
184 artifactAndFacet.getData(context), | |
185 artifactAndFacet, | |
186 attr, | |
187 visible, | |
188 YAXIS.H.idx); | |
189 } | |
190 else { | |
191 logger.warn("Unknown facet name: " + name); | |
192 return; | |
193 } | |
194 } | |
195 | |
196 | |
197 /** | |
198 * @param data A data object | |
199 * @param facet The facet. This facet does NOT support any data objects. Use | |
200 * FLYSArtifact.getNativeFacet() instead to retrieve a Facet which supports | |
201 * data. | |
202 * @param theme The theme that contains styling information. | |
203 * @param visible The visibility of the curve. | |
204 */ | |
205 protected void doHeightOut( | |
206 MiddleBedHeightData data, | |
207 ArtifactAndFacet aandf, | |
208 Document theme, | |
209 boolean visible | |
210 ) { | |
211 logger.debug("MiddleBedHeightGenerator.doMainChannelOut"); | |
212 | |
213 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme); | |
214 | |
215 StyledSeriesBuilder.addPoints(series, data.getMiddleHeightsPoints(), true); | |
216 | |
217 addAxisSeries(series, YAXIS.H.idx, visible); | |
218 } | |
219 | |
220 | |
221 /** Look up the axis identifier for a given facet type. */ | |
222 public int axisIdxForFacet(String facetName) { | |
223 if (FacetTypes.IS.H(facetName)) { | |
224 return YAXIS.H.idx; | |
225 } | |
226 else { | |
227 logger.warn("Could not find axis for facet " + facetName); | |
228 return YAXIS.H.idx; | |
229 } | |
230 } | |
231 | |
232 | |
233 /** | |
234 * Do Area out. | |
235 * @param theme styling information. | |
236 * @param visible whether or not visible. | |
237 */ | |
238 protected void doArea( | |
239 Object o, | |
240 ArtifactAndFacet aandf, | |
241 Document theme, | |
242 boolean visible | |
243 ) { | |
244 logger.debug("FlowVelocityGenerator.doArea"); | |
245 logger.warn("TODO: Implement FlowVelocityGenerator.doArea"); | |
246 } | |
247 } | |
248 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |