changeset 1881:0e9c0b49b4ef

CrossSectionApp: draw ground with StableXYDifferenceRenderer flys-artifacts/trunk@3240 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 12 Nov 2011 12:05:37 +0000
parents ebd16028efa3
children d67a9ca116c3
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/charts/CrossSectionApp.java flys-artifacts/src/main/java/de/intevation/flys/jfree/StableXYDifferenceRenderer.java flys-artifacts/src/main/java/de/intevation/flys/jfree/XYDatasetToZeroMapper.java
diffstat 4 files changed, 81 insertions(+), 202 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Nov 11 12:07:06 2011 +0000
+++ b/flys-artifacts/ChangeLog	Sat Nov 12 12:05:37 2011 +0000
@@ -1,3 +1,15 @@
+2011-11-10	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/charts/CrossSectionApp.java:
+	  Draw ground with StableXYDifferenceRenderer.
+
+	* src/main/java/de/intevation/flys/jfree/StableXYDifferenceRenderer.java:
+	  Removed XYDatasetToZeroMapper stuff. Not needed any longer
+	  because we use rendereres on dataset basis now.
+
+	* src/main/java/de/intevation/flys/jfree/XYDatasetToZeroMapper.java:
+	  Removed.Not longer needed.
+
 2011-11-11  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	* doc/conf/meta-data.xml: Include computed discharge curves in dc
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/charts/CrossSectionApp.java	Fri Nov 11 12:07:06 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/charts/CrossSectionApp.java	Sat Nov 12 12:05:37 2011 +0000
@@ -10,6 +10,8 @@
 
 import de.intevation.flys.utils.Pair;
 
+import de.intevation.flys.jfree.StableXYDifferenceRenderer;
+
 import java.awt.BorderLayout;
 import java.awt.Dimension;
 import java.awt.FlowLayout;
@@ -60,6 +62,7 @@
 import org.jfree.chart.plot.PlotOrientation;
 import org.jfree.chart.plot.XYPlot;
 
+import org.jfree.data.xy.DefaultXYDataset;
 import org.jfree.data.xy.XYSeries;
 import org.jfree.data.xy.XYDataset;
 import org.jfree.data.xy.XYSeriesCollection;
@@ -402,11 +405,12 @@
         }
     }
 
-    public XYDataset generateWaterLevels(
-        List<Point2D>      points
+    public void generateWaterLevels(
+        List<Point2D>                         points,
+        List<Pair<XYDataset, XYItemRenderer>> datasets
     ) {
         if (points == null || points.isEmpty() || lastWaterLevel == null) {
-            return null;
+            return;
         }
 
         double [][] data = Lines.createWaterLines(points, lastWaterLevel);
@@ -419,15 +423,17 @@
             series.add(x[i], y[i], false);
         }
 
-        return new XYSeriesCollection(series);
+        datasets.add(new Pair<XYDataset, XYItemRenderer>(
+            new XYSeriesCollection(series), null));
     }
 
-    public XYDataset generateProfile(
-        List<Point2D>      points,
-        String             legend
+    public void generateProfile(
+        List<Point2D>                         points,
+        String                                legend,
+        List<Pair<XYDataset, XYItemRenderer>> datasets
     ) {
         if (points == null || points.isEmpty()) {
-            return null;
+            return;
         }
 
         double [][] values = CrossSectionLine.fetchCrossSectionProfile(points);
@@ -440,17 +446,32 @@
             series.add(x[i], y[i], false);
         }
 
-        return new XYSeriesCollection(series);
+        datasets.add(new Pair<XYDataset, XYItemRenderer>(
+            new XYSeriesCollection(series), null));;
+    }
+
+    public void generateGround(
+        List<Point2D>                         points,
+        String                                legend,
+        List<Pair<XYDataset, XYItemRenderer>> datasets
+    ) {
+        if (points == null || points.isEmpty()) {
+            return;
+        }
+
+        double [][] values = CrossSectionLine.fetchCrossSectionProfile(points);
+
+        DefaultXYDataset dataset = new DefaultXYDataset();
+        dataset.addSeries(legend, values);
+
+        StableXYDifferenceRenderer renderer =
+            new StableXYDifferenceRenderer();
+
+        datasets.add(new Pair<XYDataset, XYItemRenderer>(
+            dataset, renderer));
     }
 
     public List<Pair<XYDataset, XYItemRenderer>> generateDatasets() {
-        List<Pair<XYDataset, XYItemRenderer>> pairs =
-            new ArrayList<Pair<XYDataset, XYItemRenderer>>();
-
-        return pairs;
-    }
-
-    public List<Pair<XYDataset, XYItemRenderer>> generateDataset() {
 
         List<Pair<XYDataset, XYItemRenderer>> datasets =
             new ArrayList<Pair<XYDataset, XYItemRenderer>>();
@@ -460,41 +481,46 @@
 
         for (int i = 0; i < drawCrossSection.length; ++i) {
             List<Point2D> points = null;
+            CrossSection cs = crossSections.get(i);
 
             if (drawCrossSection[i]) {
-                CrossSection cs = crossSections.get(i);
                 for (Pair<CrossSection, CrossSectionLine> csl: csli.lines) {
                     if (csl.getA() == cs) {
                         points = csl.getB().fetchCrossSectionLinesPoints();
 
-                        XYDataset dataset = generateProfile(
-                            points, cs.getDescription());
-                        if (dataset != null) {
-                            datasets.add(new Pair<XYDataset, XYItemRenderer>(
-                                dataset, null));
-                        }
+                        generateProfile(
+                            points, cs.getDescription(), datasets);
                         break;
                     }
                 }
             }
 
             if (drawWaterLevel[i]) {
-                CrossSection cs = crossSections.get(i);
                 for (Pair<CrossSection, CrossSectionLine> csl: csli.lines) {
                     if (csl.getA() == cs) {
                         if (points != null) {
                             points = csl.getB().fetchCrossSectionLinesPoints();
                         }
-                        XYDataset dataset = generateWaterLevels(points);
-                        if (dataset != null) {
-                            datasets.add(new Pair<XYDataset, XYItemRenderer>(
-                                dataset, null));
-                        }
+                        generateWaterLevels(points, datasets);
                         break;
                     }
                 }
             }
 
+            if (drawGround[i]) {
+                for (Pair<CrossSection, CrossSectionLine> csl: csli.lines) {
+                    if (csl.getA() == cs) {
+                        if (points != null) {
+                            points = csl.getB().fetchCrossSectionLinesPoints();
+                        }
+                        generateGround(
+                            points,
+                            cs.getDescription() + "/Boden",
+                            datasets);
+                        break;
+                    }
+                }
+            }
         }
 
         return datasets;
@@ -527,7 +553,7 @@
             false);
 
         List<Pair<XYDataset, XYItemRenderer>> datasets =
-            generateDataset();
+            generateDatasets();
 
         XYPlot plot = chart.getXYPlot();
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/StableXYDifferenceRenderer.java	Fri Nov 11 12:07:06 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/StableXYDifferenceRenderer.java	Sat Nov 12 12:05:37 2011 +0000
@@ -88,7 +88,6 @@
 import java.io.ObjectOutputStream;
 import java.util.Collections;
 import java.util.LinkedList;
-import java.util.Iterator;
 
 import org.jfree.chart.LegendItem;
 import org.jfree.chart.axis.ValueAxis;
@@ -139,7 +138,7 @@
     /** The shape to display in the legend item. */
     private transient Shape legendLine;
 
-    private XYDatasetToZeroMapper mapper;
+    //private XYDatasetToZeroMapper mapper;
 
     /**
      * This flag controls whether or not the x-coordinates (in Java2D space)
@@ -156,7 +155,7 @@
      * Creates a new renderer with default attributes.
      */
     public StableXYDifferenceRenderer() {
-        this(Color.green, Color.red, false, null);
+        this(Color.green, Color.red, false /*,  null */);
     }
 
     /**
@@ -169,8 +168,7 @@
      * @param shapes  draw shapes?
      */
     public StableXYDifferenceRenderer(Paint positivePaint, Paint negativePaint,
-                                boolean shapes,
-                                XYDatasetToZeroMapper mapper) {
+                                boolean shapes) {
         if (positivePaint == null) {
             throw new IllegalArgumentException(
                     "Null 'positivePaint' argument.");
@@ -184,7 +182,6 @@
         this.shapesVisible = shapes;
         this.legendLine = new Line2D.Double(-7.0, 0.0, 7.0, 0.0);
         this.roundXCoordinates = false;
-        this.mapper = mapper;
     }
 
     /**
@@ -392,38 +389,17 @@
                          int item,
                          CrosshairState crosshairState,
                          int pass) {
-
-        if (mapper == null) {
-            switch (pass) {
-                case 0:
-                    drawItemPass0(g2, dataArea, info, 
-                        plot, domainAxis, rangeAxis,
-                        dataset, series, item, crosshairState);
-                    break;
-                case 1:
-                    drawItemPass1(g2, dataArea, info,
-                        plot, domainAxis, rangeAxis,
-                        dataset, series, item, crosshairState);
-            }
+        switch (pass) {
+            case 0:
+                drawItemPass0(g2, dataArea, info, 
+                    plot, domainAxis, rangeAxis,
+                    dataset, series, item, crosshairState);
+                break;
+            case 1:
+                drawItemPass1(g2, dataArea, info,
+                    plot, domainAxis, rangeAxis,
+                    dataset, series, item, crosshairState);
         }
-        else {
-            for (Iterator<XYDataset> iter = mapper.iterator(dataset);
-                iter.hasNext();
-            ) {
-                switch (pass) {
-                    case 0:
-                        drawItemPass0(g2, dataArea, info, 
-                            plot, domainAxis, rangeAxis,
-                            dataset, series, item, crosshairState);
-                        break;
-                    case 1:
-                        drawItemPass1(g2, dataArea, info,
-                            plot, domainAxis, rangeAxis,
-                            dataset, series, item, crosshairState);
-                }
-            } // for all segments
-        }
-
     }
 
     /**
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/XYDatasetToZeroMapper.java	Fri Nov 11 12:07:06 2011 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,135 +0,0 @@
-package de.intevation.flys.jfree;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.ArrayList;
-
-import org.jfree.data.xy.XYDataset;
-
-import org.jfree.data.general.DatasetChangeListener;
-import org.jfree.data.general.DatasetGroup;
-
-import org.jfree.data.DomainOrder;
-
-import java.io.Serializable;
-
-public class XYDatasetToZeroMapper
-implements   Serializable
-{
-    protected int seriesA;
-    protected int seriesB;
-
-    public class MappedXYDataset implements XYDataset, Serializable {
-
-        protected XYDataset parent;
-
-        public MappedXYDataset() {
-        }
-
-        public MappedXYDataset(XYDataset parent) {
-            this.parent = parent;
-        }
-
-        protected int remap(int series) {
-            switch (series) {
-                case 0: return seriesA;
-                case 1: return seriesB;
-            }
-            return series;
-        }
-
-        @Override
-        public int getSeriesCount() {
-            return seriesA != seriesB ? 2 : 1;
-        }
-
-        @Override
-        public Comparable getSeriesKey(int series) {
-            return parent.getSeriesKey(remap(series));
-        }
-
-        @Override
-        public int indexOf(Comparable seriesKey) {
-            Comparable cmpA = parent.getSeriesKey(seriesA);
-            if (cmpA == seriesKey
-            || (cmpA != null && cmpA.equals(seriesKey))) {
-                return 0;
-            }
-            Comparable cmpB = parent.getSeriesKey(seriesB);
-            if (cmpB == seriesKey
-            || (cmpB != null && cmpB.equals(seriesKey))) {
-                return 1;
-            }
-            return -1;
-        }
-
-        @Override
-        public void addChangeListener(DatasetChangeListener listener) {
-            parent.addChangeListener(listener);
-        }
-
-        @Override
-        public void removeChangeListener(DatasetChangeListener listener) {
-            parent.removeChangeListener(listener);
-        }
-
-        @Override
-        public DatasetGroup getGroup() {
-            return parent.getGroup();
-        }
-
-        @Override
-        public void setGroup(DatasetGroup group) {
-            parent.setGroup(group);
-        }
-
-        @Override
-        public DomainOrder getDomainOrder() {
-            return parent.getDomainOrder();
-        }
-
-        @Override
-        public int getItemCount(int series) {
-            return parent.getItemCount(remap(series));
-        }
-
-        @Override
-        public Number getX(int series, int item) {
-            return parent.getX(remap(series), item);
-        }
-
-        @Override
-        public double getXValue(int series, int item) {
-            return parent.getXValue(remap(series), item);
-        }
-
-        @Override
-        public Number getY(int series, int item) {
-            return parent.getY(remap(series), item);
-        }
-
-        @Override
-        public double getYValue(int series, int item) {
-            return parent.getYValue(remap(series), item);
-        }
-    } // class MappedXYDataset
-
-    public XYDatasetToZeroMapper() {
-    }
-
-    public XYDatasetToZeroMapper(int seriesA) {
-        this(seriesA, seriesA);
-    }
-
-    public XYDatasetToZeroMapper(int seriesA, int seriesB) {
-        this.seriesA = seriesA;
-        this.seriesB = seriesB;
-    }
-
-    public Iterator<XYDataset> iterator(XYDataset dataset) {
-        List<XYDataset> list = new ArrayList<XYDataset>(1);
-        list.add(new MappedXYDataset(dataset));
-        return list.iterator();
-    }
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org