view flys-artifacts/src/main/java/de/intevation/flys/jfree/JFreeUtil.java @ 3034:842502b3913a

JFreeChart: Added adapter class to bridge de.intevation.flys.artifacts.math.Function to org.jfree.data.function.Function2D. flys-artifacts/trunk@4603 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 06 Jun 2012 10:26:28 +0000
parents e19ff9086035
children 5642a83420f2
line wrap: on
line source
package de.intevation.flys.jfree;

import java.awt.Shape;
import java.awt.geom.Rectangle2D;

import java.util.Iterator;

import org.jfree.chart.entity.ChartEntity;
import org.jfree.chart.entity.EntityCollection;

public class JFreeUtil {
    
    /** Do not instantiate. */
    private JFreeUtil() {
    }


    /**
     * True if \param hotspot collides with a Entity in \param entities.
     * @param hotspot Shape to compare against other shapes (bounds only).
     * @param entities entities against which to compare shape.
     * @param exclusiveEntityClass If not null, consider only entities of
     *        given class.
     * @return true if a collision (non-zero intersection) exists between
     *        shapes.
     */
    public static boolean collides(Shape hotspot, EntityCollection entities,
        Class exclusiveEntityClass) {
        if (entities == null) return false;

        Rectangle2D hotspotBox = hotspot.getBounds2D();
        
        for (Iterator i = entities.iterator(); i.hasNext(); ) {
            Object next = i.next();
            ChartEntity entity = (ChartEntity) next;
            if (exclusiveEntityClass == null
                || exclusiveEntityClass.isInstance(entity))
                {
                if (entity.getArea().intersects(hotspotBox)) {
                    // Found collision, early stop.
                    return true;
                }
            }
        }

        return false;
    }
}

http://dive4elements.wald.intevation.org