changeset 3175:4616436a84f4

Progressed LegendItemAggregation. flys-artifacts/trunk@4789 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Mon, 25 Jun 2012 18:12:19 +0000
parents 6bde7c90dc93
children cbaa49896eca
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java
diffstat 2 files changed, 30 insertions(+), 76 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon Jun 25 16:33:22 2012 +0000
+++ b/flys-artifacts/ChangeLog	Mon Jun 25 18:12:19 2012 +0000
@@ -1,3 +1,9 @@
+2012-06-25	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/exports/XYChartGenerator.java:
+	  Fix LegendAggregation; prevent single aggregated legend item to
+	  overflow by splitting it into many, but iconless legenditems.
+
 2012-06-25	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/services/FixingsKMChartService.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Mon Jun 25 16:33:22 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Mon Jun 25 18:12:19 2012 +0000
@@ -5,6 +5,7 @@
 import java.awt.Font;
 import java.awt.Paint;
 import java.awt.Stroke;
+import java.awt.geom.Line2D;
 
 import java.text.NumberFormat;
 
@@ -1298,75 +1299,7 @@
 
 
     /**
-     * Create a label for multiple items.
-     *
-     * For example from "W(Q=100)" and "W(Q=220)"
-     * "W(Q= {100, 22})" would result.
-     *
-     * @param items list of legenditems.
-     * @return the merged label.
-     */
-    public String mergeLegendNames(List<LegendItem> items) {
-        if (items.size() == 0) {
-            return null;
-        }
-        if (items.size() == 1) {
-            return items.get(0).getLabel();
-        }
-
-        // TODO consider using regionMathches for implementation.
-        int lastMatchedChar = 0;
-        boolean first = true;
-        String startPattern = "";
-        String endPattern = "";
-        String name = "";
-        // First, figure out beginning and end patterns, then merge.
-        for (LegendItem item : items) {
-            if (first) {
-                startPattern = item.getLabel();
-                endPattern = item.getLabel();
-                first = false;
-                continue;
-            }
-            while (startPattern.length() > 0 && !item.getLabel().startsWith(startPattern)) {
-                startPattern = startPattern.substring(0, startPattern.length() -1);
-            }
-            while (endPattern.length() > 0 && !item.getLabel().endsWith(endPattern)) {
-                endPattern = endPattern.substring(1);
-            }
-        }
-
-        // Then, merge.
-        name = startPattern + " {";
-        first = true;
-        for (LegendItem item : items) {
-            if (!first) {
-                name += ", ";
-            }
-            else {
-                first = false;
-            }
-            // Possible case in differences
-            if (startPattern.length() + endPattern.length() < item.getLabel().length()) {
-                // Note that we do not really want this.
-                logger.error("Legend aggregation does not cover case: " +
-                    startPattern + "  -- " + item.getLabel() + " -- " + endPattern);
-                name += item.getLabel();
-            }
-            else {
-                name += item.getLabel().substring(startPattern.length(),
-                        item.getLabel().length() - endPattern.length());
-            }
-        }
-        name += "} ";
-        name += endPattern;
-
-        return name;
-    }
-
-
-    /**
-     * Create new legend entries, dependant on settings.
+     * Create new legend entries, dependent on settings.
      * @param plot The plot for which to modify the legend.
      */
     public void aggregateLegendEntries(XYPlot plot) {
@@ -1417,13 +1350,28 @@
                 LegendItem item = (LegendItem) itemList.get(0);
                 // Unfortunately we cannot clone and just setDescription, as this
                 // method was added in JFreeChart 1.0.14 (we are at .13).
-                LegendItem merged = new LegendItem(
-                    mergeLegendNames(itemList), item.getDescription(), item.getToolTipText(),
-                    item.getURLText(), item.isShapeVisible(), item.getShape(),
-                    item.isShapeFilled(), item.getFillPaint(), item.isShapeOutlineVisible(),
-                    item.getOutlinePaint(), item.getOutlineStroke(), item.isLineVisible(),
-                    item.getLine(), item.getLineStroke(), item.getLinePaint());
-                newLegend.add(merged);
+
+                // Remove the shapes of all but the first items,
+                // to prevent "overfill" of legenditemblock.
+                for (int i = 0; i < itemList.size(); i++) {
+                    if (i != 0) {
+                        LegendItem litem = itemList.get(i);
+
+                        // TODO Like in D-Flys, define a static "SPACE" shape.
+                        // Make shape and line really small.
+                        LegendItem merged = new LegendItem(
+                            ", " + litem.getLabel(), litem.getDescription(), litem.getToolTipText(),
+                            litem.getURLText(), false, /*litem.getShape()*/ new Line2D.Double(0,0,0,0),
+                            false, litem.getFillPaint(), false,
+                            litem.getOutlinePaint(), litem.getOutlineStroke(), false,
+                            new Line2D.Double(0,0,0,0)
+                            /*litem.getLine()*/, litem.getLineStroke(), litem.getLinePaint());
+                        newLegend.add(merged);
+                    }
+                    else {
+                        newLegend.add(itemList.get(i));
+                    }
+                }
             }
             else {
                 // Do not merge entries.

http://dive4elements.wald.intevation.org