# HG changeset patch # User Felix Wolfsteller # Date 1338902891 0 # Node ID fb07f936b5ad509f05022d35c7d7b098ab5dfa8d # Parent 296b067e17e68069d5c9c3282a6765360e3d1d53 New helper. flys-artifacts/trunk@4584 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 296b067e17e6 -r fb07f936b5ad flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Tue Jun 05 12:35:49 2012 +0000 +++ b/flys-artifacts/ChangeLog Tue Jun 05 13:28:11 2012 +0000 @@ -1,3 +1,8 @@ +2012-06-05 Felix Wolfsteller + + * src/main/java/de/intevation/flys/jfree/JFreeUtil.java: + New jfreechart-related utility class. + 2012-06-05 Felix Wolfsteller * src/main/java/de/intevation/flys/utils/Formatter.java: diff -r 296b067e17e6 -r fb07f936b5ad flys-artifacts/src/main/java/de/intevation/flys/jfree/JFreeUtil.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/JFreeUtil.java Tue Jun 05 13:28:11 2012 +0000 @@ -0,0 +1,41 @@ +package de.intevation.flys.jfree; + +import java.awt.Shape; +import java.awt.geom.Rectangle2D; + +import java.util.Iterator; + +import org.jfree.chart.entity.ChartEntity; +import org.jfree.chart.entity.EntityCollection; + +public class JFreeUtil { + + /** Do not instantiate. */ + private JFreeUtil() { + } + + + /** + * True if \param hotspot collides with a Entity in \param entities. + * @param hotspot Shape to compare against other shapes (bounds only). + * @param entities entities against which to compare shape. + * @param true if a collision (non-zero intersection) exists between + * shapes. + */ + public static boolean collides(Shape hotspot, EntityCollection entities) { + if (entities == null) return false; + + Rectangle2D hotspotBox = hotspot.getBounds2D(); + + for (Iterator i = entities.iterator(); i.hasNext(); ) { + Object next = i.next(); + ChartEntity entity = (ChartEntity) next; + if (entity.getArea().intersects(hotspotBox)) { + // Found collision, early stop. + return true; + } + } + + return false; + } +}