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

Chartrendering integrated in Timeseries Transition gnv-artifacts/trunk@53 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Wed, 09 Sep 2009 15:28:18 +0000
parents 5db77e0a8594
children 504570de21fd
comparison
equal deleted inserted replaced
67:0e9762ebd18d 68:d117fd4b82e5
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.ByteArrayOutputStream;
9 import java.io.IOException;
10 import java.util.Collection;
11 import java.util.Iterator;
12
13 import org.apache.log4j.Logger;
14
15 import de.intevation.gnv.chart.ChartFactory;
16 import de.intevation.gnv.chart.ChartLabels;
17 import de.intevation.gnv.chart.ChartStyle;
18 import de.intevation.gnv.chart.exception.TechnicalChartException;
19 import de.intevation.gnv.geobackend.base.Result;
6 import de.intevation.gnv.transition.OutputTransitionBase; 20 import de.intevation.gnv.transition.OutputTransitionBase;
21 import de.intevation.gnv.transition.describedata.KeyValueDescibeData;
22 import de.intevation.gnv.transition.exception.TransitionException;
7 23
8 /** 24 /**
9 * @author Tim Englich <tim.englich@intevation.de> 25 * @author Tim Englich <tim.englich@intevation.de>
10 * 26 *
11 */ 27 */
12 public class TimeSeriesOutputTransition extends OutputTransitionBase{ 28 public class TimeSeriesOutputTransition extends OutputTransitionBase{
13 29
30 protected Collection<Result> chartResult = null;
31 /**
32 * the logger, used to log exceptions and additonaly information
33 */
34 private static Logger log = Logger.getLogger(TimeSeriesOutputTransition.class);
14 /** 35 /**
15 * Constructor 36 * Constructor
16 */ 37 */
17 public TimeSeriesOutputTransition() { 38 public TimeSeriesOutputTransition() {
18 super(); 39 super();
26 } 47 }
27 48
28 /** 49 /**
29 * @see de.intevation.gnv.transition.OutputTransition#out(java.lang.String) 50 * @see de.intevation.gnv.transition.OutputTransition#out(java.lang.String)
30 */ 51 */
31 public byte[] out(String outputMode) { 52 public byte[] out(String outputMode) throws TransitionException {
53 log.debug("TimeSeriesOutputTransition");
54 try {
55 this.advance(); // TODO nur neu holen wenn hash auf chartResult sich geändert hat
56 ByteArrayOutputStream os = new ByteArrayOutputStream();
57 ChartFactory chartFactory = new ChartFactory();
58
59 Collection<KeyValueDescibeData> parameters = this.getParameters();
60 Collection<KeyValueDescibeData> measurements = this.getMeasurements();
61 String timeSeriesName = "BLA";
62 ChartStyle chartStyle = this.creatStyle(600,400);
63 StringBuffer lDiagramTitle = new StringBuffer();
64 lDiagramTitle.append(/*mSelectedFis.getTitle()*/ "FIS-TITLE").append(" - ").append(/*mSelectedFeatureId[0].getTitle()*/"FeatureTitle"); // TODO: FIXME
65 String domainLable = "BLA"; // TODO woher bekommen wir das
66 ChartLabels chartLables = new ChartLabels(lDiagramTitle.toString(),domainLable , /*mSelectedParams[0].getTitle()*/ "Selected Params Title");
67 chartFactory.createSimpleTimeSeriesChart(chartLables, chartStyle, timeSeriesName,
68 parameters, measurements,
69 os, this.chartResult);
70 return os.toByteArray();
71 } catch (IOException e) {
72 log.error(e,e);
73 throw new TransitionException(e);
74 } catch (TechnicalChartException e) {
75 log.error(e,e);
76 throw new TransitionException(e);
77 }
78 }
79
80 /**
81 * @see de.intevation.gnv.transition.TransitionBase#purifyResult(java.util.Collection)
82 */
83 @Override
84 protected void purifyResult(Collection<Result> result) {
85 this.chartResult = result;
86 }
87
88 protected ChartStyle creatStyle(int witdh, int height){
89 // TODO Konfigurierbar machen
90 de.intevation.gnv.chart.Insets lInsets = new de.intevation.gnv.chart.Insets(5d, 5d, 5d, 5d);
91 Dimension lChartSize = new Dimension(witdh, height);
92 return new ChartStyle(Color.white, new Color(230, 230, 230), Color.white, Color.white, true, true, lInsets, lChartSize);
93 }
94
95 protected Collection<KeyValueDescibeData> getParameters(){
96 Iterator<Object> it = this.descibeData.iterator();
97 int i = 0;
98 while (it.hasNext()){
99
100 Object o = it.next();
101 if (i == 1){ // TODO über Identifier arbeiten This is just a hack
102 return (Collection)o;
103 }
104 i++;
105 }
32 return null; 106 return null;
33 } 107 }
34 108
109 protected Collection<KeyValueDescibeData> getMeasurements(){
110 Iterator<Object> it = this.descibeData.iterator();
111 int i = 0;
112 while (it.hasNext()){
113
114 Object o = it.next();
115 if (i == 2){ // TODO über Identifier arbeiten This is just a hack
116 return (Collection)o;
117 }
118 i++;
119 }
120 return null;
121 }
35 } 122 }

http://dive4elements.wald.intevation.org