# HG changeset patch # User Tim Englich # Date 1253785167 0 # Node ID 5d4f5d26bb7a6bd9b810517a4f705e3ccde46cb0 # Parent dbd141c6bb9730cd3a92d01c1a613d25d9cfec1e Some Codecleanup done gnv-artifacts/trunk@123 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r dbd141c6bb97 -r 5d4f5d26bb7a gnv-artifacts/Changelog --- 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 + + * 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 * src/test/ressources/queries.properties Edited: diff -r dbd141c6bb97 -r 5d4f5d26bb7a gnv-artifacts/src/main/java/de/intevation/gnv/chart/ChartFactory.java --- 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 parameters, Collection measurements, OutputStream outputStream, Collection resultSet) throws IOException, TechnicalChartException { + public synchronized void createSimpleTimeSeriesChart(ChartLabels pLabels, ChartStyle pStyle, Collection parameters, Collection measurements, OutputStream outputStream, Collection 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 resultSet, + private XYDataset createDataset(Collection resultSet, int lUpperCut, int lLowerCut,Collection parameters, Collection measurements) throws TechnicalChartException { TimeSeriesCollection lTimeSeriesCollection = new TimeSeriesCollection(); @@ -305,7 +305,6 @@ Iterator 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 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(); } } diff -r dbd141c6bb97 -r 5d4f5d26bb7a gnv-artifacts/src/main/java/de/intevation/gnv/chart/ChartLabels.java --- 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 + * 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 diff -r dbd141c6bb97 -r 5d4f5d26bb7a gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChartFactory.java --- 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 ChartFactory fulfills the following purposes: - *
    - *
  1. - *
* - * @author blume - * @version 1.0 - * @serial 1.0 - * @see - * @since 06.12.2007 17:25:59 + * @author Tim Englich + * */ public class VerticalProfileChartFactory { @@ -70,7 +56,7 @@ private static boolean sDebug = sLogger.isDebugEnabled(); - public synchronized void createSimpleVerticalProfileChart(ChartLabels pLabels, ChartStyle pStyle, String name, Collection parameters, Collection measurements, OutputStream outputStream, Collection resultSet) throws IOException, TechnicalChartException { + public synchronized void createSimpleVerticalProfileChart(ChartLabels pLabels, ChartStyle pStyle, Collection parameters, Collection measurements, OutputStream outputStream, Collection 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 resultSet, + private XYDataset createDataset(Collection resultSet, int lUpperCut, int lLowerCut,Collection parameters, Collection measurements) throws TechnicalChartException { XYSeriesCollection xyDataset = new XYSeriesCollection(); diff -r dbd141c6bb97 -r 5d4f5d26bb7a gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java --- 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 @@ -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 chartResult = null; + /** + * The different Outputmodes which are provided by an OutputTransition + */ protected Collection 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 getInputData() throws TransitionException { + log.debug("OutputTransitionBase.getInputData"); + this.chartResult = null; + return super.getInputData(); + } } diff -r dbd141c6bb97 -r 5d4f5d26bb7a gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/vertical/VerticalProfileOutputTransition.java --- 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 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 parameters, Collection 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); } diff -r dbd141c6bb97 -r 5d4f5d26bb7a gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java --- 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 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 parameters = this.getParameters(); Collection 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 parameters, - Collection 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 values = this.getCollection(collectionName); + if (values != null){ + Iterator 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 parameters, + Collection 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 getParameters(){ - String collectionName = "parameterid"; + String collectionName = "parameterid"; // TODO: Konfigurierbar machen return this.getCollection(collectionName); } protected Collection getMeasurements(){ - String collectionName = "measurementid"; + String collectionName = "measurementid"; // TODO: Konfigurierbar machen return this.getCollection(collectionName); } @@ -135,7 +150,7 @@ if (o instanceof NamedCollection){ NamedCollection nc = (NamedCollection)o; - if (nc.getName().equals(collectionName)){ // TODO: konfigurierbar machen. + if (nc.getName().equals(collectionName)){ return nc; } }