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