Example usage for org.jfree.chart ChartMouseEvent ChartMouseEvent

List of usage examples for org.jfree.chart ChartMouseEvent ChartMouseEvent

Introduction

In this page you can find the example usage for org.jfree.chart ChartMouseEvent ChartMouseEvent.

Prototype

public ChartMouseEvent(JFreeChart chart, MouseEvent trigger, ChartEntity entity) 

Source Link

Document

Constructs a new event.

Usage

From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java

/**
 * Implementation of the MouseMotionListener's method.
 * /* ww w.ja v  a  2  s  .  c om*/
 * @param e
 *            the event.
 */

@Override
public void mouseMoved(MouseEvent e) {
    Graphics2D g2 = (Graphics2D) getGraphics();
    if (this.horizontalAxisTrace) {
        drawHorizontalAxisTrace(g2, e.getX());
    }
    if (this.verticalAxisTrace) {
        drawVerticalAxisTrace(g2, e.getY());
    }
    g2.dispose();

    Object[] listeners = this.chartMouseListeners.getListeners(ChartMouseListener.class);
    if (listeners.length == 0) {
        return;
    }
    Insets insets = getInsets();
    int x = (int) ((e.getX() - insets.left) / this.scaleX);
    int y = (int) ((e.getY() - insets.top) / this.scaleY);

    ChartEntity entity = null;
    if (this.info != null) {
        EntityCollection entities = this.info.getEntityCollection();
        if (entities != null) {
            entity = entities.getEntity(x, y);
        }
    }

    // we can only generate events if the panel's chart is not null
    // (see bug report 1556951)
    if (this.chart != null) {
        ChartMouseEvent event = new ChartMouseEvent(getChart(), e, entity);
        for (int i = listeners.length - 1; i >= 0; i -= 1) {
            ((ChartMouseListener) listeners[i]).chartMouseMoved(event);
        }
    }

}

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

public void mouseMove(MouseEvent event) {

    // handle axis trace
    if (this.horizontalAxisTrace || this.verticalAxisTrace) {
        this.horizontalTraceLineY = event.y;
        this.verticalTraceLineX = event.x;
        this.canvas.redraw();
    }/*w ww  .  j av  a  2s  . c o m*/

    // handle tool tips in a simple way
    if (this.displayToolTips) {
        String s = getToolTipText(event);
        if (s == null && this.canvas.getToolTipText() != null
                || s != null && !s.equals(this.canvas.getToolTipText()))
            this.canvas.setToolTipText(s);
    }

    // new entity code
    Point2D javaPoint = translateScreenToJava2D(new Point(event.x, event.y));
    ChartEntity entity = getEntityForLocation(javaPoint.getX(), javaPoint.getY());

    // handle zoom box

    if (this.zoomPoint != null) {
        boolean hZoom, vZoom;
        Rectangle scaledDataArea = getScreenDataArea(this.zoomPoint.x, this.zoomPoint.y);
        org.eclipse.swt.graphics.Point movingPoint = getPointInRectangle(event.x, event.y, scaledDataArea);
        if (this.orientation == PlotOrientation.HORIZONTAL) {
            hZoom = this.rangeZoomable;
            vZoom = this.domainZoomable;
        } else {
            hZoom = this.domainZoomable;
            vZoom = this.rangeZoomable;
        }
        if (hZoom && vZoom) {
            // selected rectangle shouldn't extend outside the data area...
            this.zoomRectangle = new Rectangle(this.zoomPoint.x, this.zoomPoint.y,
                    movingPoint.x - this.zoomPoint.x, movingPoint.y - this.zoomPoint.y);
        } else if (hZoom) {
            this.zoomRectangle = new Rectangle(this.zoomPoint.x, scaledDataArea.y,
                    movingPoint.x - this.zoomPoint.x, scaledDataArea.height);
        } else if (vZoom) {
            int ymax = Math.max(movingPoint.y, scaledDataArea.y);
            this.zoomRectangle = new Rectangle(scaledDataArea.x, this.zoomPoint.y, scaledDataArea.width,
                    ymax - this.zoomPoint.y);
        }
        this.canvas.redraw();
    } else if (this.selectionPoint != null) {
        Rectangle scaledDataArea = getScreenDataArea(this.selectionPoint.x, this.selectionPoint.y);

        org.eclipse.swt.graphics.Point movingPoint = getPointInRectangle(event.x, event.y, scaledDataArea);

        if (this.orientation == PlotOrientation.VERTICAL) {
            Point2D selectionPointJava = translateScreenToJava2D(
                    new Point(this.selectionPoint.x, scaledDataArea.y));
            this.selectionRectangle = new Rectangle((int) selectionPointJava.getX(),
                    (int) selectionPointJava.getY(), (int) ((movingPoint.x - this.selectionPoint.x) / scaleX),
                    (int) (scaledDataArea.height / scaleY));
        } else {
            int ymax = Math.max(movingPoint.y, scaledDataArea.y);

            Point2D selectionPointJava = translateScreenToJava2D(
                    new Point(scaledDataArea.x, this.selectionPoint.y));
            this.selectionRectangle = new Rectangle((int) selectionPointJava.getX(),
                    (int) selectionPointJava.getY(), (int) (scaledDataArea.width / scaleX),
                    (int) ((ymax - this.selectionPoint.y) / scaleY));
        }

        this.canvas.redraw();
    }

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

    // pass mouse move 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]).chartMouseMoved(chartEvent);
    }
}