comparison gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontal/HorizontalProfileOutputTransition.java @ 331:1c427acb6c76

Added subtitles to charts. gnv-artifacts/trunk@397 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 04 Dec 2009 15:30:20 +0000
parents 22a6493e8460
children
comparison
equal deleted inserted replaced
330:477c0c46605e 331:1c427acb6c76
1 /** 1 /**
2 * 2 *
3 */ 3 */
4 package de.intevation.gnv.transition.profile.horizontal; 4 package de.intevation.gnv.transition.profile.horizontal;
5 5
6 import com.vividsolutions.jts.geom.Point;
7 import com.vividsolutions.jts.io.WKTReader;
8 import com.vividsolutions.jts.io.ParseException;
9
6 import java.io.IOException; 10 import java.io.IOException;
7 import java.io.OutputStream; 11 import java.io.OutputStream;
8 import java.io.UnsupportedEncodingException; 12 import java.io.UnsupportedEncodingException;
13 import java.text.SimpleDateFormat;
9 import java.util.Collection; 14 import java.util.Collection;
15 import java.util.Date;
16 import java.util.Iterator;
10 import java.util.Locale; 17 import java.util.Locale;
11 18
12 import org.apache.log4j.Logger; 19 import org.apache.log4j.Logger;
13 20
14 import de.intevation.gnv.chart.Chart; 21 import de.intevation.gnv.chart.Chart;
22 29
23 import de.intevation.gnv.exports.DefaultExport; 30 import de.intevation.gnv.exports.DefaultExport;
24 import de.intevation.gnv.exports.ShapeDataCollector; 31 import de.intevation.gnv.exports.ShapeDataCollector;
25 import de.intevation.gnv.exports.DefaultProfile; 32 import de.intevation.gnv.exports.DefaultProfile;
26 import de.intevation.gnv.exports.Export.Profile; 33 import de.intevation.gnv.exports.Export.Profile;
34 import de.intevation.gnv.transition.describedata.KeyValueDescibeData;
27 35
28 /** 36 /**
29 * @author Tim Englich <tim.englich@intevation.de> 37 * @author Tim Englich <tim.englich@intevation.de>
30 * 38 *
31 */ 39 */
36 */ 44 */
37 private static final long serialVersionUID = 4401516087492028840L; 45 private static final long serialVersionUID = 4401516087492028840L;
38 46
39 private static Logger log = Logger 47 private static Logger log = Logger
40 .getLogger(HorizontalProfileOutputTransition.class); 48 .getLogger(HorizontalProfileOutputTransition.class);
49
50 public static final String DATE_FORMAT = "yyyy.MM.dd HH:mm:ss";
51
52 public static final String [] CHART_TITLE_META = {
53 "CRUISE",
54 "DEPTH",
55 "SHAPE"
56 };
57
58
59 public static final String [] CHART_TITLE_META_RESSOURCES = {
60 "cruiseid",
61 "depth",
62 "coordinate"
63 };
41 64
42 public static final String [] TIMESERIES_CSV_PROFILE_NAMES = { 65 public static final String [] TIMESERIES_CSV_PROFILE_NAMES = {
43 "SHAPE", 66 "SHAPE",
44 "YORDINATE", 67 "YORDINATE",
45 "GROUP1", 68 "GROUP1",
130 DefaultExport export = new DefaultExport( 153 DefaultExport export = new DefaultExport(
131 new ShapeDataCollector(TIMESERIES_CSV_PROFILE_NAMES)); 154 new ShapeDataCollector(TIMESERIES_CSV_PROFILE_NAMES));
132 155
133 export.create(TIMESERIES_CSV_PROFILE, outputStream, chartResult); 156 export.create(TIMESERIES_CSV_PROFILE, outputStream, chartResult);
134 } 157 }
158
159
160 protected String createChartTitle(Locale locale, String uuid) {
161 String fisName = getFisName(locale);
162 log.debug("created title for horizontal profile chart: " + fisName);
163
164 return fisName;
165 }
166
167
168 protected String createChartSubtitle(Locale locale, String uuid) {
169 log.debug("create chart subtitle.");
170 String subtitle = createTimePeriod(locale, uuid);
171
172 // ODV results contain meta information about cruise, station and so on
173 Collection results = getODVResult(uuid);
174 if (results != null) {
175 Iterator iter = results.iterator();
176 Result result = iter.hasNext() ? (Result) iter.next() : null;
177
178 subtitle += subtitle.length() != 0 ? "\n" : "";
179 subtitle += createMetaChartSubtitle(locale, result);
180 }
181
182 return subtitle;
183 }
184
185
186 protected String createMetaChartSubtitle(Locale locale, Result result) {
187 log.debug("Fetch meta information and put it into subtitle.");
188 if (result == null)
189 return "";
190
191 StringBuilder meta = new StringBuilder();
192 WKTReader wktReader = new WKTReader();
193
194
195 for (int i = 0; i < CHART_TITLE_META.length; i++) {
196 String qry = CHART_TITLE_META[i];
197
198 if (qry.equals("SHAPE")) {
199 try {
200 Point p = (Point) wktReader.read(result.getString(qry));
201
202 meta.append(getMessage(locale,"coordinate","coordinate"));
203 meta.append(": ");
204
205 log.debug(
206 "Add " + qry + " to meta information of subtitle: "
207 + p.toString()
208 );
209 meta.append(p.getX() + ", " + p.getY());
210 }
211 catch (ParseException pe) {
212 log.warn("Error while parsing point.", pe);
213 }
214 }
215 else {
216 log.debug(
217 "Add " + qry + " to meta information of subtitle: "
218 + result.getString(qry)
219 );
220 meta.append(getMessage(
221 locale,
222 CHART_TITLE_META_RESSOURCES[i],
223 CHART_TITLE_META_RESSOURCES[i]
224 ));
225 meta.append(": ");
226 meta.append(result.getString(qry));
227 }
228
229 if (i != CHART_TITLE_META.length-1)
230 meta.append("\n");
231 }
232
233 log.debug("Meta title for chart: " + meta.toString());
234 return meta.toString();
235 }
236
237
238 protected String createTimePeriod(Locale locale, String uuid) {
239 log.debug("create time period for chart subtitle.");
240 String subTitle = null;
241 Date startDate = null;
242 Date endDate = null;
243
244 Collection dates = getDates(uuid);
245 if (dates == null) {
246 log.debug("No time period for subtitle.");
247 return "";
248 }
249
250 SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
251 KeyValueDescibeData data = null;
252
253 Iterator iter = dates.iterator();
254 while (iter.hasNext()) {
255 try {
256 data = (KeyValueDescibeData)iter.next();
257
258 if (!data.isSelected())
259 continue;
260
261 Date current = format.parse(data.getValue());
262 long time = current.getTime();
263
264 if (startDate == null) {
265 startDate = current;
266 endDate = current;
267 }
268 else if (time < startDate.getTime()) {
269 startDate = current;
270 }
271 else if (time > endDate.getTime()) {
272 endDate = current;
273 }
274 }
275 catch (java.text.ParseException pe) {
276 log.warn("Error while parsing date: " + data.getValue(), pe);
277 }
278 }
279
280 subTitle = format.format(startDate) + " - " + format.format(endDate);
281 log.debug("created title for horizontal profile chart: " + subTitle);
282
283 return subTitle;
284 }
135 } 285 }

http://dive4elements.wald.intevation.org