Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/jfree/CollisionFreeXYTextAnnotation.java @ 3785:a5f65e8983be
Merged revisions 5501-5502,5504-5508,5511-5513,5516-5519 via svnmerge from
file:///home/clients/bsh/bsh-generischer-viewer/Material/SVN/flys-artifacts/trunk
........
r5501 | felix | 2012-09-18 11:49:45 +0200 (Di, 18 Sep 2012) | 1 line
fix issue865 - missing showarea theme prop.
........
r5502 | clins | 2012-09-18 12:18:30 +0200 (Di, 18 Sep 2012) | 1 line
Add robustness checks to prevent NPEs
........
r5504 | felix | 2012-09-18 14:03:15 +0200 (Di, 18 Sep 2012) | 1 line
i18n for area label (fix issue487).
........
r5505 | clins | 2012-09-18 16:19:59 +0200 (Di, 18 Sep 2012) | 1 line
Update themes to show point descriptions
........
r5506 | rrenkert | 2012-09-18 17:00:30 +0200 (Di, 18 Sep 2012) | 3 lines
Removed incorrect characteristic diameter.
........
r5507 | rrenkert | 2012-09-18 17:03:20 +0200 (Di, 18 Sep 2012) | 3 lines
Fixed some stupid bugs in bed quality data factory and calculation.
........
r5508 | teichmann | 2012-09-18 17:45:49 +0200 (Di, 18 Sep 2012) | 1 line
The usual whitespace and import cleanups.
........
r5511 | teichmann | 2012-09-18 18:24:51 +0200 (Di, 18 Sep 2012) | 1 line
Use generics aware Collections.emptyList().
........
r5512 | teichmann | 2012-09-18 20:36:52 +0200 (Di, 18 Sep 2012) | 1 line
Some more little steps towards "Auslagerung extremer Wasserspiegellagen".
........
r5513 | clins | 2012-09-18 23:38:19 +0200 (Di, 18 Sep 2012) | 1 line
A and B facets of fix analyis are now deactivated by default
........
r5516 | bricks | 2012-09-19 10:45:51 +0200 (Mi, 19 Sep 2012) | 2 lines
Add the gauge station to the GaugeOverviewInfoService xml response
........
r5517 | rrenkert | 2012-09-19 10:50:23 +0200 (Mi, 19 Sep 2012) | 3 lines
Added CSV export to bed quality calculation.
........
r5518 | bricks | 2012-09-19 11:04:04 +0200 (Mi, 19 Sep 2012) | 2 lines
Fix date in changelog entry
........
r5519 | teichmann | 2012-09-19 11:17:14 +0200 (Mi, 19 Sep 2012) | 1 line
Removed trailing whitespace.
........
flys-artifacts/tags/2.9.1@5531 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 19 Sep 2012 14:58:31 +0000 |
parents | 0f7abd95c6e2 |
children | 6ed8ebd48d6e |
line wrap: on
line source
package de.intevation.flys.jfree; import org.apache.log4j.Logger; import java.awt.Shape; import java.awt.geom.Rectangle2D; import org.jfree.chart.entity.EntityCollection; import org.jfree.chart.annotations.XYTextAnnotation; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.entity.XYAnnotationEntity; import org.jfree.chart.plot.PlotRenderingInfo; import org.jfree.chart.plot.Plot; import org.jfree.text.TextUtilities; import org.jfree.ui.RectangleEdge; /** * Custom Annotations class that is drawn only if no collisions with other * already drawn CustomAnnotations in current plot are found. */ public class CollisionFreeXYTextAnnotation extends XYTextAnnotation { /** Logger for this class. */ private static Logger logger = Logger.getLogger(CollisionFreeXYTextAnnotation.class); public CollisionFreeXYTextAnnotation(String text, double x, double y) { super(text, x, y); } /** * Draw the Annotation only if it does not collide with other * already drawn Annotations- texts. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the render index. * @param info state information, escpecially collects info about * already drawn shapes (and thus annotations), used * for collision detection. */ @Override public void draw( java.awt.Graphics2D g2, XYPlot plot, java.awt.geom.Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info ) { // From superclass, adjusted access only. PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( plot.getRangeAxisLocation(), orientation); float anchorX = (float) domainAxis.valueToJava2D( this.getX(), dataArea, domainEdge); float anchorY = (float) rangeAxis.valueToJava2D( this.getY(), dataArea, rangeEdge); if (orientation == PlotOrientation.HORIZONTAL) { float tempAnchor = anchorX; anchorX = anchorY; anchorY = tempAnchor; } g2.setFont(getFont()); Shape hotspot = TextUtilities.calculateRotatedStringBounds( getText(), g2, anchorX, anchorY, getTextAnchor(), getRotationAngle(), getRotationAnchor()); // Deviation from superclass: prevent collision. Rectangle2D hotspotBox = hotspot.getBounds2D(); if (JFreeUtil.collides(hotspot, info.getOwner().getEntityCollection(), XYAnnotationEntity.class)) { return; } if (this.getBackgroundPaint() != null) { g2.setPaint(this.getBackgroundPaint()); g2.fill(hotspot); } g2.setPaint(getPaint()); TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY, getTextAnchor(), getRotationAngle(), getRotationAnchor()); if (this.isOutlineVisible()) { g2.setStroke(this.getOutlineStroke()); g2.setPaint(this.getOutlinePaint()); g2.draw(hotspot); } //String toolTip = getToolTipText(); //String url = getURL(); String toolTip = "CollisionFreeXYTextAnnotation"; String url = toolTip; if (toolTip != null || url != null) { addEntity(info, hotspot, rendererIndex, toolTip, url); } else { addEntity(info, hotspot, rendererIndex, "CollisionFreeXYTextAnnotation", "CollisionFreeXYTextAnnotation"); } } /** * A utility method for adding an {@link CollisionFreeXYAnnotationEntity} to * a {@link PlotRenderingInfo} instance. * * @param info the plot rendering info (<code>null</code> permitted). * @param hotspot the hotspot area. * @param rendererIndex the renderer index. * @param toolTipText the tool tip text. * @param urlText the URL text. */ protected void addEntity(PlotRenderingInfo info, Shape hotspot, int rendererIndex, String toolTipText, String urlText) { if (info == null) { return; } EntityCollection entities = info.getOwner().getEntityCollection(); if (entities == null) { return; } CollisionFreeXYTextAnnotationEntity entity = new CollisionFreeXYTextAnnotationEntity(hotspot, rendererIndex, toolTipText, urlText); entities.add(entity); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :