Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/jfree/JFreeUtil.java @ 3060:94d78e0dc5e9
Removed superfluous imports.
flys-artifacts/trunk@4639 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 11 Jun 2012 14:55:03 +0000 |
parents | e19ff9086035 |
children | 5642a83420f2 |
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. |
3023
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
22 * @param exclusiveEntityClass If not null, consider only entities of |
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
23 * given class. |
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
24 * @return true if a collision (non-zero intersection) exists between |
3018
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
25 * shapes. |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
26 */ |
3023
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
27 public static boolean collides(Shape hotspot, EntityCollection entities, |
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
28 Class exclusiveEntityClass) { |
3018
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
29 if (entities == null) return false; |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
30 |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
31 Rectangle2D hotspotBox = hotspot.getBounds2D(); |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
32 |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
33 for (Iterator i = entities.iterator(); i.hasNext(); ) { |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
34 Object next = i.next(); |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
35 ChartEntity entity = (ChartEntity) next; |
3023
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
36 if (exclusiveEntityClass == null |
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
37 || exclusiveEntityClass.isInstance(entity)) |
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
38 { |
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
39 if (entity.getArea().intersects(hotspotBox)) { |
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
40 // Found collision, early stop. |
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
41 return true; |
e19ff9086035
Avoid collisions between line labels.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3018
diff
changeset
|
42 } |
3018
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
43 } |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
44 } |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
45 |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
46 return false; |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
47 } |
fb07f936b5ad
New helper.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
48 } |