Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/NormalizedReferenceCurveGenerator.java @ 2277:3f3e4f94171b
Added generator for "Reduzierte Bezugslinie".
flys-artifacts/trunk@3936 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 06 Feb 2012 15:42:27 +0000 |
parents | |
children | 08bb95e1fc41 |
comparison
equal
deleted
inserted
replaced
2276:2966787b5188 | 2277:3f3e4f94171b |
---|---|
1 package de.intevation.flys.exports; | |
2 | |
3 import org.w3c.dom.Document; | |
4 | |
5 import java.awt.Font; | |
6 | |
7 import org.apache.log4j.Logger; | |
8 | |
9 import org.jfree.chart.JFreeChart; | |
10 import org.jfree.chart.axis.NumberAxis; | |
11 import org.jfree.chart.title.TextTitle; | |
12 | |
13 import org.jfree.data.xy.XYSeries; | |
14 | |
15 import de.intevation.artifactdatabase.state.ArtifactAndFacet; | |
16 | |
17 import de.intevation.flys.artifacts.model.FacetTypes; | |
18 import de.intevation.flys.artifacts.model.WW; | |
19 import de.intevation.flys.artifacts.model.WW.ApplyFunctionIterator; | |
20 import de.intevation.flys.artifacts.model.WWAxisTypes; | |
21 | |
22 import de.intevation.flys.jfree.StyledXYSeries; | |
23 | |
24 | |
25 /** | |
26 * An OutGenerator that generates reference curves. | |
27 */ | |
28 public class NormalizedReferenceCurveGenerator | |
29 extends XYChartGenerator | |
30 implements FacetTypes | |
31 { | |
32 public static enum YAXIS { | |
33 W_M(0), | |
34 W_CM(1); | |
35 | |
36 public int idx; | |
37 private YAXIS(int c) { | |
38 idx = c; | |
39 } | |
40 } | |
41 | |
42 /** House logger. */ | |
43 private static Logger logger = | |
44 Logger.getLogger(NormalizedReferenceCurveGenerator.class); | |
45 | |
46 public static final String I18N_CHART_TITLE = | |
47 "chart.reference.curve.title"; | |
48 | |
49 public static final String I18N_CHART_SUBTITLE = | |
50 "chart.reference.curve.subtitle"; | |
51 | |
52 public static final String W_CM_DEFAULT = | |
53 "chart.reference.curve.wcm"; | |
54 | |
55 public static final String W_NNM_DEFAULT = | |
56 "chart.reference.curve.wnn"; | |
57 | |
58 public static final String START_GAUGE = | |
59 "chart.reference.curve.start_at_gauge"; | |
60 | |
61 public static final String START_FREE = | |
62 "chart.reference.curve.start_free"; | |
63 | |
64 /* | |
65 | |
66 public static final String I18N_XAXIS_LABEL = | |
67 "chart.reference.curve.xaxis.label"; | |
68 | |
69 public static final String I18N_YAXIS_LABEL = | |
70 "chart.reference.curve.yaxis.label"; | |
71 */ | |
72 /* | |
73 public static final String I18N_XAXIS_LABEL_DEFAULT = | |
74 "W [NN + m]"; | |
75 | |
76 public static final String I18N_YAXIS_LABEL_DEFAULT = | |
77 "W [NN + m]"; | |
78 */ | |
79 | |
80 | |
81 public static final String I18N_CHART_TITLE_DEFAULT = | |
82 "Bezugslinie"; | |
83 | |
84 | |
85 public NormalizedReferenceCurveGenerator() { | |
86 super(); | |
87 } | |
88 | |
89 | |
90 /** | |
91 * Create Axis for given index. | |
92 * @return axis with according internationalized label. | |
93 */ | |
94 @Override | |
95 protected NumberAxis createYAxis(int index) { | |
96 Font labelFont = new Font("Tahoma", Font.BOLD, 14); | |
97 String label = getYAxisLabel(index); | |
98 | |
99 NumberAxis axis = createNumberAxis(index, label); | |
100 // TODO aspect-ratio settings. | |
101 if (index == YAXIS.W_M.idx) { | |
102 axis.setAutoRangeIncludesZero(false); | |
103 } | |
104 axis.setLabelFont(labelFont); | |
105 return axis; | |
106 } | |
107 | |
108 | |
109 /** Get default chart title. */ | |
110 @Override | |
111 protected String getDefaultChartTitle() { | |
112 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); | |
113 } | |
114 | |
115 @Override | |
116 protected String getDefaultChartSubtitle() { | |
117 Object[] args = new Object[] { | |
118 getRiverName(), | |
119 }; | |
120 | |
121 return msg(I18N_CHART_SUBTITLE, "", args); | |
122 } | |
123 | |
124 | |
125 @Override | |
126 protected void addSubtitles(JFreeChart chart) { | |
127 String subtitle = getChartSubtitle(); | |
128 | |
129 if (subtitle != null && subtitle.length() > 0) { | |
130 chart.addSubtitle(new TextTitle(subtitle)); | |
131 } | |
132 } | |
133 | |
134 | |
135 /** Get Label for X-axis (W). */ | |
136 @Override | |
137 protected String getDefaultXAxisLabel() { | |
138 // TODO i18nreturn msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); | |
139 // at_gauge + w_cm | |
140 return "W am Bezugsort- oder Pegel."; | |
141 } | |
142 | |
143 | |
144 /** | |
145 * Get Label for primary and other Y Axes. | |
146 * @param index Axis-Index (0-based). | |
147 */ | |
148 @Override | |
149 protected String getDefaultYAxisLabel(int index) { | |
150 String label = "default"; | |
151 if (index == YAXIS.W_M.idx) { | |
152 //label = msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); | |
153 //TODO i18n | |
154 return "W am Zielort"; | |
155 } | |
156 else if (index == YAXIS.W_CM.idx) { | |
157 return "W am Zielpegel"; | |
158 } | |
159 | |
160 return label; | |
161 } | |
162 | |
163 | |
164 /** | |
165 * Called for each facet/them in the out mapped to this generator. | |
166 * @param artifactFacet artifact and facet for this theme. | |
167 * @param theme styling info. | |
168 * @param visible Whether or not the theme is visible. | |
169 */ | |
170 @Override | |
171 public void doOut( | |
172 ArtifactAndFacet artifactFacet, | |
173 Document theme, | |
174 boolean visible | |
175 ) { | |
176 String name = artifactFacet.getFacetName(); | |
177 | |
178 logger.debug("NormalizedReferenceCurveGenerator.doOut: " + name); | |
179 | |
180 if (name == null || name.length() == 0) { | |
181 logger.error("No facet given. Cannot create dataset."); | |
182 return; | |
183 } | |
184 | |
185 if (name.equals(REFERENCE_CURVE_NORMALIZED)) { | |
186 doReferenceOut(artifactFacet.getData(context), theme, visible); | |
187 } | |
188 else { | |
189 logger.warn("Unknown facet name: " + name); | |
190 return; | |
191 } | |
192 } | |
193 | |
194 | |
195 /** Register DataSeries with (maybe transformed) points. */ | |
196 public void doReferenceOut( | |
197 Object data, | |
198 Document theme, | |
199 boolean visible | |
200 ) { | |
201 WW ww = (WW)data; | |
202 | |
203 // TODO: Fetch from black board instead! | |
204 WWAxisTypes wwat = new WWAxisTypes(ww); | |
205 | |
206 ApplyFunctionIterator iter = wwat.transform(ww); | |
207 | |
208 XYSeries series = new StyledXYSeries( | |
209 ww.getName(), false, theme); | |
210 | |
211 double [] values = new double[2]; | |
212 | |
213 while (iter.hasNext()) { | |
214 iter.next(values); | |
215 series.add(values[0], values[1], false); | |
216 } | |
217 | |
218 if (ww.endAtGauge()) { | |
219 addAxisSeries(series, YAXIS.W_M.idx, visible); | |
220 } | |
221 else { | |
222 addAxisSeries(series, YAXIS.W_CM.idx, visible); | |
223 } | |
224 } | |
225 | |
226 | |
227 /** Get Walker to iterate over all axes. */ | |
228 @Override | |
229 protected YAxisWalker getYAxisWalker() { | |
230 return new YAxisWalker() { | |
231 /** Get number of items. */ | |
232 @Override | |
233 public int length() { | |
234 return YAXIS.values().length; | |
235 } | |
236 | |
237 /** Get identifier for this index. */ | |
238 @Override | |
239 public String getId(int idx) { | |
240 YAXIS[] yaxes = YAXIS.values(); | |
241 return yaxes[idx].toString(); | |
242 } | |
243 }; | |
244 } | |
245 } | |
246 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |