felix@3018: package de.intevation.flys.jfree; felix@3018: felix@3018: import java.awt.Shape; felix@3018: import java.awt.geom.Rectangle2D; felix@3018: felix@3018: import java.util.Iterator; felix@3018: ingo@3105: import org.w3c.dom.Document; ingo@3105: felix@3018: import org.jfree.chart.entity.ChartEntity; felix@3018: import org.jfree.chart.entity.EntityCollection; felix@3018: ingo@3105: import org.jfree.data.function.Function2D; ingo@3105: ingo@3105: felix@3018: public class JFreeUtil { sascha@3076: felix@3018: /** Do not instantiate. */ felix@3018: private JFreeUtil() { felix@3018: } felix@3018: felix@3018: felix@3018: /** felix@3018: * True if \param hotspot collides with a Entity in \param entities. felix@3018: * @param hotspot Shape to compare against other shapes (bounds only). felix@3018: * @param entities entities against which to compare shape. felix@3023: * @param exclusiveEntityClass If not null, consider only entities of felix@3023: * given class. felix@3023: * @return true if a collision (non-zero intersection) exists between felix@3018: * shapes. felix@3018: */ felix@3023: public static boolean collides(Shape hotspot, EntityCollection entities, felix@3023: Class exclusiveEntityClass) { felix@3018: if (entities == null) return false; felix@3018: felix@3018: Rectangle2D hotspotBox = hotspot.getBounds2D(); sascha@3076: felix@3018: for (Iterator i = entities.iterator(); i.hasNext(); ) { felix@3018: Object next = i.next(); felix@3018: ChartEntity entity = (ChartEntity) next; felix@3023: if (exclusiveEntityClass == null felix@3023: || exclusiveEntityClass.isInstance(entity)) felix@3023: { felix@3023: if (entity.getArea().intersects(hotspotBox)) { felix@3023: // Found collision, early stop. felix@3023: return true; felix@3023: } felix@3018: } felix@3018: } felix@3018: felix@3018: return false; felix@3018: } ingo@3105: ingo@3105: ingo@3105: public static StyledXYSeries sampleFunction2D( ingo@3105: Function2D func, ingo@3105: Document theme, ingo@3105: String seriesKey, ingo@3105: int samples, ingo@3105: double start, ingo@3105: double end ingo@3105: ) { ingo@3105: StyledXYSeries series = new StyledXYSeries(seriesKey, theme); ingo@3105: ingo@3105: double step = (end - start) / (samples - 1); ingo@3105: ingo@3105: for (int i = 0; i < samples; i++) { ingo@3105: double x = start + (step * i); ingo@3105: series.add(x, func.getValue(x)); ingo@3105: } ingo@3105: ingo@3105: return series; ingo@3105: } felix@3018: } sascha@3083: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :