diff flys-artifacts/src/main/java/de/intevation/flys/jfree/CollisionFreeXYTextAnnotation.java @ 2318:0b8c04c7f762

Avoid that annotations like the ones used for hyks prevent manual point text annotation rendering. flys-artifacts/trunk@3999 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 09 Feb 2012 13:45:26 +0000
parents c68f4f227c09
children e19ff9086035
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/CollisionFreeXYTextAnnotation.java	Thu Feb 09 13:28:57 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/CollisionFreeXYTextAnnotation.java	Thu Feb 09 13:45:26 2012 +0000
@@ -7,6 +7,7 @@
 import java.awt.Shape;
 import java.awt.geom.Rectangle2D;
 
+import org.jfree.chart.entity.EntityCollection;
 import org.jfree.chart.annotations.XYTextAnnotation;
 import org.jfree.chart.axis.ValueAxis;
 import org.jfree.chart.plot.PlotOrientation;
@@ -90,7 +91,7 @@
                 i.hasNext(); ) {
             Object next = i.next();
             // Collision with other stuff than XYAnnotations are okay.
-            if (next instanceof XYAnnotationEntity) {
+            if (next instanceof CollisionFreeXYTextAnnotationEntity) {
                 XYAnnotationEntity drawnShape = (XYAnnotationEntity) next;
                 if (drawnShape.getArea().intersects(hotspotBox)) {
                     // Found collision, early stop.
@@ -112,8 +113,11 @@
             g2.draw(hotspot);
         }
 
-        String toolTip = getToolTipText();
-        String url = getURL();
+        //String toolTip = getToolTipText();
+        //String url = getURL();
+        String toolTip = "CollisionFreeXYTextAnnotation";
+        String url     = toolTip;
+
         if (toolTip != null || url != null) {
             addEntity(info, hotspot, rendererIndex, toolTip, url);
         }
@@ -123,5 +127,31 @@
                 "CollisionFreeXYTextAnnotation");
         }
     }
+
+    /**
+     * A utility method for adding an {@link CollisionFreeXYAnnotationEntity} to
+     * a {@link PlotRenderingInfo} instance.
+     *
+     * @param info  the plot rendering info (<code>null</code> permitted).
+     * @param hotspot  the hotspot area.
+     * @param rendererIndex  the renderer index.
+     * @param toolTipText  the tool tip text.
+     * @param urlText  the URL text.
+     */
+    protected void addEntity(PlotRenderingInfo info,
+                             Shape hotspot, int rendererIndex,
+                             String toolTipText, String urlText) {
+        if (info == null) {
+            return;
+        }
+        EntityCollection entities = info.getOwner().getEntityCollection();
+        if (entities == null) {
+            return;
+        }
+        CollisionFreeXYTextAnnotationEntity entity =
+            new CollisionFreeXYTextAnnotationEntity(hotspot,
+                rendererIndex, toolTipText, urlText);
+        entities.add(entity);
+    } 
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org