List of usage examples for javafx.scene.input ScrollEvent getDeltaY
public double getDeltaY()
From source file:Main.java
public static java.awt.event.KeyEvent toAwt(final ScrollEvent event) { final EventType type = event.getEventType(); if (null == type) { return null; }/* w w w . j av a2s .c om*/ final long when = -1; final int id = java.awt.event.KeyEvent.KEY_PRESSED; final int keyCode; if (event.getDeltaY() > 0) { keyCode = java.awt.event.KeyEvent.VK_PAGE_DOWN; } else { keyCode = java.awt.event.KeyEvent.VK_PAGE_UP; } final int modifiers = modifiers(event); final char keyChar = ' '; return new java.awt.event.KeyEvent(empty, id, when, modifiers, keyCode, keyChar); }
From source file:Main.java
@Override public void start(Stage stage) throws Exception { ImageView imageView = new ImageView(); ScrollPane scrollPane = new ScrollPane(); DoubleProperty zoomProperty = new SimpleDoubleProperty(200); zoomProperty.addListener(new InvalidationListener() { @Override// ww w. j ava2s. co m public void invalidated(Observable arg0) { imageView.setFitWidth(zoomProperty.get() * 2); imageView.setFitHeight(zoomProperty.get() * 3); } }); scrollPane.addEventFilter(ScrollEvent.ANY, new EventHandler<ScrollEvent>() { @Override public void handle(ScrollEvent event) { if (event.getDeltaY() > 0) { zoomProperty.set(zoomProperty.get() * 1.2); } else if (event.getDeltaY() < 0) { zoomProperty.set(zoomProperty.get() / 1.1); } } }); imageView.setImage(new Image("http://yourImageURL")); imageView.preserveRatioProperty().set(true); scrollPane.setContent(imageView); stage.setScene(new Scene(scrollPane, 400, 300)); stage.show(); }
From source file:ZoomExample.java
@Override public void start(Stage stage) throws Exception { zoomProperty.addListener(new InvalidationListener() { @Override//w w w . j a va2 s . c om public void invalidated(Observable arg0) { imageView.setFitWidth(zoomProperty.get() * 4); imageView.setFitHeight(zoomProperty.get() * 3); } }); scrollPane.addEventFilter(ScrollEvent.ANY, new EventHandler<ScrollEvent>() { @Override public void handle(ScrollEvent event) { if (event.getDeltaY() > 0) { zoomProperty.set(zoomProperty.get() * 1.1); } else if (event.getDeltaY() < 0) { zoomProperty.set(zoomProperty.get() / 1.1); } } }); imageView.setImage(new Image("http://yourImageURL")); imageView.preserveRatioProperty().set(true); scrollPane.setContent(imageView); stage.setScene(new Scene(scrollPane, 400, 300)); stage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { Group root = new Group(); Scene scene = new Scene(root, 300, 250); Rectangle rect = new Rectangle(); rect.setWidth(100);//from w ww .j a v a 2s .c o m rect.setHeight(100); root.getChildren().add(rect); rect.setOnScroll(new EventHandler<ScrollEvent>() { @Override public void handle(ScrollEvent event) { if (!event.isInertia()) { rect.setTranslateX(rect.getTranslateX() + event.getDeltaX()); rect.setTranslateY(rect.getTranslateY() + event.getDeltaY()); } System.out.println("Rectangle: Scroll event" + ", inertia: " + event.isInertia() + ", direct: " + event.isDirect()); event.consume(); } }); rect.setOnScrollStarted(new EventHandler<ScrollEvent>() { @Override public void handle(ScrollEvent event) { System.out.println("Rectangle: Scroll started event"); event.consume(); } }); rect.setOnScrollFinished(new EventHandler<ScrollEvent>() { @Override public void handle(ScrollEvent event) { System.out.println("Rectangle: Scroll finished event"); event.consume(); } }); rect.setOnZoom(new EventHandler<ZoomEvent>() { @Override public void handle(ZoomEvent event) { rect.setScaleX(rect.getScaleX() * event.getZoomFactor()); rect.setScaleY(rect.getScaleY() * event.getZoomFactor()); System.out.println("Rectangle: Zoom event" + ", inertia: " + event.isInertia() + ", direct: " + event.isDirect()); event.consume(); } }); rect.setOnZoomStarted(new EventHandler<ZoomEvent>() { @Override public void handle(ZoomEvent event) { System.out.println("Rectangle: Zoom event started"); event.consume(); } }); rect.setOnZoomFinished(new EventHandler<ZoomEvent>() { @Override public void handle(ZoomEvent event) { System.out.println("Rectangle: Zoom event finished"); event.consume(); } }); rect.setOnRotate(new EventHandler<RotateEvent>() { @Override public void handle(RotateEvent event) { rect.setRotate(rect.getRotate() + event.getAngle()); System.out.println("Rectangle: Rotate event" + ", inertia: " + event.isInertia() + ", direct: " + event.isDirect()); event.consume(); } }); rect.setOnRotationStarted(new EventHandler<RotateEvent>() { @Override public void handle(RotateEvent event) { System.out.println("Rectangle: Rotate event started"); event.consume(); } }); rect.setOnRotationFinished(new EventHandler<RotateEvent>() { @Override public void handle(RotateEvent event) { System.out.println("Rectangle: Rotate event finished"); event.consume(); } }); rect.setOnSwipeRight(new EventHandler<SwipeEvent>() { @Override public void handle(SwipeEvent event) { System.out.println("Rectangle: Swipe right event"); event.consume(); } }); rect.setOnSwipeLeft(new EventHandler<SwipeEvent>() { @Override public void handle(SwipeEvent event) { System.out.println("Rectangle: Swipe left event"); event.consume(); } }); rect.setOnTouchPressed(new EventHandler<TouchEvent>() { @Override public void handle(TouchEvent event) { System.out.println("Rectangle: Touch pressed event"); event.consume(); } }); rect.setOnTouchReleased(new EventHandler<TouchEvent>() { @Override public void handle(TouchEvent event) { System.out.println("Rectangle: Touch released event"); event.consume(); } }); rect.setOnMousePressed(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { if (event.isSynthesized()) { System.out.println( "Ellipse: Mouse pressed event from touch" + ", synthesized: " + event.isSynthesized()); } event.consume(); } }); rect.setOnMouseReleased(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { if (event.isSynthesized()) { System.out.println( "Ellipse: Mouse released event from touch" + ", synthesized: " + event.isSynthesized()); } event.consume(); } }); primaryStage.setScene(scene); primaryStage.show(); }
From source file:de.hs.mannheim.modUro.controller.diagram.fx.interaction.ScrollHandlerFX.java
@Override public void handleScroll(ChartCanvas canvas, ScrollEvent e) { JFreeChart chart = canvas.getChart(); Plot plot = chart.getPlot();//from www.j a v a2 s .co m 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()); } }
From source file:de.hs.mannheim.modUro.controller.diagram.fx.interaction.ScrollHandlerFX.java
/** * Handle the case where a plot implements the {@link Zoomable} interface. * * @param zoomable the zoomable plot.//w ww.ja v a 2 s .com * @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 } }
From source file:be.makercafe.apps.makerbench.editors.JFXScadEditor.java
public JFXScadEditor(String tabText, Path path) { super(tabText); this.viewGroup = new Group(); this.editorContainer = new BorderPane(); this.viewContainer = new Pane(); this.caCodeArea = new CodeArea(""); this.caCodeArea.setEditable(true); this.caCodeArea.setParagraphGraphicFactory(LineNumberFactory.get(caCodeArea)); this.caCodeArea.setPrefSize(Double.MAX_VALUE, Double.MAX_VALUE); this.caCodeArea.getStylesheets().add(this.getClass().getResource("java-keywords.css").toExternalForm()); this.caCodeArea.richChanges().subscribe(change -> { caCodeArea.setStyleSpans(0, computeHighlighting(caCodeArea.getText())); });//from ww w . j av a 2 s. c o m addContextMenu(this.caCodeArea); EventStream<Change<String>> textEvents = EventStreams.changesOf(caCodeArea.textProperty()); textEvents.reduceSuccessions((a, b) -> b, Duration.ofMillis(3000)).subscribe(code -> { if (autoCompile) { compile(code.getNewValue()); } }); if (path == null) { this.caCodeArea.replaceText("CSG cube = new Cube(2).toCSG()\n" + "CSG sphere = new Sphere(1.25).toCSG()\n" + "\n" + "cube.difference(sphere)"); } else { try { this.caCodeArea.replaceText(FileUtils.readFileToString(path.toFile())); } catch (IOException ex) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Error reading file.", ex); } } //editorContainer.setCenter(this.codeArea); subScene = new SubScene(viewGroup, 100, 100, true, SceneAntialiasing.BALANCED); subScene.widthProperty().bind(viewContainer.widthProperty()); subScene.heightProperty().bind(viewContainer.heightProperty()); PerspectiveCamera subSceneCamera = new PerspectiveCamera(false); subScene.setCamera(subSceneCamera); viewContainer.getChildren().add(subScene); SplitPane editorPane = new SplitPane(caCodeArea, viewContainer); editorPane.setOrientation(Orientation.HORIZONTAL); BorderPane rootPane = new BorderPane(); BorderPane pane = (BorderPane) this.getTab().getContent(); toolBar = createToolBar(); rootPane.setTop(toolBar); rootPane.setCenter(editorPane); this.getTab().setContent(rootPane); subScene.setOnScroll(new EventHandler<ScrollEvent>() { @Override public void handle(ScrollEvent event) { System.out .println(String.format("deltaX: %.3f deltaY: %.3f", event.getDeltaX(), event.getDeltaY())); double z = subSceneCamera.getTranslateZ(); double newZ = z + event.getDeltaY(); subSceneCamera.setTranslateZ(newZ); } }); }
From source file:be.makercafe.apps.makerbench.editors.GCodeEditor.java
public GCodeEditor(String tabText, Path path) { super(tabText); this.viewGroup = new Group(); this.editorContainer = new BorderPane(); this.viewContainer = new Pane(); this.caCodeArea = new CodeArea(""); this.caCodeArea.setEditable(true); this.caCodeArea.setParagraphGraphicFactory(LineNumberFactory.get(caCodeArea)); this.caCodeArea.setPrefSize(Double.MAX_VALUE, Double.MAX_VALUE); // this.caCodeArea.getStylesheets().add(this.getClass().getResource("java-keywords.css").toExternalForm()); // this.caCodeArea.richChanges().subscribe(change -> { // caCodeArea.setStyleSpans(0, // computeHighlighting(caCodeArea.getText())); // });//from www. ja v a 2s. c o m addContextMenu(this.caCodeArea); EventStream<Change<String>> textEvents = EventStreams.changesOf(caCodeArea.textProperty()); textEvents.reduceSuccessions((a, b) -> b, Duration.ofMillis(3000)).subscribe(code -> { if (autoCompile) { compile(code.getNewValue()); } }); if (path == null) { this.caCodeArea.replaceText("#empty"); } else { try { this.caCodeArea.replaceText(FileUtils.readFileToString(path.toFile())); } catch (IOException ex) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Error reading file.", ex); } } // editorContainer.setCenter(this.codeArea); subScene = new SubScene(viewGroup, 100, 100, true, SceneAntialiasing.BALANCED); subScene.widthProperty().bind(viewContainer.widthProperty()); subScene.heightProperty().bind(viewContainer.heightProperty()); PerspectiveCamera subSceneCamera = new PerspectiveCamera(false); subScene.setCamera(subSceneCamera); viewContainer.getChildren().add(subScene); SplitPane editorPane = new SplitPane(caCodeArea, viewContainer); editorPane.setOrientation(Orientation.HORIZONTAL); BorderPane rootPane = new BorderPane(); BorderPane pane = (BorderPane) this.getTab().getContent(); toolBar = createToolBar(); rootPane.setTop(toolBar); rootPane.setCenter(editorPane); this.getTab().setContent(rootPane); subScene.setOnScroll(new EventHandler<ScrollEvent>() { @Override public void handle(ScrollEvent event) { System.out .println(String.format("deltaX: %.3f deltaY: %.3f", event.getDeltaX(), event.getDeltaY())); double z = subSceneCamera.getTranslateZ(); double newZ = z + event.getDeltaY(); subSceneCamera.setTranslateZ(newZ); } }); }
From source file:net.rptools.tokentool.controller.TokenTool_Controller.java
@FXML void compositeTokenPane_OnScroll(ScrollEvent event) { // if event is touch enabled, skip this as it will be handled by onZoom & onRotate handlers if (event.isDirect()) return;/*w w w . ja va 2 s .c o m*/ if (event.isShiftDown()) { // Note: OK, this is stupid but on Windows shift + mousewheel returns X delta but on Ubuntu it returns Y delta... double delta = event.getDeltaY(); if (delta == 0) delta = event.getDeltaX(); Double r = portraitImageView.getRotate() + delta / 20; if (r < -360d || r > 360d) r = 0d; portraitImageView.setRotate(r); } else { Double scale = portraitImageView.getScaleY() * Math.pow(1.001, event.getDeltaY()); portraitImageView.setScaleX(scale); portraitImageView.setScaleY(scale); } event.consume(); updateTokenPreviewImageView(); }
From source file:fr.amap.lidar.amapvox.gui.MainFrameController.java
private void showImage(File file) { try {/* ww w . j av a 2 s . co m*/ ImageView iv = new ImageView(new Image(file.toURI().toURL().toString())); iv.setPreserveRatio(true); Stage stage = new Stage(); final DoubleProperty zoomProperty = new SimpleDoubleProperty(200); zoomProperty.addListener(new InvalidationListener() { @Override public void invalidated(javafx.beans.Observable observable) { iv.setFitWidth(zoomProperty.get() * 4); iv.setFitHeight(zoomProperty.get() * 3); } }); ScrollPane sp = new ScrollPane(iv); stage.addEventFilter(ScrollEvent.ANY, new EventHandler<ScrollEvent>() { @Override public void handle(ScrollEvent event) { if (event.getDeltaY() > 0) { zoomProperty.set(zoomProperty.get() * 1.1); } else if (event.getDeltaY() < 0) { zoomProperty.set(zoomProperty.get() / 1.1); } } }); stage.setScene(new Scene(new Group(sp))); stage.sizeToScene(); stage.show(); } catch (IOException ex) { showErrorDialog(ex); } }