/** * 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) { 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 }
/** * 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 }
/** * Handles a mouse pressed event. * * @param e the event. */ public void mousePressed(MouseEvent e) { ChartPanel panel = (ChartPanel) e.getSource(); Plot plot = panel.getChart().getPlot(); if (!(plot instanceof Pannable)) { return; // there's nothing for us to do } Pannable pannable = (Pannable) plot; if (pannable.isDomainPannable() || pannable.isRangePannable()) { Rectangle2D screenDataArea = panel.getScreenDataArea(e.getX(), e.getY()); if (screenDataArea != null && screenDataArea.contains( e.getPoint())) { this.panW = screenDataArea.getWidth(); this.panH = screenDataArea.getHeight(); this.panLast = e.getPoint(); panel.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); } } // the actual panning occurs later in the mouseDragged() method }
/** * Handles a mouse dragged event by calculating the distance panned and * updating the axes accordingly. * * @param canvas the JavaFX canvas ({@code null} not permitted). * @param e the mouse event ({@code null} not permitted). */ @Override 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); }
/** * 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); }
/** * Handles a mouse dragged event. This is where the panning occurs. * * @param e the event. */ public void mouseDragged(MouseEvent e) { // handle panning if we have a start point if (this.panLast == null) { return; } ChartPanel panel = (ChartPanel) e.getSource(); JFreeChart chart = panel.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 = panel.getChartRenderingInfo().getPlotInfo(); if (p.getOrientation() == PlotOrientation.VERTICAL) { 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 = e.getPoint(); chart.getPlot().setNotify(old); return; }