changeset 2652:9d2a06c3a134

Added DataType for lines that also stores width, use it. Added HasLabel interface for some series. flys-artifacts/trunk@4318 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 27 Apr 2012 09:58:21 +0000
parents 9e9eb9d97548
children fa363aac788b
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WaterLineArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/charts/CrossSectionApp.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Lines.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionWaterLineFacet.java flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java flys-artifacts/src/main/java/de/intevation/flys/jfree/HasLabel.java flys-artifacts/src/main/java/de/intevation/flys/jfree/StyledXYSeries.java
diffstat 10 files changed, 110 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Apr 26 15:08:51 2012 +0000
+++ b/flys-artifacts/ChangeLog	Fri Apr 27 09:58:21 2012 +0000
@@ -1,3 +1,32 @@
+2012-04-26	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/geom/Lines.java:
+	  Added local class LineData and return it to also include
+	  Length of lines.
+	
+	* src/main/java/de/intevation/flys/artifacts/WaterLineArtifact.java:
+	  Changed signature of interfaces getWaterLines.
+	
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/model/CrossSectionWaterLineFacet.java:
+	  (getWaterLines): adjusted signature.
+	
+	* src/main/java/de/intevation/flys/artifacts/charts/CrossSectionApp.java:
+	  Adjusted to return type of Lines.createWaterLines.
+	
+	* src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java:
+	  Include length in label (stub).
+
+	* src/main/java/de/intevation/flys/jfree/HasLabel.java:
+	  New interface.
+	
+	* src/main/java/de/intevation/flys/jfree/StyledXYSeries.java:
+	  Implement new HasLabel interface.
+	
+	* src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java:
+	  Take into account that StyledXYSeries are HasLabel.
+
 2012-04-26  Raimund Renkert <raimund.renkert@intevation.de>
 
 	Initial transition configuration and artifact/state stubs for fixation
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java	Thu Apr 26 15:08:51 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java	Fri Apr 27 09:58:21 2012 +0000
@@ -258,7 +258,7 @@
      *         in the form {{x1, x2} {y1, y2}} ).
      */
     @Override
-    public double [][] getWaterLines(int idx, FastCrossSectionLine csl) {
+    public Lines.LineData getWaterLines(int idx, FastCrossSectionLine csl) {
         logger.debug("getWaterLines(" + idx + ")");
 
         List<Point2D> points = csl.getPoints();
@@ -271,7 +271,7 @@
         double wAtKm = getWAtKm(wkms, km);
         if (wAtKm == -1) {
             logger.warn("Waterlevel at km " + km + " unknown.");
-            return new double[][] {{}};
+            return new Lines.LineData(new double[][] {{}}, 0d);
         }
 
         return Lines.createWaterLines(points, wAtKm);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Thu Apr 26 15:08:51 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Fri Apr 27 09:58:21 2012 +0000
@@ -770,7 +770,8 @@
      * @return an array holding coordinates of points of surface of water (
      *         in the form {{x1, x2} {y1, y2}} ).
      */
-    public double [][] getWaterLines(int idx, FastCrossSectionLine csl) {
+    @Override
+    public Lines.LineData getWaterLines(int idx, FastCrossSectionLine csl) {
         logger.debug("getWaterLines(" + idx + ")");
 
         List<Point2D> points = csl.getPoints();
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WaterLineArtifact.java	Thu Apr 26 15:08:51 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WaterLineArtifact.java	Fri Apr 27 09:58:21 2012 +0000
@@ -1,5 +1,6 @@
 package de.intevation.flys.artifacts;
 
+import de.intevation.flys.geom.Lines;
 
 import de.intevation.flys.model.FastCrossSectionLine;
 /**
@@ -9,6 +10,6 @@
 
     /** Get points that define a line of a (water)facet against a cross-
      * section. */
-    public double [][] getWaterLines(int facetIdx, FastCrossSectionLine csl);
+    public Lines.LineData getWaterLines(int facetIdx, FastCrossSectionLine csl);
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/charts/CrossSectionApp.java	Thu Apr 26 15:08:51 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/charts/CrossSectionApp.java	Fri Apr 27 09:58:21 2012 +0000
@@ -474,7 +474,7 @@
             return;
         }
 
-        double [][] data = Lines.createWaterLines(points, lastWaterLevel);
+        double [][] data = Lines.createWaterLines(points, lastWaterLevel).points;
         XYSeries series =
             new XYSeries(String.valueOf(lastWaterLevel), false);
 
@@ -497,7 +497,7 @@
             return;
         }
 
-        double [][] data   = Lines.createWaterLines(points, lastWaterLevel);
+        double [][] data   = Lines.createWaterLines(points, lastWaterLevel).points;
         double [][] values = CrossSectionLine.fetchCrossSectionProfile(points);
 
         DefaultXYDataset dataset = new DefaultXYDataset();
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Lines.java	Thu Apr 26 15:08:51 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Lines.java	Fri Apr 27 09:58:21 2012 +0000
@@ -13,6 +13,9 @@
 
 import gnu.trove.TDoubleArrayList;
 
+/**
+ * Utility to create lines (intersect water with cross-section etc).
+ */
 public class Lines
 {
     private static Logger log = Logger.getLogger(Lines.class);
@@ -24,6 +27,9 @@
     protected Lines() {
     }
 
+    /**
+     * Calculate the 'length' of the given lines.
+     */
     public static double length(List<Line2D> lines) {
         double sum = 0d;
         for (Line2D line: lines) {
@@ -261,7 +267,21 @@
         return result;
     }
 
-    public static double [][] createWaterLines(
+
+    /**
+     * Class holding points that form lines and the calculated length.
+     */
+    public static class LineData {
+        public double [][] points;
+        public double width;
+        public LineData(double[][] points, double width) {
+            this.points = points;
+            this.width = width;
+        }
+    }
+
+
+    public static LineData createWaterLines(
         List<Point2D> points,
         double        waterlevel
     ) {
@@ -269,22 +289,32 @@
 
         TDoubleArrayList lxs = new TDoubleArrayList();
         TDoubleArrayList lys = new TDoubleArrayList();
+        double linesLength = 0.0f;
 
         for (Iterator<Line2D> iter = lines.iterator(); iter.hasNext();) {
-            Line2D  l  = iter.next();
-            Point2D p1 = l.getP1();
-            Point2D p2 = l.getP2();
+            Line2D  line = iter.next();
+            Point2D p1   = line.getP1();
+            Point2D p2   = line.getP2();
             lxs.add(p1.getX());
             lys.add(p1.getY());
             lxs.add(p2.getX());
             lys.add(p2.getY());
+
+            // Length calculation.
+            double xDiff = line.getX1() - line.getX2();
+            double yDiff = line.getY1() - line.getY2();
+            linesLength += Math.sqrt(xDiff*xDiff + yDiff*yDiff);
+
             if (iter.hasNext()) {
                 lxs.add(Double.NaN);
                 lys.add(Double.NaN);
             }
         }
 
-        return new double [][] { lxs.toNativeArray(), lys.toNativeArray() };
+        return new LineData(
+            new double [][] { lxs.toNativeArray(), lys.toNativeArray() },
+            linesLength
+            );
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionWaterLineFacet.java	Thu Apr 26 15:08:51 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionWaterLineFacet.java	Fri Apr 27 09:58:21 2012 +0000
@@ -14,6 +14,8 @@
 
 import de.intevation.flys.model.FastCrossSectionLine;
 
+import de.intevation.flys.geom.Lines;
+
 /**
  * Facet for Waterlines in Cross Sections.
  */
@@ -40,7 +42,7 @@
             getDataProvider(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA);
         if (providers.size() < 1) {
             logger.warn("Could not find Cross-Section data provider.");
-            return new double[][] {};
+            return new Lines.LineData(new double[][] {}, 0d);
         }
         
         Object crossSection = providers.get(0)
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java	Thu Apr 26 15:08:51 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java	Fri Apr 27 09:58:21 2012 +0000
@@ -23,6 +23,8 @@
 import de.intevation.flys.model.FastCrossSectionLine;
 import de.intevation.flys.artifacts.model.HYKFactory;
 
+import de.intevation.flys.geom.Lines;
+
 
 /**
  * An OutGenerator that generates cross section graphs.
@@ -216,10 +218,14 @@
     ) {
         logger.debug("CrossSectionGenerator.doCrossSectionWaterLineOut");
 
+        Lines.LineData lines = (Lines.LineData) o;
         // DO NOT SORT DATA! This destroys the gaps indicated by NaNs
-        XYSeries series = new StyledXYSeries(seriesName, false, theme);
+        StyledXYSeries series = new StyledXYSeries(seriesName, false, theme);
+        // TODO Label for line with infos if wished.
 
-        StyledSeriesBuilder.addPoints(series, (double [][]) o);
+        series.setLabel(series.getLabel() + lines.width);
+        
+        StyledSeriesBuilder.addPoints(series, lines.points);
 
         addAxisSeries(series, 0, visible);
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/HasLabel.java	Fri Apr 27 09:58:21 2012 +0000
@@ -0,0 +1,8 @@
+package de.intevation.flys.jfree;
+
+public interface HasLabel {
+    public String getLabel();
+    public void setLabel(String label);
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
+
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/StyledXYSeries.java	Thu Apr 26 15:08:51 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/StyledXYSeries.java	Fri Apr 27 09:58:21 2012 +0000
@@ -7,19 +7,25 @@
 
 import org.jfree.data.xy.XYSeries;
 
+import de.intevation.flys.jfree.HasLabel;
+
 
 /**
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
-public class StyledXYSeries extends XYSeries implements StyledSeries {
+public class StyledXYSeries extends XYSeries implements StyledSeries, HasLabel {
 
     private static final Logger logger = Logger.getLogger(StyledXYSeries.class);
 
     protected Style style;
 
+    /** If this Series is to be labelled, use this String as label. */
+    protected String label;
+
 
     public StyledXYSeries(String key, Document theme) {
         this(key, true, theme);
+        this.label = key.toString();
     }
 
 
@@ -31,6 +37,7 @@
     public StyledXYSeries(String key, boolean sorted, Document theme) {
         super(key, sorted);
         setStyle(new XYStyle(theme));
+        this.label = key.toString();
     }
 
 
@@ -44,5 +51,16 @@
     public Style getStyle() {
         return style;
     }
+
+    
+    @Override
+    public String getLabel() {
+        return label;
+    }
+
+    @Override
+    public void setLabel(String label) {
+        this.label = label;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org