Java Code Examples for javafx.scene.input.ScrollEvent#getDeltaY()
The following examples show how to use
javafx.scene.input.ScrollEvent#getDeltaY() .
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: ScrollHandlerFX.java From ccu-historian with GNU General Public License v3.0 | 6 votes |
/** * 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 2
Source File: ScrollHandlerFX.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * 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 3
Source File: ScrollHandlerFX.java From ECG-Viewer with GNU General Public License v2.0 | 6 votes |
/** * 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 4
Source File: Fx3DStageController.java From mzmine2 with GNU General Public License v2.0 | 6 votes |
/** * @param event * Zooms in and out when the mouse is scrolled. */ public void onScrollHandler(ScrollEvent event) { double delta = 1.2; double scale = (plot.getScaleX()); if (event.getDeltaY() < 0) { scale /= delta; } else { scale *= delta; } scale = clamp(scale, MIN_SCALE, MAX_SCALE); plot.setScaleX(scale); plot.setScaleY(scale); event.consume(); }
Example 5
Source File: ScrollHandlerFX.java From SIMVA-SoS with Apache License 2.0 | 6 votes |
/** * 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 6
Source File: ScrollHandlerFX.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * 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: TaScrollHandlerFX.java From TAcharting with GNU Lesser General Public License v2.1 | 6 votes |
/** * 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(TaChartCanvas canvas, Zoomable zoomable, ScrollEvent e) { // don't zoom unless the mouse pointer is in the plot's org.sjwimmer.tacharting.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 (canvas.isDomainZoomable()) { zoomable.zoomDomainAxes(zf, pinfo, p, true); } if (canvas.isRangeZoomable()) { zoomable.zoomRangeAxes(zf, pinfo, p, true); } plot.setNotify(notifyState); // this generates the change event too } }
Example 8
Source File: PlotCanvasBase.java From phoebus with Eclipse Public License 1.0 | 6 votes |
/** Zoom in/out triggered by mouse wheel * @param event Scroll event */ protected void wheelZoom(final ScrollEvent event) { // Invoked by mouse scroll wheel. // Only allow zoom (with control), not pan. if (! event.isControlDown()) return; if (event.getDeltaY() > 0) zoomInOut(event.getX(), event.getY(), 1.0/ZOOM_FACTOR); else if (event.getDeltaY() < 0) zoomInOut(event.getX(), event.getY(), ZOOM_FACTOR); else return; event.consume(); }
Example 9
Source File: Zoomer.java From chart-fx with Apache License 2.0 | 6 votes |
private static void zoomOnAxis(final Axis axis, final ScrollEvent event) { if (hasBoundedRange(axis)) { return; } final boolean isZoomIn = event.getDeltaY() > 0; final boolean isHorizontal = axis.getSide().isHorizontal(); final double mousePos = isHorizontal ? event.getX() : event.getY(); final double posOnAxis = axis.getValueForDisplay(mousePos); final double max = axis.getMax(); final double min = axis.getMin(); final double scaling = isZoomIn ? 0.9 : 1 / 0.9; final double diffHalf1 = scaling * Math.abs(posOnAxis - min); final double diffHalf2 = scaling * Math.abs(max - posOnAxis); axis.set(posOnAxis - diffHalf1, posOnAxis + diffHalf2); axis.forceRedraw(); }
Example 10
Source File: Fx3DStageController.java From mzmine3 with GNU General Public License v2.0 | 6 votes |
/** * @param event Zooms in and out when the mouse is scrolled. */ public void onScrollHandler(ScrollEvent event) { double delta = 1.2; double scale = (plot.getScaleX()); if (event.getDeltaY() < 0) { scale /= delta; } else { scale *= delta; } scale = clamp(scale, MIN_SCALE, MAX_SCALE); plot.setScaleX(scale); plot.setScaleY(scale); event.consume(); }
Example 11
Source File: ScrollHandlerFX.java From openstock with GNU General Public License v3.0 | 6 votes |
/** * 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 12
Source File: ScrollHandlerFX.java From jfreechart-fx with GNU Lesser General Public License v2.1 | 5 votes |
/** * Handle the case where a plot implements the {@link Zoomable} interface. * * @param canvas the chart canvas. * @param zoomable the zoomable plot. * @param e the mouse wheel event. */ private void handleZoomable(ChartCanvas canvas, Zoomable zoomable, ScrollEvent e) { if (canvas.getChart() == null) { return; } // 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 (canvas.isDomainZoomable()) { zoomable.zoomDomainAxes(zf, pinfo, p, true); } if (canvas.isRangeZoomable()) { zoomable.zoomRangeAxes(zf, pinfo, p, true); } plot.setNotify(notifyState); // this generates the change event too } }
Example 13
Source File: TimelineChart.java From constellation with Apache License 2.0 | 5 votes |
public void performZoom(final ScrollEvent se, final double mouseX) { final double range = upperTimeExtent - lowerTimeExtent; final double width = parent.getWidth(); // Register the event as a ScrollEvent: // Zoom on scrolling events: if (se.getEventType() == ScrollEvent.SCROLL) { // Determine the scale here: final double quantum = range / 10.0; final double msMouse = lowerTimeExtent + ((mouseX * (upperTimeExtent - lowerTimeExtent)) / width); // We are zooming in: if (se.getDeltaY() > 0d) { // Only zoom in if we haven't reached the minimum size: if (quantum >= 0.5) { lowerTimeExtent = (msMouse - ((msMouse - lowerTimeExtent) * 0.9)); // Zoom in by 10% upperTimeExtent = (msMouse + ((upperTimeExtent - msMouse) * 0.9)); // update the scope window: parent.coordinator.setExtents(lowerTimeExtent, upperTimeExtent); } } else { // We are zooming out: if (quantum <= YEAR * 10d) { lowerTimeExtent = (long) (msMouse - ((msMouse - lowerTimeExtent) * 1.1)); // Zoom out by 10% upperTimeExtent = (long) (msMouse + ((upperTimeExtent - msMouse) * 1.1)); // update the scope window: parent.coordinator.setExtents((long) lowerTimeExtent, (long) upperTimeExtent); } } } }
Example 14
Source File: ViewportGestures.java From fxgraph with Do What The F*ck You Want To Public License | 5 votes |
@Override public void handle(ScrollEvent event) { double scale = canvas.getScale(); // currently we only use Y, same value is used for X final double oldScale = scale; if(event.getDeltaY() < 0) { scale /= getZoomSpeed(); } else if (event.getDeltaY() > 0) { scale *= getZoomSpeed(); } scale = clamp(scale, minScaleProperty.get(), maxScaleProperty.get()); final double f = (scale / oldScale) - 1; // maxX = right overhang, maxY = lower overhang final double maxX = canvas.getBoundsInParent().getMaxX() - canvas.localToParent(canvas.getPrefWidth(), canvas.getPrefHeight()).getX(); final double maxY = canvas.getBoundsInParent().getMaxY() - canvas.localToParent(canvas.getPrefWidth(), canvas.getPrefHeight()).getY(); // minX = left overhang, minY = upper overhang final double minX = canvas.localToParent(0, 0).getX() - canvas.getBoundsInParent().getMinX(); final double minY = canvas.localToParent(0, 0).getY() - canvas.getBoundsInParent().getMinY(); // adding the overhangs together, as we only consider the width of canvas itself final double subX = maxX + minX; final double subY = maxY + minY; // subtracting the overall overhang from the width and only the left and upper overhang from the upper left point final double dx = (event.getSceneX() - ((canvas.getBoundsInParent().getWidth() - subX) / 2 + (canvas.getBoundsInParent().getMinX() + minX))); final double dy = (event.getSceneY() - ((canvas.getBoundsInParent().getHeight() - subY) / 2 + (canvas.getBoundsInParent().getMinY() + minY))); canvas.setScale(scale); // note: pivot value must be untransformed, i. e. without scaling canvas.setPivot(f * dx, f * dy); event.consume(); }
Example 15
Source File: PanOrZoomOnScrollHandler.java From gef with Eclipse Public License 2.0 | 5 votes |
/** * Computes the translation for the given {@link ScrollEvent}. The * horizontal and vertical translation is inverted when * {@link #isPanDirectionSwapped(ScrollEvent)} returns <code>true</code>. * * @param event * The original {@link ScrollEvent}. * @return A {@link Dimension} storing the horizontal and vertical * translation. */ protected Dimension computePanTranslation(ScrollEvent event) { double dx = event.getDeltaX(); double dy = event.getDeltaY(); if (isPanDirectionSwapped(event)) { double t = dx; dx = dy; dy = t; } return new Dimension(dx, dy); }
Example 16
Source File: WebViewEventDispatcher.java From oim-fx with MIT License | 5 votes |
private void processScrollEvent(ScrollEvent ev) { if (page == null) { return; } double dx = - ev.getDeltaX() * webView.getFontScale() * webView.getScaleX(); double dy = - ev.getDeltaY() * webView.getFontScale() * webView.getScaleY(); WCMouseWheelEvent wheelEvent = new WCMouseWheelEvent((int)ev.getX(), (int)ev.getY(), (int)ev.getScreenX(), (int)ev.getScreenY(), System.currentTimeMillis(), ev.isShiftDown(), ev.isControlDown(), ev.isAltDown(), ev.isMetaDown(), (float)dx, (float)dy); page.dispatchMouseWheelEvent(wheelEvent); ev.consume(); }
Example 17
Source File: MouseEventNotificator.java From DeskChan with GNU Lesser General Public License v3.0 | 4 votes |
/** * Use this method to process a scroll event and send a special GUI event by the means of the message system. * @param event ScrollEvent */ void notifyScrollEvent(ScrollEvent event) { int delta = (event.getDeltaY() > 0) ? -1 : 1; impl_notifyScrollEvent(delta, event.getScreenX(), event.getScreenY(), event.getX(), event.getY()); }
Example 18
Source File: InfluenceAnalysisUI.java From SONDY with GNU General Public License v3.0 | 4 votes |
public final VBox createNetworkVisualization(){ System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer"); Viewer viewer = new Viewer(AppParameters.authorNetwork, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD); view = viewer.addDefaultView(false); viewer.enableAutoLayout(); view.resizeFrame(Main.columnWidthLEFT, 290); swingNode = new CustomSwingNode(); swingNode.setContent(view); swingNode.resize(Main.columnWidthLEFT, 290); EventHandler<MouseEvent> mouseHandlerGraphClick = new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent mouseEvent) { if (mouseEvent.getEventType() == MouseEvent.MOUSE_PRESSED) { if(mouseEvent.getButton() == MouseButton.SECONDARY){ Node node = (Node) view.findNodeOrSpriteAt(mouseEvent.getX(), mouseEvent.getY()); if(node != null){ userMessages(node.getId()); } } if(mouseEvent.getButton() == MouseButton.PRIMARY){ double translateCoeff = view.getCamera().getViewPercent(); Point3 center = view.getCamera().getViewCenter(); if(mouseEvent.getY()>175){ view.getCamera().setViewCenter(center.x, center.y-5*translateCoeff, center.z); }else{ view.getCamera().setViewCenter(center.x, center.y+5*translateCoeff, center.z); } if(mouseEvent.getX()>275){ view.getCamera().setViewCenter(center.x+5*translateCoeff, center.y, center.z); }else{ view.getCamera().setViewCenter(center.x-5*translateCoeff, center.y, center.z); } } if(mouseEvent.getButton() == MouseButton.MIDDLE){ view.getCamera().setViewPercent(view.getCamera().getViewPercent()/2); } } } }; EventHandler<ScrollEvent> mouseHandlerGraphScroll = new EventHandler<ScrollEvent>() { @Override public void handle(ScrollEvent event) { if(event.getDeltaY() < 0){ view.getCamera().setViewPercent(view.getCamera().getViewPercent()*2); }else{ view.getCamera().setViewPercent(view.getCamera().getViewPercent()/2); } } }; swingNode.setOnMousePressed(mouseHandlerGraphClick); swingNode.setOnScroll(mouseHandlerGraphScroll); VBox graphBox = new VBox(); graphBox.getChildren().addAll(new Rectangle(Main.columnWidthLEFT,0),swingNode); initializeNetworkVisualizationStyle(); return graphBox; }
Example 19
Source File: ChartZoomManager.java From jfxutils with Apache License 2.0 | 4 votes |
@Override public void handle( ScrollEvent event ) { EventType<? extends Event> eventType = event.getEventType(); if ( eventType == ScrollEvent.SCROLL_STARTED ) { //mouse wheel events never send SCROLL_STARTED ignoring = true; } else if ( eventType == ScrollEvent.SCROLL_FINISHED ) { //end non-mouse wheel event ignoring = false; } else if ( eventType == ScrollEvent.SCROLL && //If we are allowing mouse wheel zooming mouseWheelZoomAllowed.get() && //If we aren't between SCROLL_STARTED and SCROLL_FINISHED !ignoring && //inertia from non-wheel gestures might have touch count of 0 !event.isInertia() && //Only care about vertical wheel events event.getDeltaY() != 0 && //mouse wheel always has touch count of 0 event.getTouchCount() == 0 ) { //Find out which axes to zoom based on the strategy double eventX = event.getX(); double eventY = event.getY(); DefaultChartInputContext context = new DefaultChartInputContext( chartInfo, eventX, eventY ); AxisConstraint zoomMode = mouseWheelAxisConstraintStrategy.getConstraint( context ); if ( zoomMode == AxisConstraint.None ) return; //If we are are doing a zoom animation, stop it. Also of note is that we don't zoom the //mouse wheel zooming. Because the mouse wheel can "fly" and generate a lot of events, //animation doesn't work well. Plus, as the mouse wheel changes the view a small amount in //a predictable way, it "looks like" an animation when you roll it. //We might experiment with mouse wheel zoom animation in the future, though. zoomAnimation.stop(); //At this point we are a mouse wheel event, based on everything I've read Point2D dataCoords = chartInfo.getDataCoordinates( eventX, eventY ); //Determine the proportion of change to the lower and upper bounds based on how far the //cursor is along the axis. double xZoomBalance = getBalance( dataCoords.getX(), getXAxisLowerBound(), getXAxisUpperBound() ); double yZoomBalance = getBalance( dataCoords.getY(), getYAxisLowerBound(), getYAxisUpperBound() ); //Are we zooming in or out, based on the direction of the roll double direction = -Math.signum( event.getDeltaY() ); //TODO: Do we need to handle "continuous" scroll wheels that don't work based on ticks? //If so, the 0.2 needs to be modified double zoomAmount = 0.2 * direction; if ( zoomMode == AxisConstraint.Both || zoomMode == AxisConstraint.Horizontal ) { double xZoomDelta = ( getXAxisUpperBound() - getXAxisLowerBound() ) * zoomAmount; xAxis.setAutoRanging( false ); setXAxisLowerBound( getXAxisLowerBound() - xZoomDelta * xZoomBalance ); setXAxisUpperBound( getXAxisUpperBound() + xZoomDelta * ( 1 - xZoomBalance ) ); } if ( zoomMode == AxisConstraint.Both || zoomMode == AxisConstraint.Vertical ) { double yZoomDelta = ( getYAxisUpperBound() - getYAxisLowerBound() ) * zoomAmount; yAxis.setAutoRanging( false ); setYAxisLowerBound( getYAxisLowerBound() - yZoomDelta * yZoomBalance ); setYAxisUpperBound( getYAxisUpperBound() + yZoomDelta * ( 1 - yZoomBalance ) ); } } }
Example 20
Source File: PanOrZoomOnScrollHandler.java From gef with Eclipse Public License 2.0 | 2 votes |
/** * Computes the zoom factor from the given {@link ScrollEvent}. * * @param event * The {@link ScrollEvent} from which to compute the zoom factor. * @return The zoom factor according to the given {@link ScrollEvent}. */ protected double computeZoomFactor(ScrollEvent event) { return event.getDeltaY() > 0 ? 1.05 : 1 / 1.05; }