changeset 1677:dd9dfe1e48fa

Bugfixes for various issues: Improved rendering process of annotations. flys-artifacts/trunk@2894 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 05 Oct 2011 11:23:18 +0000
parents 6e840e213fdf
children 03fbf1b30e72
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/AnnotationFacet.java flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java flys-artifacts/src/main/java/de/intevation/flys/jfree/FLYSAnnotation.java
diffstat 4 files changed, 110 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Oct 05 10:36:40 2011 +0000
+++ b/flys-artifacts/ChangeLog	Wed Oct 05 11:23:18 2011 +0000
@@ -1,4 +1,27 @@
-2011-10-04	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+2011-10-05  Ingo Weinzierl <ingo@intevation.de>
+
+	flys/issue347 (W-INFO / Wasserspiegellagenberechnung, Längsschnittdiagramm)
+	flys/issue303 (Keine Streckenfavoriten, wenn nur Q im Längsschnittdiagram ausgewählt)
+	flys/issue353 (W-INFO / Wasserspiegellagenberechnung, Diagramm)
+
+	* src/main/java/de/intevation/flys/jfree/FLYSAnnotation.java: New. A
+	  wrapper for Annotations which allows us to provide a description for a
+	  set of annotations.
+
+	* src/main/java/de/intevation/flys/artifacts/model/AnnotationFacet.java:
+	  The getData() will now return an instance of FLYSAnnotation that wraps
+	  the Annotations returned by the AnnotationArtifact. The lebel of
+	  FLYSAnnotation is the description of this Facet.
+
+	* src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java:
+	  Modified the way to add Annotations. We will no longer create an empty
+	  series to support a LegendItem for a set of Annotations, but we will add
+	  a LegendItem manually to the LegendItemCollection of the plot. In
+	  addition, we are now able to display annotations if one of the two
+	  y-axes are missing. If there are no y-axes existing, we are not able to
+	  display annotations yet.
+
+2011-10-05	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java:
 	  Lifted the wrong point. Now all backjump corrections look fine. :-)
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/AnnotationFacet.java	Wed Oct 05 10:36:40 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/AnnotationFacet.java	Wed Oct 05 11:23:18 2011 +0000
@@ -1,11 +1,16 @@
 package de.intevation.flys.artifacts.model;
 
+import java.util.List;
+
 import org.apache.log4j.Logger;
 
 import de.intevation.artifacts.Artifact;
 import de.intevation.artifacts.CallContext;
 
 import de.intevation.flys.artifacts.AnnotationArtifact;
+import de.intevation.flys.jfree.FLYSAnnotation;
+
+import de.intevation.flys.model.Annotation;
 
 import de.intevation.artifactdatabase.state.DefaultFacet;
 import de.intevation.artifactdatabase.state.Facet;
@@ -48,7 +53,9 @@
     @Override
     public Object getData(Artifact artifact, CallContext context) {
         AnnotationArtifact annotationArtifact = (AnnotationArtifact) artifact;
-        return annotationArtifact.getAnnotations();
+        List<Annotation> annotations = annotationArtifact.getAnnotations();
+
+        return new FLYSAnnotation(description, annotations);
     }
 
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Wed Oct 05 10:36:40 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Wed Oct 05 11:23:18 2011 +0000
@@ -6,13 +6,14 @@
 import org.apache.log4j.Logger;
 
 import org.jfree.chart.JFreeChart;
+import org.jfree.chart.LegendItem;
+import org.jfree.chart.LegendItemCollection;
 import org.jfree.chart.axis.NumberAxis;
 import org.jfree.chart.axis.ValueAxis;
 import org.jfree.chart.plot.XYPlot;
 import org.jfree.chart.title.TextTitle;
 import org.jfree.data.Range;
 import org.jfree.data.xy.XYSeries;
-import org.jfree.data.xy.XYSeriesCollection;
 import org.jfree.ui.TextAnchor;
 
 import org.w3c.dom.Document;
@@ -26,6 +27,7 @@
 import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.model.WQKms;
 
+import de.intevation.flys.jfree.FLYSAnnotation;
 import de.intevation.flys.jfree.StickyAxisAnnotation;
 import de.intevation.flys.model.Annotation;
 import de.intevation.flys.utils.FLYSUtils;
@@ -71,15 +73,12 @@
     protected boolean inverted;
 
     /** List of annotations to insert in plot. */
-    protected List<Annotation> annotations;
-
-    /** Pseudo-Dataseries to have a legend for the annotations. */
-    protected XYSeriesCollection pseudoAnnotationData = null;
+    protected List<FLYSAnnotation> annotations;
 
 
     public LongitudinalSectionGenerator() {
         super();
-        annotations = new ArrayList<Annotation>();
+        annotations = new ArrayList<FLYSAnnotation>();
     }
 
 
@@ -165,27 +164,53 @@
         plot.clearAnnotations();
         // TODO Position calculation could/should be done in
         // the StickyAxisAnnotation-Implementation itself.
-        ValueAxis yAxis = plot.getRangeAxis();
+
+        int idx = 0;
+        ValueAxis yAxis = plot.getRangeAxis(idx);
+
+        if (yAxis == null) {
+            if (plot.getRangeAxisCount() >= 2) {
+                yAxis = plot.getRangeAxis(++idx);
+            }
+        }
+
+        if (yAxis == null) {
+            // XXX There is no y-axis that might be used to add annotations. If
+            // we absolutely want to display annotations, we need to create a
+            // virtual dataset for an axis.
+            return;
+        }
+
         float posY = 140.f;
-        if (yAxis != null) {
-            posY = (float) yAxis.getRange().getLowerBound();
-            // Add some (2%) space between Text and axis.
-            posY += 0.02f * (yAxis.getRange().getUpperBound()
-                    - yAxis.getRange().getLowerBound());
-        }
+        posY = (float) yAxis.getRange().getLowerBound();
+        // Add some (2%) space between Text and axis.
+        posY += 0.02f * (yAxis.getRange().getUpperBound()
+                - yAxis.getRange().getLowerBound());
+
+        LegendItemCollection lic = plot.getLegendItems();
 
         // Add all annotations.
-        for (Annotation a: annotations) {
-            float posX = (float) a.getRange().getA().doubleValue();
-            String text = a.getPosition().getValue();
+        for (FLYSAnnotation fa: annotations) {
+            lic.add(new LegendItem(fa.getLabel()));
 
-            StickyAxisAnnotation ta = new StickyAxisAnnotation(text, posX, posY);
-            double rotation = 270.0f * (Math.PI / 180.0f);
-            ta.setRotationAngle(rotation);
-            ta.setRotationAnchor(TextAnchor.CENTER_LEFT);
-            ta.setTextAnchor(TextAnchor.CENTER_LEFT);
-            plot.getRenderer().addAnnotation(ta);
+            for (Annotation a: fa.getAnnotations()) {
+                float posX = (float) a.getRange().getA().doubleValue();
+                String text = a.getPosition().getValue();
+
+                StickyAxisAnnotation ta = new StickyAxisAnnotation(
+                    text,
+                    posX,
+                    posY);
+
+                double rotation = 270.0f * (Math.PI / 180.0f);
+                ta.setRotationAngle(rotation);
+                ta.setRotationAnchor(TextAnchor.CENTER_LEFT);
+                ta.setTextAnchor(TextAnchor.CENTER_LEFT);
+                plot.getRenderer(idx).addAnnotation(ta);
+            }
         }
+
+        plot.setFixedLegendItems(lic);
     }
 
 
@@ -271,16 +296,10 @@
      */
     protected void doAnnotationsOut(Object o, Document theme) {
         logger.debug("LongitudinalSectionGenerator.doAnnotationsOut");
-        this.annotations = (List<Annotation>) o;
 
-        // Add (empty) pseudo series to have legend entry for annotations.
-        if (pseudoAnnotationData == null) {
-            pseudoAnnotationData = new XYSeriesCollection();
-        }
-        // Localized legend.
-        Object[] args = new Object[] {getRiverName()};
-        String label = msg(I18N_ANNOTATIONS_LABEL, "", args);
-        pseudoAnnotationData.addSeries(new StyledXYSeries(label, theme));
+        // Add all annotations in list o to our annotation pool.
+        FLYSAnnotation fa = (FLYSAnnotation) o;
+        annotations.add(fa);
     }
 
 
@@ -353,19 +372,6 @@
 
 
     /**
-     * Add datasets to plot.
-     * @param plot plot to add datasets to.
-     */
-    @Override
-    protected void addDatasets(XYPlot plot) {
-        super.addDatasets(plot);
-        if (pseudoAnnotationData != null) {
-            plot.setDataset(2, pseudoAnnotationData);
-        }
-    }
-
-
-    /**
      * Get name of series (displayed in legend).
      * @return name of the series.
      */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/FLYSAnnotation.java	Wed Oct 05 11:23:18 2011 +0000
@@ -0,0 +1,28 @@
+package de.intevation.flys.jfree;
+
+import java.util.List;
+
+import de.intevation.flys.model.Annotation;
+
+
+public class FLYSAnnotation {
+
+    protected List<Annotation> annotations;
+
+    protected String label;
+
+
+    public FLYSAnnotation(String label, List<Annotation> annotations) {
+        this.label       = label;
+        this.annotations = annotations;
+    }
+
+    public String getLabel() {
+        return label;
+    }
+
+    public List<Annotation> getAnnotations() {
+        return annotations;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org