Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/JFreeUtil.java @ 3018:fb07f936b5ad
New helper.
flys-artifacts/trunk@4584 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 05 Jun 2012 13:28:11 +0000 |
parents | |
children | e19ff9086035 |
comparison
equal
deleted
inserted
replaced
3017:296b067e17e6 | 3018:fb07f936b5ad |
---|---|
1 package de.intevation.flys.jfree; | |
2 | |
3 import java.awt.Shape; | |
4 import java.awt.geom.Rectangle2D; | |
5 | |
6 import java.util.Iterator; | |
7 | |
8 import org.jfree.chart.entity.ChartEntity; | |
9 import org.jfree.chart.entity.EntityCollection; | |
10 | |
11 public class JFreeUtil { | |
12 | |
13 /** Do not instantiate. */ | |
14 private JFreeUtil() { | |
15 } | |
16 | |
17 | |
18 /** | |
19 * True if \param hotspot collides with a Entity in \param entities. | |
20 * @param hotspot Shape to compare against other shapes (bounds only). | |
21 * @param entities entities against which to compare shape. | |
22 * @param true if a collision (non-zero intersection) exists between | |
23 * shapes. | |
24 */ | |
25 public static boolean collides(Shape hotspot, EntityCollection entities) { | |
26 if (entities == null) return false; | |
27 | |
28 Rectangle2D hotspotBox = hotspot.getBounds2D(); | |
29 | |
30 for (Iterator i = entities.iterator(); i.hasNext(); ) { | |
31 Object next = i.next(); | |
32 ChartEntity entity = (ChartEntity) next; | |
33 if (entity.getArea().intersects(hotspotBox)) { | |
34 // Found collision, early stop. | |
35 return true; | |
36 } | |
37 } | |
38 | |
39 return false; | |
40 } | |
41 } |