changeset 7059:f9d5020af0af generator-refactoring

Remove AxisProcessor "glue" class and extend Processor interface
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 20 Sep 2013 10:30:03 +0200
parents 5c07024cdc24
children 78ded33f5f5b
files artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java artifacts/src/main/java/org/dive4elements/river/exports/process/DefaultProcessor.java artifacts/src/main/java/org/dive4elements/river/exports/process/DischargeProcessor.java artifacts/src/main/java/org/dive4elements/river/exports/process/Processor.java
diffstat 5 files changed, 67 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java	Fri Sep 20 10:29:14 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java	Fri Sep 20 10:30:03 2013 +0200
@@ -58,27 +58,6 @@
         }
     } // class AxisAttributes
 
-    public static class AxisProcessor {
-        private Processor processor;
-        private String axisName;
-
-        public AxisProcessor() {
-        }
-
-        public AxisProcessor(Processor processor, String axisName) {
-            this.processor = processor;
-            this.axisName  = axisName;
-        }
-
-        public Processor getProcessor() {
-            return processor;
-        }
-
-        public String getAxisName() {
-            return axisName;
-        }
-    } // class AxisProcessor
-
     public static class Argument {
         private String expression;
         private String type;
@@ -160,14 +139,14 @@
     } // class Title
 
     private List<AxisAttributes> axesAttrs;
-    private List<AxisProcessor> axesProcessors;
+    private List<Processor> processors;
 
     private Title title;
     private Title subtitle;
 
     public DiagramAttributes() {
         axesAttrs      = new ArrayList<AxisAttributes>(5);
-        axesProcessors = new ArrayList<AxisProcessor>(5);
+        processors     = new ArrayList<Processor>(5);
     }
 
     public DiagramAttributes(Element config) {
@@ -200,8 +179,8 @@
         }
     }
 
-    public List<AxisProcessor> getAxesProcessors() {
-        return axesProcessors;
+    public List<Processor> getProcessors() {
+        return processors;
     }
 
     public Title getTitle() {
@@ -226,7 +205,8 @@
             try {
                 Processor processor =
                     (Processor)Class.forName(className).newInstance();
-                axesProcessors.add(new AxisProcessor(processor, axisName));
+                processor.setAxisName(axisName);
+                processors.add(processor);
             }
             catch (ClassNotFoundException cnfe) {
                 log.error(cnfe, cnfe);
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java	Fri Sep 20 10:29:14 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java	Fri Sep 20 10:30:03 2013 +0200
@@ -41,6 +41,7 @@
 
 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
 import org.dive4elements.artifactdatabase.state.Facet;
+import org.dive4elements.river.exports.process.Processor;
 import org.dive4elements.river.jfree.AxisDataset;
 import org.dive4elements.river.jfree.AnnotationHelper;
 import org.dive4elements.river.jfree.Bounds;
@@ -53,15 +54,6 @@
 
 import org.w3c.dom.Element;
 
-/* TODO remove after hackish testing */
-import org.dive4elements.river.exports.process.Processor;
-import org.dive4elements.river.exports.process.BedDiffHeightYearProcessor;
-import org.dive4elements.river.exports.process.BedDiffYearProcessor;
-import org.dive4elements.river.exports.process.BedheightProcessor;
-import org.dive4elements.river.exports.process.QOutProcessor;
-import org.dive4elements.river.exports.process.WOutProcessor;
-/* end TODO*/
-
 /**
  * The main diagram creation class.
  *
@@ -1010,16 +1002,10 @@
 
         logger.debug("DoOut for facet: " + facetName);
 
-        for (DiagramAttributes.AxisProcessor ap:
-            diagramAttributes.getAxesProcessors()) {
-
-            Processor pr = ap.getProcessor();
-
+        for (Processor pr: diagramAttributes.getProcessors()) {
             if (pr.canHandle(facetName)) {
-            //    pr.doOut(this, bundle, theme, visible, 0);
+//                pr.doOut(this, bundle, theme, visible, 0);
             }
         }
     }
-
-
 }
--- a/artifacts/src/main/java/org/dive4elements/river/exports/process/DefaultProcessor.java	Fri Sep 20 10:29:14 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/DefaultProcessor.java	Fri Sep 20 10:30:03 2013 +0200
@@ -10,12 +10,23 @@
 
 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
 import org.dive4elements.river.exports.XYChartGenerator;
+import org.dive4elements.river.exports.DiagramGenerator;
 import org.dive4elements.river.themes.ThemeDocument;
 
 /** Dummy implementation for the Processor interface.
  */
 public class DefaultProcessor implements Processor {
 
+    protected String axisName;
+
+    public void setAxisName(String axisName) {
+        this.axisName = axisName;
+    }
+
+    public String getAxisName() {
+        return axisName;
+    }
+
     /**
      * Processes data to generate e.g. a chart.
      *
@@ -25,13 +36,22 @@
      * @param visible       The visibility of the curve.
      * @param index        The index of the curve
      */
+    @Override
     public void doOut(
             XYChartGenerator generator,
             ArtifactAndFacet aandf,
             ThemeDocument    theme,
             boolean          visible,
-            int              indexu)
-    {
+            int              index) {
+        return;
+    }
+
+    @Override
+    public void doOut(
+            DiagramGenerator generator,
+            ArtifactAndFacet aandf,
+            ThemeDocument    theme,
+            boolean          visible) {
         return;
     }
 
@@ -41,6 +61,7 @@
      * @param facettype Name of the facet type
      * @return true if the facettype can be processed
      */
+    @Override
     public boolean canHandle(String facettype)
     {
         return false;
--- a/artifacts/src/main/java/org/dive4elements/river/exports/process/DischargeProcessor.java	Fri Sep 20 10:29:14 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/DischargeProcessor.java	Fri Sep 20 10:30:03 2013 +0200
@@ -31,7 +31,7 @@
 
 /** Helper for data handling in discharge diagrams. */
 public class DischargeProcessor
-implements   Processor, FacetTypes {
+extends DefaultProcessor implements FacetTypes {
 
     private final static Logger logger =
             Logger.getLogger(DischargeProcessor.class);
--- a/artifacts/src/main/java/org/dive4elements/river/exports/process/Processor.java	Fri Sep 20 10:29:14 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/Processor.java	Fri Sep 20 10:30:03 2013 +0200
@@ -11,6 +11,7 @@
 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
 import org.dive4elements.river.exports.XYChartGenerator;
 import org.dive4elements.river.themes.ThemeDocument;
+import org.dive4elements.river.exports.DiagramGenerator;
 
 /**
  * A processor is intended to generate an output e.g. curve in a chart diagramm from
@@ -19,17 +20,46 @@
  * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
  */
 public interface Processor {
+    /**
+     * Set the axis for this processor.
+     * This should be done before doOut is called for the first time.
+     *
+     * @param axisName The name of the Axis this processor should use.
+     */
+    public void setAxisName(String axisName);
+
+    /**
+     * Get the axis for this processor.
+     *
+     * @return The name of the axis that is used.
+     */
+    public String getAxisName();
 
     /**
      * Processes data to generate e.g. a chart.
      *
      * @param generator XYChartGenerator to add output on.
-     * @param aandf       The artifact and facet
-     * @param theme      The theme that contains styling information.
-     * @param visible       The visibility of the curve.
-     * @param index        The index of the curve
+     * @param aandf     The artifact and facet
+     * @param theme     The theme that contains styling information.
+     * @param visible   The visibility of the curve.
      */
     public void doOut(
+            DiagramGenerator generator,
+            ArtifactAndFacet aandf,
+            ThemeDocument    theme,
+            boolean          visible);
+
+    /**
+     * Processes data to generate e.g. a chart.
+     *
+     * @param generator DiagramGenerator to add output on.
+     * @param aandf     The artifact and facet
+     * @param theme     The theme that contains styling information.
+     * @param visible   The visibility of the curve.
+     * @param index     The index of the curve
+     */
+    @Deprecated
+    public void doOut(
             XYChartGenerator generator,
             ArtifactAndFacet aandf,
             ThemeDocument    theme,

http://dive4elements.wald.intevation.org