Search in sources :

Example 16 with ChartMouseEvent

use of org.jfree.chart.ChartMouseEvent in project SIMVA-SoS by SESoS.

the class ChartComposite method mouseDown.

/**
 * Handles a mouse down event.
 *
 * @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);
    // force a redraw
    this.chart.setNotify(true);
    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);
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) Point(java.awt.Point) ChartMouseListener(org.jfree.chart.ChartMouseListener) Point2D(java.awt.geom.Point2D) EntityCollection(org.jfree.chart.entity.EntityCollection) ChartEntity(org.jfree.chart.entity.ChartEntity)

Example 17 with ChartMouseEvent

use of org.jfree.chart.ChartMouseEvent in project SIMVA-SoS by SESoS.

the class ChartComposite method mouseMove.

/**
 * Handles a mouse move event.
 *
 * @param event  the mouse event.
 */
public void mouseMove(MouseEvent event) {
    // handle axis trace
    if (this.horizontalAxisTrace || this.verticalAxisTrace) {
        this.horizontalTraceLineY = event.y;
        this.verticalTraceLineX = event.x;
        this.canvas.redraw();
    }
    // 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);
    }
    // handle zoom box
    boolean hZoom, vZoom;
    if (this.zoomPoint != null) {
        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();
    }
    // new entity code
    ChartEntity entity = null;
    int x = (int) ((event.x - getClientArea().x) / this.scaleX);
    int y = (int) ((event.y - getClientArea().y) / this.scaleY);
    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 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);
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) Point(java.awt.Point) ChartMouseListener(org.jfree.chart.ChartMouseListener) EntityCollection(org.jfree.chart.entity.EntityCollection) ChartEntity(org.jfree.chart.entity.ChartEntity)

Aggregations

ChartMouseEvent (org.jfree.chart.ChartMouseEvent)17 ChartMouseListener (org.jfree.chart.ChartMouseListener)17 ChartEntity (org.jfree.chart.entity.ChartEntity)12 ChartPanel (org.jfree.chart.ChartPanel)8 ChartComposite (org.jfree.experimental.chart.swt.ChartComposite)7 BasicStroke (java.awt.BasicStroke)6 Color (java.awt.Color)6 XYItemEntity (org.jfree.chart.entity.XYItemEntity)6 GridBagLayout (java.awt.GridBagLayout)5 JLabel (javax.swing.JLabel)5 JPanel (javax.swing.JPanel)5 CrosshairOverlay (org.jfree.chart.panel.CrosshairOverlay)5 Crosshair (org.jfree.chart.plot.Crosshair)5 XYDataset (org.jfree.data.xy.XYDataset)5 TalendChartComposite (org.talend.dataprofiler.chart.util.TalendChartComposite)4 Point2D (java.awt.geom.Point2D)3 DisposeEvent (org.eclipse.swt.events.DisposeEvent)3 DisposeListener (org.eclipse.swt.events.DisposeListener)3 Menu (org.eclipse.swt.widgets.Menu)3 CategoryItemEntity (org.jfree.chart.entity.CategoryItemEntity)3