changeset 4377:512a3af69e18

Extract common generator method from FixLongitudinalSectionGenerator The extracted methods and code can be reused for generating charts for bed differences if fixanalysis data is loaded via the datacache.
author Björn Ricks <bjoern.ricks@intevation.de>
date Fri, 02 Nov 2012 15:47:15 +0100
parents 3c8964855270
children 8eb1d6dc96a9
files flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/AbstractFixGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixLongitudinalSectionGenerator.java
diffstat 2 files changed, 113 insertions(+), 108 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/AbstractFixGenerator.java	Fri Nov 02 15:47:15 2012 +0100
@@ -0,0 +1,108 @@
+package de.intevation.flys.exports.fixings;
+
+import org.apache.log4j.Logger;
+import org.jfree.data.xy.XYSeries;
+import org.jfree.data.xy.XYSeriesCollection;
+import org.w3c.dom.Document;
+
+import de.intevation.artifactdatabase.state.ArtifactAndFacet;
+import de.intevation.flys.artifacts.model.fixings.AnalysisPeriod;
+import de.intevation.flys.artifacts.model.fixings.QWD;
+import de.intevation.flys.jfree.StyledXYSeries;
+import de.intevation.flys.utils.KMIndex;
+
+public abstract class AbstractFixGenerator extends FixChartGenerator {
+
+    public static final String I18N_DW_YAXIS_LABEL_DEFAULT  =
+            "delta W [cm]";
+
+    public static final String I18N_DW_YAXIS_LABEL =
+            "chart.fixings.longitudinalsection.yaxis.label";
+
+    private final static Logger logger =
+            Logger.getLogger(FixLongitudinalSectionGenerator.class);
+    
+    @SuppressWarnings("unchecked")
+    protected void doSectorAverageOut(ArtifactAndFacet aaf, Document doc, boolean visible, int idx) {
+        logger.debug("doSectorAverageOut" + aaf.getFacet().getIndex());
+    
+        int index = aaf.getFacet().getIndex();
+        int sectorNdx = index & 3;
+    
+        KMIndex<AnalysisPeriod> kms =
+                (KMIndex<AnalysisPeriod>)aaf.getData(context);
+    
+        if(kms == null) {
+            return;
+        }
+    
+        XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), doc);
+    
+        for (KMIndex.Entry<AnalysisPeriod> entry: kms) {
+            double km = entry.getKm();
+            AnalysisPeriod ap = entry.getValue();
+            QWD qwd = ap.getQSectorAverages()[sectorNdx];
+            if (qwd == null) {
+                continue;
+            }
+            double deltaW = qwd.getDeltaW();
+            series.add(km, deltaW);
+        }
+    
+        addAxisSeries(series, idx, visible);
+    
+    }
+
+    @SuppressWarnings("unchecked")
+    protected void doAnalysisEventsOut(ArtifactAndFacet aaf, Document doc, boolean visible, int idx) {
+        logger.debug("doAnalysisEventsOut");
+    
+        KMIndex<QWD> kms =
+                (KMIndex<QWD>)aaf.getData(context);
+    
+        if(kms == null) {
+            return;
+        }
+    
+        XYSeriesCollection col = new XYSeriesCollection();
+    
+        StyledXYSeries series = new StyledXYSeries(aaf.getFacetDescription(), false, doc);
+    
+        for (KMIndex.Entry<QWD> entry: kms) {
+            double km = entry.getKm();
+            QWD qwd = entry.getValue();
+    
+            series.add(km, qwd.getDeltaW());
+        }
+        col.addSeries(series);
+    
+        addAxisDataset(col, idx, visible);
+    }
+
+    @SuppressWarnings("unchecked")
+    protected void doReferenceEventsOut(ArtifactAndFacet aaf, Document doc, boolean visible, int idx) {
+        logger.debug("doReferenceEventOut");
+    
+        KMIndex<QWD> kms =
+                (KMIndex<QWD>)aaf.getData(context);
+    
+        if(kms == null) {
+            return;
+        }
+    
+        XYSeriesCollection col = new XYSeriesCollection();
+    
+        StyledXYSeries series = new StyledXYSeries(aaf.getFacetDescription(), false, doc);
+    
+        for (KMIndex.Entry<QWD> entry: kms) {
+            double km = entry.getKm();
+            QWD qwd = entry.getValue();
+    
+            series.add(km, qwd.getDeltaW());
+        }
+        col.addSeries(series);
+    
+        addAxisDataset(col, idx, visible);
+    }
+
+}
\ No newline at end of file
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixLongitudinalSectionGenerator.java	Fri Nov 02 15:41:52 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixLongitudinalSectionGenerator.java	Fri Nov 02 15:47:15 2012 +0100
@@ -7,7 +7,6 @@
 import org.jfree.chart.plot.Marker;
 import org.jfree.chart.plot.ValueMarker;
 import org.jfree.data.xy.XYSeries;
-import org.jfree.data.xy.XYSeriesCollection;
 import org.w3c.dom.Document;
 
 import de.intevation.artifactdatabase.state.ArtifactAndFacet;
@@ -21,7 +20,7 @@
 import de.intevation.flys.utils.KMIndex;
 
 public class FixLongitudinalSectionGenerator
-extends FixChartGenerator
+extends AbstractFixGenerator
 implements FacetTypes
 {
     private static Logger logger =
@@ -36,17 +35,12 @@
     public static final String I18N_XAXIS_LABEL =
             "chart.fixings.longitudinalsection.xaxis.label";
 
-    public static final String I18N_YAXIS_LABEL =
-            "chart.fixings.longitudinalsection.yaxis.label";
-
     public static final String I18N_CHART_TITLE_DEFAULT  =
             "Fixierungsanalyse";
 
     public static final String I18N_XAXIS_LABEL_DEFAULT  =
             "[km]";
 
-    public static final String I18N_YAXIS_LABEL_DEFAULT  =
-            "delta W [cm]";
 
     public static enum YAXIS {
         dW(0);
@@ -65,13 +59,13 @@
             doSectorAverageDeviationOut(aaf, doc, visible);
         }
         else if (name.contains(FIX_SECTOR_AVERAGE_LS)) {
-            doSectorAverageOut(aaf, doc, visible);
+            doSectorAverageOut(aaf, doc, visible, YAXIS.dW.idx);
         }
         else if (name.equals(FIX_REFERENCE_EVENTS_LS)) {
-            doReferenceEventsOut(aaf, doc, visible);
+            doReferenceEventsOut(aaf, doc, visible, YAXIS.dW.idx);
         }
         else if (name.equals(FIX_ANALYSIS_EVENTS_LS)) {
-            doAnalysisEventsOut(aaf, doc, visible);
+            doAnalysisEventsOut(aaf, doc, visible, YAXIS.dW.idx);
         }
         else if (name.equals(FIX_DEVIATION_LS)) {
             doReferenceDeviationOut(aaf, doc, visible);
@@ -95,42 +89,6 @@
     }
 
     @SuppressWarnings("unchecked")
-    protected void doSectorAverageOut(
-            ArtifactAndFacet aaf,
-            Document doc,
-            boolean visible)
-    {
-        logger.debug("doSectorAverageOut" + aaf.getFacet().getIndex());
-
-        int index = aaf.getFacet().getIndex();
-        int sectorNdx = index & 3;
-
-        KMIndex<AnalysisPeriod> kms =
-                (KMIndex<AnalysisPeriod>)aaf.getData(context);
-
-        if(kms == null) {
-            return;
-        }
-
-        XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), doc);
-
-        for (KMIndex.Entry<AnalysisPeriod> entry: kms) {
-            double km = entry.getKm();
-            AnalysisPeriod ap = entry.getValue();
-            QWD qwd = ap.getQSectorAverages()[sectorNdx];
-            if (qwd == null) {
-                continue;
-            }
-            double deltaW = qwd.getDeltaW();
-            series.add(km, deltaW);
-        }
-
-        addAxisSeries(series, 0, visible);
-
-    }
-
-
-    @SuppressWarnings("unchecked")
     protected void doSectorAverageDeviationOut(
             ArtifactAndFacet aaf,
             Document doc,
@@ -220,67 +178,6 @@
         addAreaSeries(area, 0, visible);
     }
 
-    @SuppressWarnings("unchecked")
-    protected void doAnalysisEventsOut(
-            ArtifactAndFacet aaf,
-            Document doc,
-            boolean visible)
-    {
-        logger.debug("doAnalysisEventsOut");
-
-        KMIndex<QWD> kms =
-                (KMIndex<QWD>)aaf.getData(context);
-
-        if(kms == null) {
-            return;
-        }
-
-        XYSeriesCollection col = new XYSeriesCollection();
-
-        StyledXYSeries series = new StyledXYSeries(aaf.getFacetDescription(), false, doc);
-
-        for (KMIndex.Entry<QWD> entry: kms) {
-            double km = entry.getKm();
-            QWD qwd = entry.getValue();
-
-            series.add(km, qwd.getDeltaW());
-        }
-        col.addSeries(series);
-
-        addAxisDataset(col, 0, visible);
-    }
-
-    @SuppressWarnings("unchecked")
-    protected void doReferenceEventsOut(
-            ArtifactAndFacet aaf,
-            Document doc,
-            boolean visible)
-    {
-        logger.debug("doReferenceEventOut");
-
-        KMIndex<QWD> kms =
-                (KMIndex<QWD>)aaf.getData(context);
-
-        if(kms == null) {
-            return;
-        }
-
-        XYSeriesCollection col = new XYSeriesCollection();
-
-        StyledXYSeries series = new StyledXYSeries(aaf.getFacetDescription(), false, doc);
-
-        for (KMIndex.Entry<QWD> entry: kms) {
-            double km = entry.getKm();
-            QWD qwd = entry.getValue();
-
-            series.add(km, qwd.getDeltaW());
-        }
-        col.addSeries(series);
-
-        addAxisDataset(col, 0, visible);
-    }
-
-
     @Override
     protected String getDefaultChartTitle() {
         return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT);
@@ -293,7 +190,7 @@
 
     @Override
     protected String getDefaultYAxisLabel(int pos) {
-        return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT);
+        return msg(I18N_DW_YAXIS_LABEL, I18N_DW_YAXIS_LABEL_DEFAULT);
     }
 
     @Override

http://dive4elements.wald.intevation.org