Example usage for javafx.scene.input ScrollEvent consume

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

Introduction

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

Prototype

public void consume() 

Source Link

Document

Marks this Event as consumed.

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.j a v  a  2  s  . c om
    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: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   w  ww  .j ava 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:uk.bl.dpt.qa.gui.DissimilarGUIThread.java

@FXML
void mouseScroll(ScrollEvent event) {

    event.consume();
    final double diff = 0.1;

    //scroll pane locations
    final double h = scrollPaneLeft.getHvalue();
    final double v = scrollPaneLeft.getVvalue();

    final double min = 400;

    if (event.getDeltaY() > 0 && ((imageLeft.getBoundsInParent().getWidth() < min)
            || imageLeft.getBoundsInParent().getHeight() < min)) {
        return;//  w  ww  . j  a  va2  s .com
    }

    if (event.getDeltaY() < 0) {
        imageLeft.setScaleX(imageLeft.getScaleX() + diff);
        imageLeft.setScaleY(imageLeft.getScaleY() + diff);
    } else {
        imageLeft.setScaleX(imageLeft.getScaleX() - diff);
        imageLeft.setScaleY(imageLeft.getScaleY() - diff);
    }
    imageRight.setScaleX(imageLeft.getScaleX());
    imageRight.setScaleY(imageLeft.getScaleY());

    //just set the same ratio of scroll - this should work out mostly ok
    scrollPaneLeft.setHvalue(h);
    scrollPaneLeft.setVvalue(v);

}