comparison gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java @ 304:a16d337c5678

The style of charts can be configured with ChartThemes using XML configuration files. gnv-artifacts/trunk@362 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 23 Nov 2009 17:01:28 +0000
parents 9ba2cf8cad8d
children 45625b5cd6d4
comparison
equal deleted inserted replaced
303:9ba2cf8cad8d 304:a16d337c5678
1 /** 1 /**
2 * 2 *
3 */ 3 */
4 package de.intevation.gnv.transition.timeseries; 4 package de.intevation.gnv.transition.timeseries;
5 5
6 import java.awt.Color;
7 import java.awt.Dimension;
8 import java.io.IOException; 6 import java.io.IOException;
7 import java.io.File;
9 import java.io.OutputStream; 8 import java.io.OutputStream;
10 import java.io.UnsupportedEncodingException; 9 import java.io.UnsupportedEncodingException;
11 import java.util.ArrayList; 10 import java.util.ArrayList;
12 import java.util.Collection; 11 import java.util.Collection;
13 import java.util.Iterator; 12 import java.util.Iterator;
37 import de.intevation.artifacts.CallMeta; 36 import de.intevation.artifacts.CallMeta;
38 import de.intevation.artifacts.PreferredLocale; 37 import de.intevation.artifacts.PreferredLocale;
39 import de.intevation.gnv.artifacts.ressource.RessourceFactory; 38 import de.intevation.gnv.artifacts.ressource.RessourceFactory;
40 import de.intevation.gnv.chart.Chart; 39 import de.intevation.gnv.chart.Chart;
41 import de.intevation.gnv.chart.ChartLabels; 40 import de.intevation.gnv.chart.ChartLabels;
42 import de.intevation.gnv.chart.ChartStyle;
43 import de.intevation.gnv.chart.TimeSeriesChart; 41 import de.intevation.gnv.chart.TimeSeriesChart;
42 import de.intevation.gnv.chart.XMLChartTheme;
44 import de.intevation.gnv.chart.exception.TechnicalChartException; 43 import de.intevation.gnv.chart.exception.TechnicalChartException;
45 import de.intevation.gnv.exports.DefaultExport; 44 import de.intevation.gnv.exports.DefaultExport;
46 import de.intevation.gnv.exports.DefaultDataCollector; 45 import de.intevation.gnv.exports.DefaultDataCollector;
47 import de.intevation.gnv.exports.SimpleOdvDataCollector; 46 import de.intevation.gnv.exports.SimpleOdvDataCollector;
48 import de.intevation.gnv.exports.DefaultProfile; 47 import de.intevation.gnv.exports.DefaultProfile;
211 throw new TransitionException(e); 210 throw new TransitionException(e);
212 } 211 }
213 Collection<KeyValueDescibeData> parameters = this.getParameters(uuid); 212 Collection<KeyValueDescibeData> parameters = this.getParameters(uuid);
214 Collection<KeyValueDescibeData> measurements = this.getMeasurements(uuid); 213 Collection<KeyValueDescibeData> measurements = this.getMeasurements(uuid);
215 Collection<KeyValueDescibeData> dates = this.getDates(uuid); 214 Collection<KeyValueDescibeData> dates = this.getDates(uuid);
216 ChartStyle chartStyle = this
217 .creatStyle(chartWidth, chartHeight);
218 ChartLabels chartLables = new ChartLabels(this.getFisName(callMeta.getLanguages())+" "+this 215 ChartLabels chartLables = new ChartLabels(this.getFisName(callMeta.getLanguages())+" "+this
219 .getSelectedFeatureName(uuid), this.domainLable); 216 .getSelectedFeatureName(uuid), this.domainLable);
220 217
221 String exportFormat = getExportFormat(mimeType); 218 String exportFormat = getExportFormat(mimeType);
222 219
223 this.createChart( 220 this.createChart(
224 outputStream, 221 outputStream,
225 parameters, 222 parameters,
226 measurements, 223 measurements,
227 dates, 224 dates,
228 chartStyle,
229 chartLables, 225 chartLables,
230 uuid, 226 uuid,
231 exportFormat 227 exportFormat,
228 chartWidth,
229 chartHeight
232 ); 230 );
233 } else if (outputMode.equalsIgnoreCase("csv")) { 231 } else if (outputMode.equalsIgnoreCase("csv")) {
234 log.debug("CSV-File will be generated."); 232 log.debug("CSV-File will be generated.");
235 Collection<Result> chartResult = this.getChartResult(uuid); 233 Collection<Result> chartResult = this.getChartResult(uuid);
236 this.createCSV(outputStream, chartResult); 234 this.createCSV(outputStream, chartResult);
396 protected void createChart( 394 protected void createChart(
397 OutputStream outputStream, 395 OutputStream outputStream,
398 Collection parameters, 396 Collection parameters,
399 Collection measurements, 397 Collection measurements,
400 Collection dates, 398 Collection dates,
401 ChartStyle chartStyle,
402 ChartLabels chartLables, 399 ChartLabels chartLables,
403 String uuid, 400 String uuid,
404 String exportFormat 401 String exportFormat,
402 int width,
403 int height
405 ) 404 )
406 throws IOException, TechnicalChartException 405 throws IOException, TechnicalChartException
407 { 406 {
408 log.debug("Create chart."); 407 log.debug("Create chart.");
409 Chart chart = getChart( 408 Chart chart = getChart(
410 chartLables, 409 chartLables,
411 null, // ChartTheme
412 parameters, 410 parameters,
413 measurements, 411 measurements,
414 getChartResult(uuid), 412 getChartResult(uuid),
415 timeGapDefinitions, 413 timeGapDefinitions,
416 null, // Locale 414 null, // Locale
420 if (chart == null) { 418 if (chart == null) {
421 log.error("Could not initialize chart."); 419 log.error("Could not initialize chart.");
422 return; 420 return;
423 } 421 }
424 422
425 Dimension dim = chartStyle.getChartSize();
426 int width = new Double(dim.getWidth()).intValue();
427 int height = new Double(dim.getHeight()).intValue();
428
429 log.debug( 423 log.debug(
430 "export chart as " + exportFormat + 424 "export chart as " + exportFormat +
431 " in " + width + "x" + height 425 " in " + width + "x" + height
432 ); 426 );
433 427
438 ); 432 );
439 } 433 }
440 434
441 protected Chart getChart( 435 protected Chart getChart(
442 ChartLabels chartLables, 436 ChartLabels chartLables,
443 ChartTheme chartTheme,
444 Collection parameters, 437 Collection parameters,
445 Collection measurements, 438 Collection measurements,
446 Collection result, 439 Collection result,
447 Collection dates, 440 Collection dates,
448 Locale locale, 441 Locale locale,
459 return chart; 452 return chart;
460 453
461 log.info("Chart not in cache yet."); 454 log.info("Chart not in cache yet.");
462 chart = new TimeSeriesChart( 455 chart = new TimeSeriesChart(
463 chartLables, 456 chartLables,
464 null, 457 createStyle(),
465 parameters, 458 parameters,
466 measurements, 459 measurements,
467 result, 460 result,
468 dates, 461 dates,
469 null 462 null
476 } 469 }
477 470
478 return chart; 471 return chart;
479 } 472 }
480 473
481 protected ChartStyle creatStyle(int witdh, int height) { 474 protected ChartTheme createStyle() {
482 // TODO Konfigurierbar machen 475 XMLChartTheme theme = null;
483 de.intevation.gnv.chart.Insets lInsets = new de.intevation.gnv.chart.Insets( 476
484 5d, 5d, 5d, 5d); 477 Document template = Config.getChartTemplate();
485 Dimension lChartSize = new Dimension(witdh, height); 478 String name = Config.getStringXPath(
486 return new ChartStyle(Color.white, new Color(230, 230, 230), 479 template,
487 Color.white, Color.white, true, true, lInsets, lChartSize); 480 "theme/name/@value"
488 } 481 );
489 482
483 theme = new XMLChartTheme(name);
484 theme.applyXMLConfiguration(template);
485
486 return theme;
487 }
488
490 protected String getFisName(PreferredLocale[] preferredLocales){ 489 protected String getFisName(PreferredLocale[] preferredLocales){
491 String returnValue = ""; 490 String returnValue = "";
492 InputData inputData = this.inputData.get("fisname"); 491 InputData inputData = this.inputData.get("fisname");
493 if (inputData != null){ 492 if (inputData != null){
494 returnValue = RessourceFactory.getInstance() 493 returnValue = RessourceFactory.getInstance()

http://dive4elements.wald.intevation.org