comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/CollisionFreeXYTextAnnotation.java @ 3023:e19ff9086035

Avoid collisions between line labels. flys-artifacts/trunk@4590 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 05 Jun 2012 15:03:11 +0000
parents 0b8c04c7f762
children 65b6e27c6f25
comparison
equal deleted inserted replaced
3022:705d2058b682 3023:e19ff9086035
17 import org.jfree.chart.plot.Plot; 17 import org.jfree.chart.plot.Plot;
18 18
19 import org.jfree.text.TextUtilities; 19 import org.jfree.text.TextUtilities;
20 20
21 import org.jfree.ui.RectangleEdge; 21 import org.jfree.ui.RectangleEdge;
22
23 import de.intevation.flys.jfree.JFreeUtil;
22 24
23 25
24 /** 26 /**
25 * Custom Annotations class that is drawn only if no collisions with other 27 * Custom Annotations class that is drawn only if no collisions with other
26 * already drawn CustomAnnotations in current plot are found. 28 * already drawn CustomAnnotations in current plot are found.
85 getRotationAngle(), getRotationAnchor()); 87 getRotationAngle(), getRotationAnchor());
86 88
87 // Deviation from superclass: prevent collision. 89 // Deviation from superclass: prevent collision.
88 Rectangle2D hotspotBox = hotspot.getBounds2D(); 90 Rectangle2D hotspotBox = hotspot.getBounds2D();
89 91
90 for (Iterator i = info.getOwner().getEntityCollection().iterator(); 92 if (JFreeUtil.collides(hotspot, info.getOwner().getEntityCollection(),
91 i.hasNext(); ) { 93 XYAnnotationEntity.class)) {
92 Object next = i.next(); 94 return;
93 // Collision with other stuff than XYAnnotations are okay.
94 if (next instanceof CollisionFreeXYTextAnnotationEntity) {
95 XYAnnotationEntity drawnShape = (XYAnnotationEntity) next;
96 if (drawnShape.getArea().intersects(hotspotBox)) {
97 // Found collision, early stop.
98 return;
99 }
100 }
101 } 95 }
102 96
103 if (this.getBackgroundPaint() != null) { 97 if (this.getBackgroundPaint() != null) {
104 g2.setPaint(this.getBackgroundPaint()); 98 g2.setPaint(this.getBackgroundPaint());
105 g2.fill(hotspot); 99 g2.fill(hotspot);

http://dive4elements.wald.intevation.org