Example usage for javafx.scene.input ScrollEvent getDeltaX

List of usage examples for javafx.scene.input ScrollEvent getDeltaX

Introduction

In this page you can find the example usage for javafx.scene.input ScrollEvent getDeltaX.

Prototype

public double getDeltaX() 

Source Link

Document

Gets the horizontal scroll amount.

Usage

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  w  w.ja v  a2  s  . 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: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()));
    });/*w w w.  ja v  a2  s  . c  om*/

    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   w ww .  j  a  v  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("#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;/*from  ww  w  .j a va 2  s .c  om*/

    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();
}