view gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java @ 70:0035862b0295

Refactoringwork done because of changes in the artifact-module gnv-artifacts/trunk@60 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Thu, 10 Sep 2009 09:40:49 +0000
parents d117fd4b82e5
children 504570de21fd
line wrap: on
line source
/**
 *
 */
package de.intevation.gnv.transition.timeseries;

import java.awt.Color;
import java.awt.Dimension;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;

import org.apache.log4j.Logger;

import de.intevation.gnv.chart.ChartFactory;
import de.intevation.gnv.chart.ChartLabels;
import de.intevation.gnv.chart.ChartStyle;
import de.intevation.gnv.chart.exception.TechnicalChartException;
import de.intevation.gnv.geobackend.base.Result;
import de.intevation.gnv.transition.OutputTransitionBase;
import de.intevation.gnv.transition.describedata.KeyValueDescibeData;
import de.intevation.gnv.transition.exception.TransitionException;

/**
 * @author Tim Englich <tim.englich@intevation.de>
 *
 */
public class TimeSeriesOutputTransition extends OutputTransitionBase{
    
    protected Collection<Result> chartResult = null;
    /**
     * the logger, used to log exceptions and additonaly information
     */
    private static Logger log = Logger.getLogger(TimeSeriesOutputTransition.class);
    /**
     * Constructor
     */
    public TimeSeriesOutputTransition() {
        super();
    }

    /**
     * @see de.intevation.gnv.transition.Transition#validate()
     */
    public boolean validate() {
        return true;
    }

    /**
     * @see de.intevation.gnv.transition.OutputTransition#out(java.lang.String)
     */
    public byte[] out(String outputMode) throws TransitionException {
        log.debug("TimeSeriesOutputTransition");
        try {
            this.advance(); // TODO nur neu holen wenn hash auf chartResult sich ge�ndert hat
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            ChartFactory chartFactory = new ChartFactory();
            
            Collection<KeyValueDescibeData> parameters = this.getParameters();
            Collection<KeyValueDescibeData> measurements = this.getMeasurements();
            String timeSeriesName = "BLA";
            ChartStyle chartStyle = this.creatStyle(600,400);
            StringBuffer lDiagramTitle = new StringBuffer();
            lDiagramTitle.append(/*mSelectedFis.getTitle()*/ "FIS-TITLE").append(" - ").append(/*mSelectedFeatureId[0].getTitle()*/"FeatureTitle"); // TODO: FIXME
            String domainLable = "BLA"; // TODO woher bekommen wir das
            ChartLabels chartLables = new ChartLabels(lDiagramTitle.toString(),domainLable , /*mSelectedParams[0].getTitle()*/ "Selected Params Title");
            chartFactory.createSimpleTimeSeriesChart(chartLables, chartStyle, timeSeriesName, 
                                                     parameters, measurements, 
                                                     os, this.chartResult);
            return os.toByteArray();
        } catch (IOException e) {
            log.error(e,e);
            throw new TransitionException(e);
        } catch (TechnicalChartException e) {
            log.error(e,e);
            throw new TransitionException(e);
        }
    }

    /**
     * @see de.intevation.gnv.transition.TransitionBase#purifyResult(java.util.Collection)
     */
    @Override
    protected void purifyResult(Collection<Result> result) {
        this.chartResult = result;
    }
    
    protected ChartStyle creatStyle(int witdh, int height){
        // TODO Konfigurierbar machen
        de.intevation.gnv.chart.Insets lInsets = new de.intevation.gnv.chart.Insets(5d, 5d, 5d, 5d);
        Dimension lChartSize = new Dimension(witdh, height);
        return new ChartStyle(Color.white, new Color(230, 230, 230), Color.white, Color.white, true, true, lInsets, lChartSize);
    }
    
    protected Collection<KeyValueDescibeData> getParameters(){
        Iterator<Object> it = this.descibeData.iterator();
        int i = 0;
        while (it.hasNext()){
           
           Object o = it.next();
           if (i == 1){ // TODO �ber Identifier arbeiten This is just a hack
               return (Collection)o;
           }
           i++;
        }
        return null;
    }
    
    protected Collection<KeyValueDescibeData> getMeasurements(){
        Iterator<Object> it = this.descibeData.iterator();
        int i = 0;
        while (it.hasNext()){
           
           Object o = it.next();
           if (i == 2){ // TODO �ber Identifier arbeiten This is just a hack
               return (Collection)o;
           }
           i++;
        }
        return null;
    }
}

http://dive4elements.wald.intevation.org