Example usage for org.jfree.chart.entity ChartEntity getArea

List of usage examples for org.jfree.chart.entity ChartEntity getArea

Introduction

In this page you can find the example usage for org.jfree.chart.entity ChartEntity getArea.

Prototype

public Shape getArea() 

Source Link

Document

Returns the area occupied by the entity (in Java 2D space).

Usage

From source file:edu.pitt.dbmi.odie.ui.jfreechart.EnhancedChartComposite.java

public void mouseDown(MouseEvent event) {

    Point2D javaPoint = translateScreenToJava2D(new Point(event.x, event.y));
    Rectangle scaledDataArea = getScreenDataArea(event.x, event.y);
    if (scaledDataArea == null)
        return;//from w  w w. j  a v a2s  .co m

    // new entity code
    ChartEntity entity = getEntityForLocation(javaPoint.getX(), javaPoint.getY());
    if (entity != null)
        logger.debug("Entity Bounds:" + entity.getArea().getBounds());

    // logger.debug("----------END------------");

    if (event.button == 1) {
        // Init zoom point only if CTRL key is down.
        if ((event.stateMask & SWT.CONTROL) != 0) {
            this.zoomPoint = getPointInRectangle(event.x, event.y, scaledDataArea);
        } else {
            clearSelection(false, false);
            this.selectionPoint = getPointInRectangle(event.x, event.y, scaledDataArea);
        }
    }

    this.anchor = javaPoint;
    this.chart.setNotify(true); // force a redraw
    this.canvas.redraw();

    Object[] listeners = this.chartMouseListeners.getListeners(ChartMouseListener.class);
    if (listeners.length == 0) {
        return;
    }

    // pass mouse down event if some ChartMouseListener are listening
    java.awt.event.MouseEvent mouseEvent = SWTUtils.toAwtMouseEvent(event);
    ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), mouseEvent, entity);
    for (int i = listeners.length - 1; i >= 0; i -= 1) {
        ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent);
    }
}

From source file:edu.pitt.dbmi.odie.ui.jfreechart.EnhancedChartComposite.java

/**
 * Returns chart entities that are enclosed within the selection rectangle.
 * /*from  w w  w . j a v  a 2  s  . co m*/
 * @param selectionRectangle
 * @return ChartEntity objects.
 */
private List<ChartEntity> getEnclosedEntities(Rectangle selectionRectangle) {
    List<ChartEntity> entities = new ArrayList<ChartEntity>();

    // DISTANCE_FROM_AXIS is used so that we minimize the search along the
    // axis for
    // the chartentity if the point is not within a chartentity's bounds.
    // See getEntityForLocation.
    final int DISTANCE_FROM_AXIS = 5;

    if (orientation == PlotOrientation.VERTICAL) {
        int x = selectionRectangle.x;
        int y = selectionRectangle.y + selectionRectangle.height - DISTANCE_FROM_AXIS;

        while (x <= selectionRectangle.x + selectionRectangle.width) {
            ChartEntity e = getEntityForLocation(x, y);

            if (e != null) {
                if (!entities.contains(e)) {
                    entities.add(e);
                    x += e.getArea().getBounds().getWidth();
                    continue;

                }
            }
            x++;
        }
    } else {
        int x = selectionRectangle.x + DISTANCE_FROM_AXIS;
        int y = selectionRectangle.y;

        while (y < selectionRectangle.y + selectionRectangle.height) {
            ChartEntity e = getEntityForLocation(x, y);
            if (e != null) {
                if (!entities.contains(e)) {
                    entities.add(e);
                    y += e.getArea().getBounds().getHeight();
                    continue;
                }
            }
            y++;
        }
    }
    return entities;
}