org.jfree.chart.fx.ChartCanvas Java Examples

The following examples show how to use org.jfree.chart.fx.ChartCanvas. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PanHandlerFX.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Handles a mouse pressed event by recording the initial mouse pointer
 * location.
 * 
 * @param canvas  the JavaFX canvas (<code>null</code> not permitted).
 * @param e  the mouse event (<code>null</code> not permitted).
 */
@Override
public void handleMousePressed(ChartCanvas canvas, MouseEvent e) {
    Plot plot = canvas.getChart().getPlot();
    if (!(plot instanceof Pannable)) {
        canvas.clearLiveHandler();
        return;
    }
    Pannable pannable = (Pannable) plot;
    if (pannable.isDomainPannable() || pannable.isRangePannable()) {
        Point2D point = new Point2D.Double(e.getX(), e.getY());
        Rectangle2D dataArea = canvas.findDataArea(point);
        if (dataArea != null && dataArea.contains(point)) {
            this.panW = dataArea.getWidth();
            this.panH = dataArea.getHeight();
            this.panLast = point;
            canvas.setCursor(javafx.scene.Cursor.MOVE);
        }
    }
    // the actual panning occurs later in the mouseDragged() method
}
 
Example #2
Source File: ChartGestureMouseAdapterFX.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 
 * @param canvas the canvas ({@code null} not permitted).
 * @param e the event ({@code null} not permitted).
 */
@Override
public void handleMouseReleased(ChartCanvas chartPanel, MouseEvent eOrig) {
  if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.RELEASED))
    return;

  MouseEventWrapper e = new MouseEventWrapper(eOrig);
  ChartEntity entity = findChartEntity(e);
  ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity);
  Button button = Button.getButton(e.getButton());

  // last gesture was dragged? keep the same chartEntity
  if (lastDragEvent != null) {
    entity = lastDragEvent.getEntity();
    gestureEntity = lastDragEvent.getGesture().getEntity();
  }
  // handle event
  handleEvent(new ChartGestureEvent(cw, e, entity,
      new ChartGesture(gestureEntity, Event.RELEASED, button)));

  // reset drag
  lastDragEvent = null;
}
 
Example #3
Source File: TooltipHandlerFX.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the tooltip text.
 * 
 * @param canvas  the canvas that is displaying the chart.
 * @param x  the x-coordinate of the mouse pointer.
 * @param y  the y-coordinate of the mouse pointer.
 * 
 * @return String The tooltip text (possibly <code>null</code>).
  */
private String getTooltipText(ChartCanvas canvas, double x, double y) {
    ChartRenderingInfo info = canvas.getRenderingInfo();
    if (info == null) {
        return null;
    }
    EntityCollection entities = info.getEntityCollection();
    if (entities == null) {
        return null;
    }
    ChartEntity entity = entities.getEntity(x, y);
    if (entity == null) {
        return null;
    }
    return entity.getToolTipText();
}
 
Example #4
Source File: ChartLogicsFX.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Find chartentities like JFreeChartEntity, AxisEntity, PlotEntity, TitleEntity, XY...
 * 
 * @param chart
 * @return
 */
public static ChartEntity findChartEntity(ChartCanvas chart, double mx, double my) {
  // TODO check if insets were needed
  // coordinates to find chart entities
  int x = (int) (mx / chart.getScaleX());
  int y = (int) (my / chart.getScaleY());

  ChartRenderingInfo info = chart.getRenderingInfo();
  ChartEntity entity = null;
  if (info != null) {
    EntityCollection entities = info.getEntityCollection();
    if (entities != null) {
      entity = entities.getEntity(x, y);
    }
  }
  return entity;
}
 
Example #5
Source File: ChartGestureMouseAdapterFX.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 
 * @param canvas the canvas ({@code null} not permitted).
 * @param e the event ({@code null} not permitted).
 */
@Override
public void handleMouseReleased(ChartCanvas chartPanel, MouseEvent eOrig) {
  if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.RELEASED))
    return;

  MouseEventWrapper e = new MouseEventWrapper(eOrig);
  ChartEntity entity = findChartEntity(e);
  ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity);
  Button button = Button.getButton(e.getButton());

  // last gesture was dragged? keep the same chartEntity
  if (lastDragEvent != null) {
    entity = lastDragEvent.getEntity();
    gestureEntity = lastDragEvent.getGesture().getEntity();
  }
  // handle event
  handleEvent(new ChartGestureEvent(cw, e, entity,
      new ChartGesture(gestureEntity, Event.RELEASED, button)));

  // reset drag
  lastDragEvent = null;
}
 
Example #6
Source File: ScrollHandlerFX.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Handle the case where a plot implements the {@link Zoomable} interface.
 *
 * @param zoomable  the zoomable plot.
 * @param e  the mouse wheel event.
 */
private void handleZoomable(ChartCanvas canvas, Zoomable zoomable, 
        ScrollEvent e) {
    // don't zoom unless the mouse pointer is in the plot's data area
    ChartRenderingInfo info = canvas.getRenderingInfo();
    PlotRenderingInfo pinfo = info.getPlotInfo();
    Point2D p = new Point2D.Double(e.getX(), e.getY());
    if (pinfo.getDataArea().contains(p)) {
        Plot plot = (Plot) zoomable;
        // do not notify while zooming each axis
        boolean notifyState = plot.isNotify();
        plot.setNotify(false);
        int clicks = (int) e.getDeltaY();
        double zf = 1.0 + this.zoomFactor;
        if (clicks < 0) {
            zf = 1.0 / zf;
        }
        if (true) { //this.chartPanel.isDomainZoomable()) {
            zoomable.zoomDomainAxes(zf, pinfo, p, true);
        }
        if (true) { //this.chartPanel.isRangeZoomable()) {
            zoomable.zoomRangeAxes(zf, pinfo, p, true);
        }
        plot.setNotify(notifyState);  // this generates the change event too
    } 
}
 
Example #7
Source File: PanHandlerFX.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Handles a mouse pressed event by recording the initial mouse pointer
 * location.
 * 
 * @param canvas  the JavaFX canvas (<code>null</code> not permitted).
 * @param e  the mouse event (<code>null</code> not permitted).
 */
@Override
public void handleMousePressed(ChartCanvas canvas, MouseEvent e) {
    Plot plot = canvas.getChart().getPlot();
    if (!(plot instanceof Pannable)) {
        canvas.clearLiveHandler();
        return;
    }
    Pannable pannable = (Pannable) plot;
    if (pannable.isDomainPannable() || pannable.isRangePannable()) {
        Point2D point = new Point2D.Double(e.getX(), e.getY());
        Rectangle2D dataArea = canvas.findDataArea(point);
        if (dataArea != null && dataArea.contains(point)) {
            this.panW = dataArea.getWidth();
            this.panH = dataArea.getHeight();
            this.panLast = point;
            canvas.setCursor(javafx.scene.Cursor.MOVE);
        }
    }
    // the actual panning occurs later in the mouseDragged() method
}
 
Example #8
Source File: ScrollHandlerFX.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Handle the case where a plot implements the {@link Zoomable} interface.
 *
 * @param zoomable  the zoomable plot.
 * @param e  the mouse wheel event.
 */
private void handleZoomable(ChartCanvas canvas, Zoomable zoomable, 
        ScrollEvent e) {
    // don't zoom unless the mouse pointer is in the plot's data area
    ChartRenderingInfo info = canvas.getRenderingInfo();
    PlotRenderingInfo pinfo = info.getPlotInfo();
    Point2D p = new Point2D.Double(e.getX(), e.getY());
    if (pinfo.getDataArea().contains(p)) {
        Plot plot = (Plot) zoomable;
        // do not notify while zooming each axis
        boolean notifyState = plot.isNotify();
        plot.setNotify(false);
        int clicks = (int) e.getDeltaY();
        double zf = 1.0 + this.zoomFactor;
        if (clicks < 0) {
            zf = 1.0 / zf;
        }
        if (true) { //this.chartPanel.isDomainZoomable()) {
            zoomable.zoomDomainAxes(zf, pinfo, p, true);
        }
        if (true) { //this.chartPanel.isRangeZoomable()) {
            zoomable.zoomRangeAxes(zf, pinfo, p, true);
        }
        plot.setNotify(notifyState);  // this generates the change event too
    } 
}
 
Example #9
Source File: ChartGestureMouseAdapterFX.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Handles a mouse dragged event. This implementation does nothing, override the method if
 * required.
 * 
 * @param canvas the canvas ({@code null} not permitted).
 * @param e the event ({@code null} not permitted).
 */
@Override
public void handleMouseDragged(ChartCanvas chartPanel, MouseEvent eOrig) {
  if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.DRAGGED))
    return;

  MouseEventWrapper e = new MouseEventWrapper(eOrig);
  // keep the same chartEntity
  ChartEntity entity = lastDragEvent.getEntity();
  ChartGesture.Entity gestureEntity = lastDragEvent.getGesture().getEntity();
  Button button = lastDragEvent.getGesture().getButton();

  // handle event
  lastDragEvent = new ChartGestureEvent(cw, e, entity,
      new ChartGesture(gestureEntity, Event.DRAGGED, button));
  handleEvent(lastDragEvent);
}
 
Example #10
Source File: ChartLogicsFX.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Find chartentities like JFreeChartEntity, AxisEntity, PlotEntity, TitleEntity, XY...
 * 
 * @param chart
 * @return
 */
public static ChartEntity findChartEntity(ChartCanvas chart, double mx, double my) {
  // TODO check if insets were needed
  // coordinates to find chart entities
  int x = (int) (mx / chart.getScaleX());
  int y = (int) (my / chart.getScaleY());

  ChartRenderingInfo info = chart.getRenderingInfo();
  ChartEntity entity = null;
  if (info != null) {
    EntityCollection entities = info.getEntityCollection();
    if (entities != null) {
      entity = entities.getEntity(x, y);
    }
  }
  return entity;
}
 
Example #11
Source File: ScrollHandlerFX.java    From jfreechart-fx with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void handleScroll(ChartCanvas canvas, ScrollEvent e) {
    JFreeChart chart = canvas.getChart();
    if (chart == null) {
        return;
    }
    Plot plot = chart.getPlot();
    if (plot instanceof Zoomable) {
        Zoomable zoomable = (Zoomable) plot;
        handleZoomable(canvas, zoomable, e);
    }
    else if (plot instanceof PiePlot) {
        PiePlot pp = (PiePlot) plot;
        pp.handleMouseWheelRotation((int) e.getDeltaY());
    }
}
 
Example #12
Source File: ScrollHandlerFX.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Handle the case where a plot implements the {@link Zoomable} interface.
 *
 * @param zoomable  the zoomable plot.
 * @param e  the mouse wheel event.
 */
private void handleZoomable(ChartCanvas canvas, Zoomable zoomable, 
        ScrollEvent e) {
    // don't zoom unless the mouse pointer is in the plot's data area
    ChartRenderingInfo info = canvas.getRenderingInfo();
    PlotRenderingInfo pinfo = info.getPlotInfo();
    Point2D p = new Point2D.Double(e.getX(), e.getY());
    if (pinfo.getDataArea().contains(p)) {
        Plot plot = (Plot) zoomable;
        // do not notify while zooming each axis
        boolean notifyState = plot.isNotify();
        plot.setNotify(false);
        int clicks = (int) e.getDeltaY();
        double zf = 1.0 + this.zoomFactor;
        if (clicks < 0) {
            zf = 1.0 / zf;
        }
        if (true) { //this.chartPanel.isDomainZoomable()) {
            zoomable.zoomDomainAxes(zf, pinfo, p, true);
        }
        if (true) { //this.chartPanel.isRangeZoomable()) {
            zoomable.zoomRangeAxes(zf, pinfo, p, true);
        }
        plot.setNotify(notifyState);  // this generates the change event too
    } 
}
 
Example #13
Source File: TooltipHandlerFX.java    From jfreechart-fx with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns the tooltip text.
 * 
 * @param canvas  the canvas that is displaying the chart.
 * @param x  the x-coordinate of the mouse pointer.
 * @param y  the y-coordinate of the mouse pointer.
 * 
 * @return String The tooltip text (possibly {@code null}).
  */
private String getTooltipText(ChartCanvas canvas, double x, double y) {
    ChartRenderingInfo info = canvas.getRenderingInfo();
    if (info == null) {
        return null;
    }
    EntityCollection entities = info.getEntityCollection();
    if (entities == null) {
        return null;
    }
    ChartEntity entity = entities.getEntity(x, y);
    if (entity == null) {
        return null;
    }
    return entity.getToolTipText();
}
 
Example #14
Source File: ChartGestureMouseAdapterFX.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Handles a mouse moved event. This implementation does nothing, override the method if required.
 * 
 * @param canvas the canvas ({@code null} not permitted).
 * @param e the event ({@code null} not permitted).
 */
@Override
public void handleMouseMoved(ChartCanvas chartPanel, MouseEvent eOrig) {
  if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.MOVED))
    return;

  MouseEventWrapper e = new MouseEventWrapper(eOrig);
  ChartViewWrapper cw = new ChartViewWrapper(chartViewer);
  ChartEntity entity = findChartEntity(e);
  ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity);
  GestureButton button = GestureButton.getButton(e.getButton());

  // handle event
  handleEvent(
      new ChartGestureEvent(cw, e, entity, new ChartGesture(gestureEntity, Event.MOVED, button)));
}
 
Example #15
Source File: ChartGestureMouseAdapterFX.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Handles a mouse moved event. This implementation does nothing, override the method if required.
 * 
 * @param canvas the canvas ({@code null} not permitted).
 * @param e the event ({@code null} not permitted).
 */
@Override
public void handleMouseMoved(ChartCanvas chartPanel, MouseEvent eOrig) {
  if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.MOVED))
    return;

  MouseEventWrapper e = new MouseEventWrapper(eOrig);
  ChartViewWrapper cw = new ChartViewWrapper(chartViewer);
  ChartEntity entity = findChartEntity(e);
  ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity);
  Button button = Button.getButton(e.getButton());

  // handle event
  handleEvent(
      new ChartGestureEvent(cw, e, entity, new ChartGesture(gestureEntity, Event.MOVED, button)));
}
 
Example #16
Source File: ChartGestureMouseAdapterFX.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 
 * @param canvas the canvas ({@code null} not permitted).
 * @param e the event ({@code null} not permitted).
 */
@Override
public void handleMouseReleased(ChartCanvas chartPanel, MouseEvent eOrig) {
  if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.RELEASED))
    return;

  MouseEventWrapper e = new MouseEventWrapper(eOrig);
  ChartEntity entity = findChartEntity(e);
  ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity);
  GestureButton button = GestureButton.getButton(e.getButton());

  // last gesture was dragged? keep the same chartEntity
  if (lastDragEvent != null) {
    entity = lastDragEvent.getEntity();
    gestureEntity = lastDragEvent.getGesture().getEntity();
  }
  // handle event
  handleEvent(new ChartGestureEvent(cw, e, entity,
      new ChartGesture(gestureEntity, Event.RELEASED, button)));

  // reset drag
  lastDragEvent = null;
}
 
Example #17
Source File: PanHandlerFX.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Handles a mouse pressed event by recording the initial mouse pointer
 * location.
 * 
 * @param canvas  the JavaFX canvas (<code>null</code> not permitted).
 * @param e  the mouse event (<code>null</code> not permitted).
 */
@Override
public void handleMousePressed(ChartCanvas canvas, MouseEvent e) {
    Plot plot = canvas.getChart().getPlot();
    if (!(plot instanceof Pannable)) {
        canvas.clearLiveHandler();
        return;
    }
    Pannable pannable = (Pannable) plot;
    if (pannable.isDomainPannable() || pannable.isRangePannable()) {
        Point2D point = new Point2D.Double(e.getX(), e.getY());
        Rectangle2D dataArea = canvas.findDataArea(point);
        if (dataArea != null && dataArea.contains(point)) {
            this.panW = dataArea.getWidth();
            this.panH = dataArea.getHeight();
            this.panLast = point;
            canvas.setCursor(javafx.scene.Cursor.MOVE);
        }
    }
    // the actual panning occurs later in the mouseDragged() method
}
 
Example #18
Source File: TooltipHandlerFX.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the tooltip text.
 * 
 * @param canvas  the canvas that is displaying the chart.
 * @param x  the x-coordinate of the mouse pointer.
 * @param y  the y-coordinate of the mouse pointer.
 * 
 * @return String The tooltip text (possibly <code>null</code>).
  */
private String getTooltipText(ChartCanvas canvas, double x, double y) {
    ChartRenderingInfo info = canvas.getRenderingInfo();
    if (info == null) {
        return null;
    }
    EntityCollection entities = info.getEntityCollection();
    if (entities == null) {
        return null;
    }
    ChartEntity entity = entities.getEntity(x, y);
    if (entity == null) {
        return null;
    }
    return entity.getToolTipText();
}
 
Example #19
Source File: PanHandlerFX.java    From jfreechart-fx with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Handles a mouse pressed event by recording the initial mouse pointer
 * location.
 * 
 * @param canvas  the JavaFX canvas ({@code null} not permitted).
 * @param e  the mouse event ({@code null} not permitted).
 */
@Override
public void handleMousePressed(ChartCanvas canvas, MouseEvent e) {
	if (canvas.getChart() == null) {
		return;
	}
    Plot plot = canvas.getChart().getPlot();
    if (!(plot instanceof Pannable)) {
        canvas.clearLiveHandler();
        return;
    }
    Pannable pannable = (Pannable) plot;
    if (pannable.isDomainPannable() || pannable.isRangePannable()) {
        Point2D point = new Point2D.Double(e.getX(), e.getY());
        Rectangle2D dataArea = canvas.findDataArea(point);
        if (dataArea != null && dataArea.contains(point)) {
            this.panW = dataArea.getWidth();
            this.panH = dataArea.getHeight();
            this.panLast = point;
            canvas.setCursor(javafx.scene.Cursor.MOVE);
        }
    }
    // the actual panning occurs later in the mouseDragged() method
}
 
Example #20
Source File: PanHandlerFX.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
public void handleMouseReleased(ChartCanvas canvas, MouseEvent e) {  
    //if we have been panning reset the cursor
    //unregister in any case
    if (this.panLast != null) {
        canvas.setCursor(javafx.scene.Cursor.DEFAULT);
    }
    this.panLast = null;
    canvas.clearLiveHandler();
}
 
Example #21
Source File: DispatchHandlerFX.java    From jfreechart-fx with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Handles a mouse clicked event by setting the anchor point for the
 * canvas and redrawing the chart (the anchor point is a reference point
 * used by the chart to determine crosshair lines).
 * 
 * @param canvas  the chart canvas ({@code null} not permitted).
 * @param e  the mouse event ({@code null} not permitted).
 */
@Override
public void handleMouseClicked(ChartCanvas canvas, MouseEvent e) {
    if (this.mousePressedPoint == null || canvas.getChart() == null) {
        return;
    }
    double x = e.getX();
    double y = e.getY();
    ChartEntity entity = canvas.getRenderingInfo().getEntityCollection().getEntity(x, y);
    ChartMouseEventFX event = new ChartMouseEventFX(canvas.getChart(), e, entity);
    for (ChartMouseListenerFX listener : canvas.getChartMouseListeners()) {
        listener.chartMouseClicked(event);
    }
}
 
Example #22
Source File: AnchorHandlerFX.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Handles a mouse clicked event by setting the anchor point for the
 * canvas and redrawing the chart (the anchor point is a reference point
 * used by the chart to determine crosshair lines).
 * 
 * @param canvas  the chart canvas (<code>null</code> not permitted).
 * @param e  the mouse event (<code>null</code> not permitted).
 */
@Override
public void handleMouseClicked(ChartCanvas canvas, MouseEvent e) {
    if (this.mousePressedPoint == null) {
        return;
    }
    Point2D currPt = new Point2D.Double(e.getX(), e.getY());
    if (this.mousePressedPoint.distance(currPt) < 2) {
        canvas.setAnchor(currPt);
    }
    this.mousePressedPoint = null;
}
 
Example #23
Source File: PanHandlerFX.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Handles a mouse dragged event by calculating the distance panned and
 * updating the axes accordingly.
 * 
 * @param canvas  the JavaFX canvas (<code>null</code> not permitted).
 * @param e  the mouse event (<code>null</code> not permitted).
 */
public void handleMouseDragged(ChartCanvas canvas, MouseEvent e) {
    if (this.panLast == null) {
        //handle panning if we have a start point else unregister
        canvas.clearLiveHandler();
        return;
    }

    JFreeChart chart = canvas.getChart();
    double dx = e.getX() - this.panLast.getX();
    double dy = e.getY() - this.panLast.getY();
    if (dx == 0.0 && dy == 0.0) {
        return;
    }
    double wPercent = -dx / this.panW;
    double hPercent = dy / this.panH;
    boolean old = chart.getPlot().isNotify();
    chart.getPlot().setNotify(false);
    Pannable p = (Pannable) chart.getPlot();
    PlotRenderingInfo info = canvas.getRenderingInfo().getPlotInfo();
    if (p.getOrientation().isVertical()) {
        p.panDomainAxes(wPercent, info, this.panLast);
        p.panRangeAxes(hPercent, info, this.panLast);
    }
    else {
        p.panDomainAxes(hPercent, info, this.panLast);
        p.panRangeAxes(wPercent, info, this.panLast);
    }
    this.panLast = new Point2D.Double(e.getX(), e.getY());
    chart.getPlot().setNotify(old);
}
 
Example #24
Source File: PanHandlerFX.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Handles a mouse dragged event by calculating the distance panned and
 * updating the axes accordingly.
 * 
 * @param canvas  the JavaFX canvas (<code>null</code> not permitted).
 * @param e  the mouse event (<code>null</code> not permitted).
 */
public void handleMouseDragged(ChartCanvas canvas, MouseEvent e) {
    if (this.panLast == null) {
        //handle panning if we have a start point else unregister
        canvas.clearLiveHandler();
        return;
    }

    JFreeChart chart = canvas.getChart();
    double dx = e.getX() - this.panLast.getX();
    double dy = e.getY() - this.panLast.getY();
    if (dx == 0.0 && dy == 0.0) {
        return;
    }
    double wPercent = -dx / this.panW;
    double hPercent = dy / this.panH;
    boolean old = chart.getPlot().isNotify();
    chart.getPlot().setNotify(false);
    Pannable p = (Pannable) chart.getPlot();
    PlotRenderingInfo info = canvas.getRenderingInfo().getPlotInfo();
    if (p.getOrientation().isVertical()) {
        p.panDomainAxes(wPercent, info, this.panLast);
        p.panRangeAxes(hPercent, info, this.panLast);
    }
    else {
        p.panDomainAxes(hPercent, info, this.panLast);
        p.panRangeAxes(wPercent, info, this.panLast);
    }
    this.panLast = new Point2D.Double(e.getX(), e.getY());
    chart.getPlot().setNotify(old);
}
 
Example #25
Source File: ZoomHandlerFX.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Handles a mouse pressed event by recording the initial mouse pointer
 * location.
 * 
 * @param canvas  the JavaFX canvas (<code>null</code> not permitted).
 * @param e  the mouse event (<code>null</code> not permitted).
 */
@Override
public void handleMousePressed(ChartCanvas canvas, MouseEvent e) {
    Point2D pt = new Point2D.Double(e.getX(), e.getY());
    Rectangle2D dataArea = canvas.findDataArea(pt);
    if (dataArea != null) {
        this.startPoint = ShapeUtilities.getPointInRectangle(e.getX(),
                e.getY(), dataArea);
    } else {
        this.startPoint = null;
        canvas.clearLiveHandler();
    }
}
 
Example #26
Source File: PanHandlerFX.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Handles a mouse dragged event by calculating the distance panned and
 * updating the axes accordingly.
 * 
 * @param canvas  the JavaFX canvas (<code>null</code> not permitted).
 * @param e  the mouse event (<code>null</code> not permitted).
 */
public void handleMouseDragged(ChartCanvas canvas, MouseEvent e) {
    if (this.panLast == null) {
        //handle panning if we have a start point else unregister
        canvas.clearLiveHandler();
        return;
    }

    JFreeChart chart = canvas.getChart();
    double dx = e.getX() - this.panLast.getX();
    double dy = e.getY() - this.panLast.getY();
    if (dx == 0.0 && dy == 0.0) {
        return;
    }
    double wPercent = -dx / this.panW;
    double hPercent = dy / this.panH;
    boolean old = chart.getPlot().isNotify();
    chart.getPlot().setNotify(false);
    Pannable p = (Pannable) chart.getPlot();
    PlotRenderingInfo info = canvas.getRenderingInfo().getPlotInfo();
    if (p.getOrientation().isVertical()) {
        p.panDomainAxes(wPercent, info, this.panLast);
        p.panRangeAxes(hPercent, info, this.panLast);
    }
    else {
        p.panDomainAxes(hPercent, info, this.panLast);
        p.panRangeAxes(wPercent, info, this.panLast);
    }
    this.panLast = new Point2D.Double(e.getX(), e.getY());
    chart.getPlot().setNotify(old);
}
 
Example #27
Source File: TooltipHandlerFX.java    From jfreechart-fx with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Handles a mouse moved event by updating the tooltip.
 * 
 * @param canvas  the chart canvas ({@code null} not permitted).
 * @param e  the mouse event.
 */
@Override
public void handleMouseMoved(ChartCanvas canvas, MouseEvent e) {
    if (canvas.getChart() == null || !canvas.isTooltipEnabled()) {
        return;
    }
    String text = getTooltipText(canvas, e.getX(), e.getY());
    canvas.setTooltip(text, e.getScreenX(), e.getScreenY());
}
 
Example #28
Source File: ScrollHandlerFX.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handleScroll(ChartCanvas canvas, ScrollEvent e) {
    JFreeChart chart = canvas.getChart();
    Plot plot = chart.getPlot();
    if (plot instanceof Zoomable) {
        Zoomable zoomable = (Zoomable) plot;
        handleZoomable(canvas, zoomable, e);
    }
    else if (plot instanceof PiePlot) {
        PiePlot pp = (PiePlot) plot;
        pp.handleMouseWheelRotation((int) e.getDeltaY());
    }
}
 
Example #29
Source File: PanHandlerFX.java    From jfreechart-fx with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void handleMouseReleased(ChartCanvas canvas, MouseEvent e) {  
    //if we have been panning reset the cursor
    //unregister in any case
    if (this.panLast != null) {
        canvas.setCursor(javafx.scene.Cursor.DEFAULT);
    }
    this.panLast = null;
    canvas.clearLiveHandler();
}
 
Example #30
Source File: ScrollHandlerFX.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handleScroll(ChartCanvas canvas, ScrollEvent e) {
    JFreeChart chart = canvas.getChart();
    Plot plot = chart.getPlot();
    if (plot instanceof Zoomable) {
        Zoomable zoomable = (Zoomable) plot;
        handleZoomable(canvas, zoomable, e);
    }
    else if (plot instanceof PiePlot) {
        PiePlot pp = (PiePlot) plot;
        pp.handleMouseWheelRotation((int) e.getDeltaY());
    }
}