Mercurial > dive4elements > river
changeset 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 | 9b5541dcc01f |
children | bf134f4c0be1 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/jfree/CollisionFreeXYTextAnnotation.java flys-artifacts/src/main/java/de/intevation/flys/jfree/CollisionFreeXYTextAnnotationEntity.java |
diffstat | 3 files changed, 64 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Thu Feb 09 13:28:57 2012 +0000 +++ b/flys-artifacts/ChangeLog Thu Feb 09 13:45:26 2012 +0000 @@ -1,3 +1,15 @@ +2012-02-09 Felix Wolfsteller <felix.wolfsteller@intevation.de> + + Fix flys/issue490. Allow CollisionFree..Annotations to collide with + non-collision-free annotations. + + * src/main/java/de/intevation/flys/jfree/CollisionFreeXYTextAnnotationEntity.java: + New, to take advantage of cheap instanceof operator. + + * src/main/java/de/intevation/flys/jfree/CollisionFreeXYTextAnnotation.java: + Only avoid collisions with members of same family (i.e. allow + collision with annotations of other types). + 2012-02-09 Ingo Weinzierl <ingo@intevation.de> * doc/conf/themes.xml: Added themes for historical discharge curves and
--- 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 :
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/CollisionFreeXYTextAnnotationEntity.java Thu Feb 09 13:45:26 2012 +0000 @@ -0,0 +1,19 @@ +package de.intevation.flys.jfree; + +import java.awt.Shape; + +import org.jfree.chart.entity.XYAnnotationEntity; + + +public class CollisionFreeXYTextAnnotationEntity +extends XYAnnotationEntity { + public CollisionFreeXYTextAnnotationEntity( + Shape hotspot, + int rendererIndex, + String toolTip, + String url + ) { + super(hotspot, rendererIndex, toolTip, url); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :