changeset 86:5d4f5d26bb7a

Some Codecleanup done gnv-artifacts/trunk@123 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Thu, 24 Sep 2009 09:39:27 +0000
parents dbd141c6bb97
children ce398a7a99fc
files gnv-artifacts/Changelog gnv-artifacts/src/main/java/de/intevation/gnv/chart/ChartFactory.java gnv-artifacts/src/main/java/de/intevation/gnv/chart/ChartLabels.java gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChartFactory.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/vertical/VerticalProfileOutputTransition.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java
diffstat 7 files changed, 150 insertions(+), 110 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/Changelog	Wed Sep 23 14:32:55 2009 +0000
+++ b/gnv-artifacts/Changelog	Thu Sep 24 09:39:27 2009 +0000
@@ -1,3 +1,22 @@
+2009-09-24  Tim Englich  <tim.englich@intevation.de>
+
+    * src/main/java/de/intevation/gnv/chart/VerticalProfileChartFactory.java  Edited, 
+      src/main/java/de/intevation/gnv/chart/ChartLabels.java Edited,
+      src/main/java/de/intevation/gnv/chart/ChartFactory.java Edited:
+      Removed obsolet Parameters an Methods.
+      Use the ChartLable to put the DomainAxisLable into the Chart. 
+    
+    * src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java Edited:
+      Some more Loggingoutput integrated.
+      Some Performanceimprovements done. The ResultData will only be refreshed if
+      the InputValues has changed.
+      Some Refactoring Work done. Move some Members into from extending Classes
+      into this implementation.
+    * src/main/java/de/intevation/gnv/transition/profile/vertical/VerticalProfileOutputTransition.java Edited, 
+      src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java Edited:
+     Dummywerte für Diagrammgenerierung durch Echtwerte ersetzt.
+     Obsolete Übergabeparameter entfernt. 
+     
 2009-09-23  Tim Englich  <tim.englich@intevation.de>
 
     * src/test/ressources/queries.properties Edited:
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/ChartFactory.java	Wed Sep 23 14:32:55 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/ChartFactory.java	Thu Sep 24 09:39:27 2009 +0000
@@ -66,7 +66,7 @@
 	private static boolean sDebug = sLogger.isDebugEnabled();
 
 
-	public synchronized void createSimpleTimeSeriesChart(ChartLabels pLabels, ChartStyle pStyle, String pTimeSeriesName, Collection<KeyValueDescibeData> parameters, Collection<KeyValueDescibeData> measurements, OutputStream outputStream, Collection<Result> resultSet) throws IOException, TechnicalChartException {
+	public synchronized void createSimpleTimeSeriesChart(ChartLabels pLabels, ChartStyle pStyle, Collection<KeyValueDescibeData> parameters, Collection<KeyValueDescibeData> measurements, OutputStream outputStream, Collection<Result> resultSet) throws IOException, TechnicalChartException {
 		if (sDebug)
 			sLogger.debug("createSimpleTimeSeriesChart()");
 		int lLowerLevel = Integer.MIN_VALUE;
@@ -81,12 +81,12 @@
 		}
 		if (sDebug)
 			sLogger.debug("  vor createDataset()");
-		XYDataset lSet = createDataset(pTimeSeriesName, resultSet, lUpperLevel,
+		XYDataset lSet = this.createDataset(resultSet, lUpperLevel,
 				lLowerLevel,parameters,measurements);
 		if (sDebug)
 			sLogger.debug("  nach createDataset()");
 		final Color[] color = {Color.black, Color.red, Color.green, Color.blue};
-		DateAxis domain = new DateAxis("Zeit [UTC]");
+		DateAxis domain = new DateAxis(pLabels.getDomainAxisLabel());
         NumberAxis axis;
         StandardXYItemRenderer renderer = new StandardXYItemRenderer();
 		XYPlot plot = new XYPlot();
@@ -292,7 +292,7 @@
 		return lTimeseries;
 	}
 
-	private XYDataset createDataset(String pTimeseriesName, Collection<Result> resultSet,
+	private XYDataset createDataset(Collection<Result> resultSet,
 			int lUpperCut, int lLowerCut,Collection<KeyValueDescibeData> parameters, Collection<KeyValueDescibeData> measurements) throws TechnicalChartException {
 		
 		TimeSeriesCollection lTimeSeriesCollection = new TimeSeriesCollection();
@@ -305,7 +305,6 @@
 	
 			Iterator<Result> resultIterator = resultSet.iterator();
 			if (resultIterator.hasNext()){
-    //			Row row = new Row(sArrayStrLine);
     			Result row = resultIterator.next();
     			
     			break1 = row.getString("GROUP1"); // 2
@@ -331,7 +330,6 @@
     	
     				}
     				mEnd = i;
-    				//mEnd ++;
     				dEnd = row.getDate("XORDINATE");
     				i = i + 1;
     			}
@@ -381,7 +379,7 @@
         Iterator<KeyValueDescibeData> it = values.iterator();
     	while(it.hasNext()){
     	    KeyValueDescibeData data = it.next();
-    		if (id  ==Integer.parseInt(data.getKey())){ // TODO just a hack
+    		if (id  ==Integer.parseInt(data.getKey())){
     		    return data.getValue();
     		}
     	}
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/ChartLabels.java	Wed Sep 23 14:32:55 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/ChartLabels.java	Thu Sep 24 09:39:27 2009 +0000
@@ -14,69 +14,41 @@
 
 /**
  * @author  drewnak
+ * @author Tim Englich <tim.englich@intevation.de>
+ * Changes and codecleanup
  */
 public class ChartLabels {
     /**
      * 
      */
-    private String mTitle;
-    /**
-     * 
-     */
-    private String mTimeAxisLabel;
+    private String title;
     /**
      * 
      */
-    private String mValueAxisLabel;
+    private String domainAxisLabel;
+
     /**
-     * 
+     * Constructor
+     * @param title
+     * @param domainAxisLabel
      */
-    public ChartLabels(String pTitle, String pTimeAxisLabel, String pValueAxisLabel) {
-        mTitle = pTitle;
-        mTimeAxisLabel = pTimeAxisLabel;
-        mValueAxisLabel = pValueAxisLabel;
+    public ChartLabels(String title, String domainAxisLabel) {
+        this.title = title;
+        this.domainAxisLabel = domainAxisLabel;
     }
 
     /**
      * @return the title
      */
     public String getTitle() {
-        return mTitle;
+        return this.title;
     }
 
-    /**
-     * @param pTitle the title to set
-     */
-    public void setTitle(String pTitle) {
-        mTitle = pTitle;
-    }
 
     /**
      * @return the timeAxisLabel
      */
-    public String getTimeAxisLabel() {
-        return mTimeAxisLabel;
-    }
-
-    /**
-     * @param pTimeAxisLabel the timeAxisLabel to set
-     */
-    public void setTimeAxisLabel(String pTimeAxisLabel) {
-        mTimeAxisLabel = pTimeAxisLabel;
+    public String getDomainAxisLabel() {
+        return this.domainAxisLabel;
     }
-
-    /**
-     * @return the valueAxisLabel
-     */
-    public String getValueAxisLabel() {
-        return mValueAxisLabel;
-    }
-
-    /**
-     * @param pValueAxisLabel the valueAxisLabel to set
-     */
-    public void setValueAxisLabel(String pValueAxisLabel) {
-        mValueAxisLabel = pValueAxisLabel;
-    }
-
 }
\ No newline at end of file
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChartFactory.java	Wed Sep 23 14:32:55 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChartFactory.java	Thu Sep 24 09:39:27 2009 +0000
@@ -21,13 +21,11 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Collection;
-import java.util.Date;
 import java.util.Iterator;
 
 import org.apache.log4j.Logger;
 import org.jfree.chart.JFreeChart;
 import org.jfree.chart.axis.AxisLocation;
-import org.jfree.chart.axis.DateAxis;
 import org.jfree.chart.axis.NumberAxis;
 import org.jfree.chart.axis.NumberTickUnit;
 import org.jfree.chart.encoders.KeypointPNGEncoderAdapter;
@@ -35,11 +33,6 @@
 import org.jfree.chart.plot.XYPlot;
 import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
-import org.jfree.data.general.Series;
-import org.jfree.data.time.Minute;
-import org.jfree.data.time.TimeSeries;
-import org.jfree.data.time.TimeSeriesCollection;
-import org.jfree.data.xy.DefaultXYDataset;
 import org.jfree.data.xy.XYDataset;
 import org.jfree.data.xy.XYSeries;
 import org.jfree.data.xy.XYSeriesCollection;
@@ -50,16 +43,9 @@
 import de.intevation.gnv.transition.describedata.KeyValueDescibeData;
 
 /**
- * The class <code>ChartFactory</code> fulfills the following purposes:
- * <ol>
- * <li></li>
- * </ol>
  * 
- * @author blume
- * @version 1.0
- * @serial 1.0
- * @see
- * @since 06.12.2007 17:25:59
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
  */
 public class VerticalProfileChartFactory {
 
@@ -70,7 +56,7 @@
 	private static boolean sDebug = sLogger.isDebugEnabled();
 
 
-	public synchronized void createSimpleVerticalProfileChart(ChartLabels pLabels, ChartStyle pStyle, String name, Collection<KeyValueDescibeData> parameters, Collection<KeyValueDescibeData> measurements, OutputStream outputStream, Collection<Result> resultSet) throws IOException, TechnicalChartException {
+	public synchronized void createSimpleVerticalProfileChart(ChartLabels pLabels, ChartStyle pStyle, Collection<KeyValueDescibeData> parameters, Collection<KeyValueDescibeData> measurements, OutputStream outputStream, Collection<Result> resultSet) throws IOException, TechnicalChartException {
 		if (sDebug)
 			sLogger.debug("createSimpleTimeSeriesChart()");
 		int lLowerLevel = Integer.MIN_VALUE;
@@ -85,12 +71,12 @@
 		}
 		if (sDebug)
 			sLogger.debug("  vor createDataset()");
-		XYDataset lSet = createDataset(name, resultSet, lUpperLevel,
+		XYDataset lSet = this.createDataset(resultSet, lUpperLevel,
 				lLowerLevel,parameters,measurements);
 		if (sDebug)
 			sLogger.debug("  nach createDataset()");
 		final Color[] color = {Color.black, Color.red, Color.green, Color.blue};
-		NumberAxis domain = new NumberAxis("Tiefe");
+		NumberAxis domain = new NumberAxis(pLabels.getDomainAxisLabel());
         NumberAxis axis;
         StandardXYItemRenderer renderer = new StandardXYItemRenderer();
 		XYPlot plot = new XYPlot();
@@ -251,7 +237,7 @@
 		return series;
 	}
 
-	private XYDataset createDataset(String name, Collection<Result> resultSet,
+	private XYDataset createDataset(Collection<Result> resultSet,
 			int lUpperCut, int lLowerCut,Collection<KeyValueDescibeData> parameters, Collection<KeyValueDescibeData> measurements) throws TechnicalChartException {
 		
 	    XYSeriesCollection xyDataset = new XYSeriesCollection();
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java	Wed Sep 23 14:32:55 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java	Thu Sep 24 09:39:27 2009 +0000
@@ -11,6 +11,8 @@
 import org.w3c.dom.NodeList;
 
 import de.intevation.artifactdatabase.Config;
+import de.intevation.gnv.geobackend.base.Result;
+import de.intevation.gnv.transition.exception.TransitionException;
 
 /**
  * @author Tim Englich <tim.englich@intevation.de>
@@ -18,12 +20,28 @@
  */
 public abstract class OutputTransitionBase extends TransitionBase implements
         OutputTransition {
+    
+    
+    /**
+     * Thie UID of this Class
+     */
+    private static final long serialVersionUID = -1718732895737303823L;
+   
     /**
      * the logger, used to log exceptions and additonaly information
      */
     private static Logger log = Logger.getLogger(OutputTransitionBase.class);
+    /**
+     * The Results which should be used for Rendering the Charts or 
+     * do other output
+     */
+    protected Collection<Result> chartResult = null;
     
+    /**
+     * The different Outputmodes which are provided by an OutputTransition
+     */
     protected Collection<OutputMode> outputModes = null;
+    
     /**
      * Constructor
      */
@@ -38,6 +56,13 @@
         log.debug("OutputTransitionBase.getOutputModes");
         return this.outputModes;
     }
+    /**
+     * @see de.intevation.gnv.transition.Transition#validate()
+     */
+    public boolean validate() {
+        log.debug("OutputTransitionBase.validate");
+        return true;
+    }
 
     /**
      * @see de.intevation.gnv.transition.TransitionBase#setup(org.w3c.dom.Node)
@@ -62,5 +87,26 @@
             }
         }
     }
+    
+    /**
+     * @see de.intevation.gnv.transition.TransitionBase#advance()
+     */
+    @Override
+    public void advance() throws TransitionException {
+        log.debug("OutputTransitionBase.advance");
+        if (this.chartResult == null){
+            super.advance();
+        }
+    }
+
+    /**
+     * @see de.intevation.gnv.transition.TransitionBase#getInputData()
+     */
+    @Override
+    public Collection<InputData> getInputData() throws TransitionException {
+        log.debug("OutputTransitionBase.getInputData");
+        this.chartResult = null;
+        return super.getInputData();
+    }
 
 }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/vertical/VerticalProfileOutputTransition.java	Wed Sep 23 14:32:55 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/vertical/VerticalProfileOutputTransition.java	Thu Sep 24 09:39:27 2009 +0000
@@ -6,9 +6,7 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Collection;
-import java.util.Iterator;
 
-import de.intevation.gnv.chart.ChartFactory;
 import de.intevation.gnv.chart.ChartLabels;
 import de.intevation.gnv.chart.ChartStyle;
 import de.intevation.gnv.chart.VerticalProfileChartFactory;
@@ -22,7 +20,7 @@
  */
 public class VerticalProfileOutputTransition extends TimeSeriesOutputTransition {
     /**
-     *
+     * The UID of this class
      */
     private static final long serialVersionUID = 4401516087492028840L;
 
@@ -30,23 +28,29 @@
      * Constructor
      */
     public VerticalProfileOutputTransition() {
+        super();
+        super.domainLable = "Tiefe";
     }
 
+    /**
+     * @see de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition#getMeasurements()
+     */
     @Override
     protected Collection<KeyValueDescibeData> getMeasurements() {
         String collectionName = "dateid";
         return this.getCollection(collectionName);
     }
     
+    /**
+     * @see de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition#createChart(java.io.OutputStream, java.util.Collection, java.util.Collection, java.lang.String, de.intevation.gnv.chart.ChartStyle, de.intevation.gnv.chart.ChartLabels)
+     */
     @Override
     protected void createChart(OutputStream outputStream,
             Collection<KeyValueDescibeData> parameters,
             Collection<KeyValueDescibeData> measurements,
-            String timeSeriesName, ChartStyle chartStyle,
-            ChartLabels chartLables) throws IOException,
-            TechnicalChartException {
+            ChartStyle chartStyle, ChartLabels chartLables) throws IOException, TechnicalChartException {
         VerticalProfileChartFactory chartFactory = new VerticalProfileChartFactory();
-        chartFactory.createSimpleVerticalProfileChart(chartLables, chartStyle, timeSeriesName, 
+        chartFactory.createSimpleVerticalProfileChart(chartLables, chartStyle, 
                                                  parameters, measurements, 
                                                  outputStream, this.chartResult);
     }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java	Wed Sep 23 14:32:55 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java	Thu Sep 24 09:39:27 2009 +0000
@@ -5,7 +5,6 @@
 
 import java.awt.Color;
 import java.awt.Dimension;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Collection;
@@ -28,12 +27,19 @@
  *
  */
 public class TimeSeriesOutputTransition extends OutputTransitionBase{
+
+    /**
+     * The UID of this Class
+     */
+    private static final long serialVersionUID = 4178407570503098858L;
     
-    protected Collection<Result> chartResult = null;
     /**
      * the logger, used to log exceptions and additonaly information
      */
     private static Logger log = Logger.getLogger(TimeSeriesOutputTransition.class);
+    
+    protected String domainLable = "Zeit [UTC]"; 
+    
     /**
      * Constructor
      */
@@ -54,18 +60,12 @@
     public void out(String outputMode, OutputStream outputStream) throws TransitionException {
         log.debug("TimeSeriesOutputTransition");
         try {
-            this.advance(); // TODO nur neu holen wenn hash auf chartResult sich ge�ndert hat
-           
-            
+            this.advance(); 
             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");
-            createChart(outputStream, parameters, measurements, timeSeriesName,
+            ChartLabels chartLables = new ChartLabels(this.getSelectedFeatureName(),this.domainLable);
+            this.createChart(outputStream, parameters, measurements,
                     chartStyle, chartLables);
         } catch (IOException e) {
             log.error(e,e);
@@ -76,26 +76,41 @@
         }
     }
 
-/**
- * @param outputStream
- * @param parameters
- * @param measurements
- * @param timeSeriesName
- * @param chartStyle
- * @param chartLables
- * @throws IOException
- * @throws TechnicalChartException
- */
-protected void createChart(OutputStream outputStream,
-        Collection<KeyValueDescibeData> parameters,
-        Collection<KeyValueDescibeData> measurements, String timeSeriesName,
-        ChartStyle chartStyle, ChartLabels chartLables) throws IOException,
-        TechnicalChartException {
-    ChartFactory chartFactory = new ChartFactory();
-    chartFactory.createSimpleTimeSeriesChart(chartLables, chartStyle, timeSeriesName, 
-                                             parameters, measurements, 
-                                             outputStream, this.chartResult);
-}
+    
+    protected String getSelectedFeatureName(){
+        String collectionName = "featureid"; // TODO: Konfigurierbar machen
+        Collection<KeyValueDescibeData> values =  this.getCollection(collectionName);
+        if (values != null){
+            Iterator<KeyValueDescibeData> it = values.iterator();
+            while(it.hasNext()){
+                KeyValueDescibeData data = it.next();
+                if (data.isSelected()){
+                    return data.getValue();
+                }
+            }
+        }
+        return null;
+    }
+    /**
+     * @param outputStream
+     * @param parameters
+     * @param measurements
+     * @param timeSeriesName
+     * @param chartStyle
+     * @param chartLables
+     * @throws IOException
+     * @throws TechnicalChartException
+     */
+    protected void createChart(OutputStream outputStream,
+            Collection<KeyValueDescibeData> parameters,
+            Collection<KeyValueDescibeData> measurements,
+            ChartStyle chartStyle, ChartLabels chartLables) throws IOException,
+            TechnicalChartException {
+        ChartFactory chartFactory = new ChartFactory();
+        chartFactory.createSimpleTimeSeriesChart(chartLables, chartStyle,
+                                                 parameters, measurements, 
+                                                 outputStream, this.chartResult);
+    }
 
     /**
      * @see de.intevation.gnv.transition.TransitionBase#purifyResult(java.util.Collection)
@@ -113,12 +128,12 @@
     }
     
     protected Collection<KeyValueDescibeData> getParameters(){
-        String collectionName = "parameterid";
+        String collectionName = "parameterid"; // TODO: Konfigurierbar machen
         return this.getCollection(collectionName);
     }
     
     protected Collection<KeyValueDescibeData> getMeasurements(){
-        String collectionName = "measurementid";
+        String collectionName = "measurementid"; // TODO: Konfigurierbar machen
         return this.getCollection(collectionName);
     }
 
@@ -135,7 +150,7 @@
            
            if (o instanceof NamedCollection<?>){
                NamedCollection<KeyValueDescibeData> nc = (NamedCollection<KeyValueDescibeData>)o;
-               if (nc.getName().equals(collectionName)){ // TODO: konfigurierbar machen.
+               if (nc.getName().equals(collectionName)){
                    return nc;
                }
            }

http://dive4elements.wald.intevation.org