comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/CollisionFreeXYTextAnnotation.java @ 2318:0b8c04c7f762

Avoid that annotations like the ones used for hyks prevent manual point text annotation rendering. flys-artifacts/trunk@3999 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 09 Feb 2012 13:45:26 +0000
parents c68f4f227c09
children e19ff9086035
comparison
equal deleted inserted replaced
2317:9b5541dcc01f 2318:0b8c04c7f762
5 import java.util.Iterator; 5 import java.util.Iterator;
6 6
7 import java.awt.Shape; 7 import java.awt.Shape;
8 import java.awt.geom.Rectangle2D; 8 import java.awt.geom.Rectangle2D;
9 9
10 import org.jfree.chart.entity.EntityCollection;
10 import org.jfree.chart.annotations.XYTextAnnotation; 11 import org.jfree.chart.annotations.XYTextAnnotation;
11 import org.jfree.chart.axis.ValueAxis; 12 import org.jfree.chart.axis.ValueAxis;
12 import org.jfree.chart.plot.PlotOrientation; 13 import org.jfree.chart.plot.PlotOrientation;
13 import org.jfree.chart.plot.XYPlot; 14 import org.jfree.chart.plot.XYPlot;
14 import org.jfree.chart.entity.XYAnnotationEntity; 15 import org.jfree.chart.entity.XYAnnotationEntity;
88 89
89 for (Iterator i = info.getOwner().getEntityCollection().iterator(); 90 for (Iterator i = info.getOwner().getEntityCollection().iterator();
90 i.hasNext(); ) { 91 i.hasNext(); ) {
91 Object next = i.next(); 92 Object next = i.next();
92 // Collision with other stuff than XYAnnotations are okay. 93 // Collision with other stuff than XYAnnotations are okay.
93 if (next instanceof XYAnnotationEntity) { 94 if (next instanceof CollisionFreeXYTextAnnotationEntity) {
94 XYAnnotationEntity drawnShape = (XYAnnotationEntity) next; 95 XYAnnotationEntity drawnShape = (XYAnnotationEntity) next;
95 if (drawnShape.getArea().intersects(hotspotBox)) { 96 if (drawnShape.getArea().intersects(hotspotBox)) {
96 // Found collision, early stop. 97 // Found collision, early stop.
97 return; 98 return;
98 } 99 }
110 g2.setStroke(this.getOutlineStroke()); 111 g2.setStroke(this.getOutlineStroke());
111 g2.setPaint(this.getOutlinePaint()); 112 g2.setPaint(this.getOutlinePaint());
112 g2.draw(hotspot); 113 g2.draw(hotspot);
113 } 114 }
114 115
115 String toolTip = getToolTipText(); 116 //String toolTip = getToolTipText();
116 String url = getURL(); 117 //String url = getURL();
118 String toolTip = "CollisionFreeXYTextAnnotation";
119 String url = toolTip;
120
117 if (toolTip != null || url != null) { 121 if (toolTip != null || url != null) {
118 addEntity(info, hotspot, rendererIndex, toolTip, url); 122 addEntity(info, hotspot, rendererIndex, toolTip, url);
119 } 123 }
120 else { 124 else {
121 addEntity(info, hotspot, rendererIndex, 125 addEntity(info, hotspot, rendererIndex,
122 "CollisionFreeXYTextAnnotation", 126 "CollisionFreeXYTextAnnotation",
123 "CollisionFreeXYTextAnnotation"); 127 "CollisionFreeXYTextAnnotation");
124 } 128 }
125 } 129 }
130
131 /**
132 * A utility method for adding an {@link CollisionFreeXYAnnotationEntity} to
133 * a {@link PlotRenderingInfo} instance.
134 *
135 * @param info the plot rendering info (<code>null</code> permitted).
136 * @param hotspot the hotspot area.
137 * @param rendererIndex the renderer index.
138 * @param toolTipText the tool tip text.
139 * @param urlText the URL text.
140 */
141 protected void addEntity(PlotRenderingInfo info,
142 Shape hotspot, int rendererIndex,
143 String toolTipText, String urlText) {
144 if (info == null) {
145 return;
146 }
147 EntityCollection entities = info.getOwner().getEntityCollection();
148 if (entities == null) {
149 return;
150 }
151 CollisionFreeXYTextAnnotationEntity entity =
152 new CollisionFreeXYTextAnnotationEntity(hotspot,
153 rendererIndex, toolTipText, urlText);
154 entities.add(entity);
155 }
126 } 156 }
127 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 157 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org