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.diversityarrays.kdxplore.chartcommon.KDXploreChartPanel.java

@Override
public void mouseReleased(MouseEvent e) {
    if (e.isShiftDown() || shiftDownatStart) {
        super.mouseReleased(e);
        shiftDownatStart = false;//ww  w. j  a  v a 2  s .c  o m

        Insets insets = getInsets();
        int x = (int) ((e.getX() - insets.left) / this.getScaleX());
        int y = (int) ((e.getY() - insets.top) / this.getScaleY());

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

        Object[] listeners = this.getListeners(ChartMouseListener.class);

        if (this.getChart() != null) {
            ChartMouseEvent event = new ChartMouseEvent(getChart(), e, entity);
            for (int i = listeners.length - 1; i >= 0; i -= 1) {
                if (listeners[i] instanceof KDXChartMouseListener) {
                    ((KDXChartMouseListener) listeners[i]).chartMouseZoomingReleased(event);
                }
            }
        }

    } else {
        super.mouseReleased(e);

        Insets insets = getInsets();
        int x = (int) ((e.getX() - insets.left) / this.getScaleX());
        int y = (int) ((e.getY() - insets.top) / this.getScaleY());

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

        Object[] listeners = this.getListeners(ChartMouseListener.class);

        if (this.getChart() != null) {
            ChartMouseEvent event = new ChartMouseEvent(getChart(), e, entity);
            for (int i = listeners.length - 1; i >= 0; i -= 1) {
                if (listeners[i] instanceof KDXChartMouseListener) {
                    ((KDXChartMouseListener) listeners[i]).chartMouseSelectedReleased(event);
                }
            }
        }
    }
}

From source file:org.mwc.cmap.grideditor.chart.JFreeChartComposite.java

@Override
public void mouseUp(final MouseEvent event) {
    final Object[] listeners = myListenerExtensions.getListeners(ChartMouseListenerExtension.class);
    if (listeners.length != 0) {
        // pass mouse down event if some ChartMouseListener are listening
        final java.awt.event.MouseEvent awtEvent = SWTUtils.toAwtMouseEvent(event);
        final ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), awtEvent, null);
        for (int i = listeners.length - 1; i >= 0; i -= 1) {
            ((ChartMouseListenerExtension) listeners[i]).chartMouseReleased(chartEvent);
        }// w w  w .  j ava  2s.c  om
        if (awtEvent.isConsumed()) {
            forgetZoomPoints();
            return;
        }
    }
    super.mouseUp(event);
}

From source file:com.diversityarrays.kdxplore.chartcommon.KDXploreChartPanel.java

@Override
public void mouseDragged(MouseEvent e) {
    if (e.isShiftDown() || shiftDownatStart) {
        super.mouseDragged(e);

    } else {//from w  w w .  j a  v a2  s. c om

        Insets insets = getInsets();
        int x = (int) ((e.getX() - insets.left) / this.getScaleX());
        int y = (int) ((e.getY() - insets.top) / this.getScaleY());

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

        if (this.getChart() != null) {
            ChartMouseEvent event = new ChartMouseEvent(getChart(), e, entity);

            EventListener[] listeners = this.getListeners(ChartMouseListener.class);

            for (int i = listeners.length - 1; i >= 0; i -= 1) {
                if (listeners[i] instanceof KDXChartMouseListener) {
                    ((KDXChartMouseListener) listeners[i]).chartMouseSelected(event);
                }
            }
        }
    }
}

From source file:de.xirp.ui.widgets.custom.XChartComposite.java

/**
 * @param event/*from   w ww. jav a 2s.  co  m*/
 */
private void handleMouseEvents(Event event) {
    switch (event.type) {
    case SWT.MouseDown:
        Rectangle scaledDataArea = getScreenDataArea(event.x, event.y);
        zoomPoint = getPointInRectangle(event.x, event.y, scaledDataArea);
        Rectangle insets = getClientArea();
        int x = (int) ((event.x - insets.x) / scaleX);
        int y = (int) ((event.y - insets.y) / scaleY);

        anchor = new Point2D.Double(x, y);
        chart.setNotify(true); // force a redraw
        canvas.redraw();
        // new entity code...
        Object[] listeners = chartMouseListeners.getListeners(ChartMouseListener.class);
        if (listeners.length == 0) {
            return;
        }

        ChartEntity entity = null;
        if (info != null) {
            EntityCollection entities = info.getEntityCollection();
            if (entities != null) {
                entity = entities.getEntity(x, y);
            }
        }
        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);
        }
        break;
    case SWT.MouseMove:
        // handle axis trace
        if (horizontalAxisTrace || verticalAxisTrace) {
            horizontalTraceLineY = event.y;
            verticalTraceLineX = event.x;
            canvas.redraw();
        }
        // handle tool tips in a simple way
        if (displayToolTips) {
            String s = getToolTipText(new MouseEvent(event));
            if (s != null && !s.equals(canvas.getToolTipText())) {
                canvas.setToolTipText(s);
            }
        }
        // handle zoom box
        if (zoomPoint == null) {
            return;
        }
        scaledDataArea = getScreenDataArea(zoomPoint.x, zoomPoint.y);
        org.eclipse.swt.graphics.Point movingPoint = getPointInRectangle(event.x, event.y, scaledDataArea);
        // handle zoom
        boolean hZoom = false;
        boolean vZoom = false;
        if (orientation == PlotOrientation.HORIZONTAL) {
            hZoom = rangeZoomable;
            vZoom = domainZoomable;
        } else {
            hZoom = domainZoomable;
            vZoom = rangeZoomable;
        }
        if (hZoom && vZoom) {
            // selected rectangle shouldn't extend outside the
            // data area...
            zoomRectangle = new Rectangle(zoomPoint.x, zoomPoint.y, movingPoint.x - zoomPoint.x,
                    movingPoint.y - zoomPoint.y);
        } else if (hZoom) {
            zoomRectangle = new Rectangle(zoomPoint.x, scaledDataArea.y, movingPoint.x - zoomPoint.x,
                    scaledDataArea.height);
        } else if (vZoom) {
            zoomRectangle = new Rectangle(scaledDataArea.x, zoomPoint.y, scaledDataArea.width,
                    event.y - zoomPoint.y);
        }
        canvas.redraw();
        break;
    case SWT.MouseUp:
        if (zoomRectangle == null) {
            Rectangle screenDataArea = getScreenDataArea(event.x, event.y);
            if (screenDataArea != null) {
                zoomPoint = getPointInRectangle(event.x, event.y, screenDataArea);
            }
            if (popup != null && event.button == 3) {
                org.eclipse.swt.graphics.Point pt = canvas.toDisplay(event.x, event.y);
                displayPopupMenu(pt.x, pt.y);
            }
        } else {
            hZoom = false;
            vZoom = false;
            if (orientation == PlotOrientation.HORIZONTAL) {
                hZoom = rangeZoomable;
                vZoom = domainZoomable;
            } else {
                hZoom = domainZoomable;
                vZoom = rangeZoomable;
            }
            boolean zoomTrigger1 = hZoom && Math.abs(zoomRectangle.width) >= zoomTriggerDistance;
            boolean zoomTrigger2 = vZoom && Math.abs(zoomRectangle.height) >= zoomTriggerDistance;
            if (zoomTrigger1 || zoomTrigger2) {
                // if the box has been drawn backwards,
                // restore the auto bounds
                if ((hZoom && (zoomRectangle.x + zoomRectangle.width < zoomPoint.x))
                        || (vZoom && (zoomRectangle.y + zoomRectangle.height < zoomPoint.y))) {
                    restoreAutoBounds();
                } else {
                    zoom(zoomRectangle);
                }
                canvas.redraw();
            }
        }
        zoomPoint = null;
        zoomRectangle = null;
        break;
    default:
        zoomPoint = null;
        zoomRectangle = null;
    }
}

From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java

/**
 * Receives notification of mouse clicks on the panel. These are
 * translated and passed on to any registered chart mouse click listeners.
 *
 * @param event  Information about the mouse event.
 *//*from  w  w  w.j av  a2  s.co m*/
public void mouseClicked(MouseEvent event) {

    Insets insets = getInsets();
    int x = event.getX() - insets.left;
    int y = event.getY() - insets.top;

    //"Custom" mouse click handling code. One may use it for interactive work with the plots
    //(or follow the original framework). 
    //Manager should be set with setManager(), and handleMouseClicked(), which
    //is an empty function of AbstractManager, should be overriden in the AbstractManager subclass.
    if (manager != null)
        manager.handleMouseClicked(x, y);

    // old 'handle click' code...
    chart.handleClick(x, y, this.info);

    // new entity code...
    if (this.chartMouseListeners.isEmpty()) {
        return;
    }

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

    Iterator iterator = chartMouseListeners.iterator();
    while (iterator.hasNext()) {
        ChartMouseListener listener = (ChartMouseListener) iterator.next();
        listener.chartMouseClicked(chartEvent);
    }
}

From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java

/**
 * Implementation of the MouseMotionListener's method
 *
 * @param e  the event.//ww  w. j  a  v a 2 s .c  o  m
 */
public void mouseMoved(MouseEvent e) {

    //crosshair
    if (this.horizontalAxisTrace && this.verticalAxisTrace && this.crosshairNotBlocked) {
        Rectangle2D rect = this.getScaledDataArea();
        double ux = userX(e);
        double uy = userY(e);

        if (!(rect.contains(e.getX(), e.getY()) && disableCrosshairTillLeavesDisplay)) {
            if (disableCrosshairTillLeavesDisplay) {
                disableCrosshairTillLeavesDisplay = false;
                drawHorizontalAxisTrace(e.getX());
                drawVerticalAxisTrace(e.getY());
            } else {
                drawHorizontalAxisTrace(e.getX());
                drawVerticalAxisTrace(e.getY());
                if (rect.contains(e.getX(), e.getY())) {
                    float uxf = (float) ux;
                    float uyf = (float) uy;
                    this.writeToStatusBar("( " + uxf + " , " + uyf + " )");

                } else {
                    this.writeToStatusBar("");
                }
            }
        }

    }

    if (this.chartMouseListeners.isEmpty()) {
        return;
    }

    Insets insets = getInsets();
    int x = e.getX() - insets.left;
    int y = e.getY() - insets.top;

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

    ChartMouseEvent event = new ChartMouseEvent(getChart(), e, entity);

    Iterator iterator = chartMouseListeners.iterator();
    while (iterator.hasNext()) {
        ChartMouseListener listener = (ChartMouseListener) iterator.next();
        listener.chartMouseMoved(event);
    }
}

From source file:org.jfree.experimental.chart.swt.ChartComposite.java

public void mouseDown(MouseEvent event) {

    Rectangle scaledDataArea = getScreenDataArea(event.x, event.y);
    if (scaledDataArea == null)
        return;/*  w ww.j  a  v  a 2s .c  o m*/
    this.zoomPoint = getPointInRectangle(event.x, event.y, scaledDataArea);
    int x = (int) ((event.x - getClientArea().x) / this.scaleX);
    int y = (int) ((event.y - getClientArea().y) / this.scaleY);

    this.anchor = new Point2D.Double(x, y);
    this.chart.setNotify(true); // force a redraw
    this.canvas.redraw();

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

    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:org.mwc.cmap.grideditor.chart.FixedChartComposite.java

/**
 * Handles a mouse down event.//from w w w.j a  va2s  . c o m
 * 
 * @param event
 *          the event.
 */
public void mouseDown(final MouseEvent event) {

    final Rectangle scaledDataArea = getScreenDataArea(event.x, event.y);
    if (scaledDataArea == null)
        return;
    this.zoomPoint = getPointInRectangle(event.x, event.y, scaledDataArea);
    final int x = (int) ((event.x - getClientArea().x) / this.scaleX);
    final int y = (int) ((event.y - getClientArea().y) / this.scaleY);

    this.anchor = new Point2D.Double(x, y);
    this.chart.setNotify(true); // force a redraw
    this.canvas.redraw();

    // new entity code
    ChartEntity entity = null;
    if (this.info != null) {
        final EntityCollection entities = this.info.getEntityCollection();
        if (entities != null) {
            // [MG] -- the code below from original
            // org.jfree.experimental.chart.swt.ChartComposite
            // doesn't work -- because entities already placed with respect to the
            // scale factor.
            //
            // [IM] -- reinstated the code below, since other version wasn't
            // working. This one (
            // the one that doesn't shift them) now works. Feb 10.
            entity = entities.getEntity(x, y);
            //
            // entity = entities.getEntity(event.x - getClientArea().x, event.y -
            // getClientArea().y);
        }
    }

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

    // pass mouse down event if some ChartMouseListener are listening
    final java.awt.event.MouseEvent mouseEvent = SWTUtils.toAwtMouseEvent(event);
    final 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:com.munch.exchange.ExchangeChartComposite.java

/**
 * Handles a mouse down event./* w  w  w . ja v  a2 s .c  o m*/
 *
 * @param event  the event.
 */
public void mouseDown(MouseEvent event) {

    Rectangle scaledDataArea = getScreenDataArea(event.x, event.y);
    if (scaledDataArea == null)
        return;
    this.zoomPoint = getPointInRectangle(event.x, event.y, scaledDataArea);
    int x = (int) ((event.x - getClientArea().x) / this.scaleX);
    int y = (int) ((event.y - getClientArea().y) / this.scaleY);

    this.anchor = new Point2D.Double(x, y);
    this.chart.setNotify(true); // force a redraw
    this.canvas.redraw();

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

    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:com.isti.traceview.common.TraceViewChartPanel.java

/**
 * Receives notification of mouse clicks on the panel. These are translated and passed on to any
 * registered chart mouse click listeners.
 * /* w  w  w . j  a  v a  2 s  .  c  o m*/
 * @param event
 *            Information about the mouse event.
 */
public void mouseClicked(MouseEvent event) {
    Insets insets = getInsets();
    int x = (int) ((event.getX() - insets.left) / this.scaleX);
    int y = (int) ((event.getY() - insets.top) / this.scaleY);

    this.anchor = new Point2D.Double(x, y);
    if (this.chart == null) {
        return;
    }
    this.chart.setNotify(true); // force a redraw
    // new entity code...
    Object[] listeners = this.chartMouseListeners.getListeners(ChartMouseListener.class);
    if (listeners.length == 0) {
        return;
    }

    ChartEntity entity = null;
    if (this.info != null) {
        EntityCollection entities = this.info.getEntityCollection();
        if (entities != null) {
            entity = entities.getEntity(x, y);
        }
    }
    ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), event, entity);
    for (int i = listeners.length - 1; i >= 0; i -= 1) {
        ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent);
    }
}