Example usage for javafx.scene.input MouseEvent getSceneX

List of usage examples for javafx.scene.input MouseEvent getSceneX

Introduction

In this page you can find the example usage for javafx.scene.input MouseEvent getSceneX.

Prototype

public final double getSceneX() 

Source Link

Document

Returns horizontal position of the event relative to the origin of the Scene that contains the MouseEvent's source.

Usage

From source file:Main.java

public static void addDraggableNode(final Node node) {

    node.setOnMousePressed((MouseEvent me) -> {
        dragInitialX = me.getSceneX();
        dragInitialY = me.getSceneY();//  www.  java  2s  . c om
    });

    node.setOnMouseDragged((MouseEvent me) -> {
        node.getScene().getWindow().setX(me.getScreenX() - dragInitialX);
        node.getScene().getWindow().setY(me.getScreenY() - dragInitialY);
    });
}

From source file:Main.java

public static void addMarker(final XYChart<?, ?> chart, final StackPane chartWrap) {
    final Line valueMarker = new Line();
    final Node chartArea = chart.lookup(".chart-plot-background");

    chartArea.setOnMouseMoved(new EventHandler<MouseEvent>() {
        @Override//from ww  w  . j av a 2 s. c  om
        public void handle(MouseEvent event) {
            Point2D scenePoint = chart.localToScene(event.getSceneX(), event.getSceneY());
            Point2D position = chartWrap.sceneToLocal(scenePoint.getX(), scenePoint.getY());

            Bounds chartAreaBounds = chartArea.localToScene(chartArea.getBoundsInLocal());
            valueMarker.setStartY(0);
            valueMarker.setEndY(chartWrap.sceneToLocal(chartAreaBounds).getMaxY()
                    - chartWrap.sceneToLocal(chartAreaBounds).getMinY());

            valueMarker.setStartX(0);
            valueMarker.setEndX(0);
            valueMarker.setTranslateX(position.getX() - chartWrap.getWidth() / 2);

            double ydelta = chartArea.localToScene(0, 0).getY() - chartWrap.localToScene(0, 0).getY();
            valueMarker.setTranslateY(-ydelta * 2);
        }
    });

    chartWrap.getChildren().add(valueMarker);
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setTitle("Imported Fruits");
    stage.setWidth(500);/*from w  ww.  j  a va 2 s  . c  o m*/
    stage.setHeight(500);

    ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
            new PieChart.Data("Grapefruit", 13), new PieChart.Data("Oranges", 25),
            new PieChart.Data("Plums", 10), new PieChart.Data("Pears", 22), new PieChart.Data("Apples", 30));

    final PieChart chart = new PieChart(pieChartData);
    chart.setTitle("Imported Fruits");
    final Label caption = new Label("");
    caption.setTextFill(Color.DARKORANGE);
    caption.setStyle("-fx-font: 24 arial;");

    for (final PieChart.Data data : chart.getData()) {
        data.getNode().addEventHandler(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent e) {
                caption.setTranslateX(e.getSceneX());
                caption.setTranslateY(e.getSceneY());
                caption.setText(String.valueOf(data.getPieValue()) + "%");
            }
        });
    }

    ((Group) scene.getRoot()).getChildren().addAll(chart, caption);
    stage.setScene(scene);
    //scene.getStylesheets().add("piechartsample/Chart.css");
    stage.show();
}

From source file:nars.rl.util.ThreeDView.java

private void handleMouse(Scene scene, final Node root) {
    scene.setOnMousePressed(new EventHandler<MouseEvent>() {
        @Override/*from   w w w . j  a  v a2  s  . c  o  m*/
        public void handle(MouseEvent me) {
            mousePosX = me.getSceneX();
            mousePosY = me.getSceneY();
            mouseOldX = me.getSceneX();
            mouseOldY = me.getSceneY();
        }
    });
    scene.setOnMouseDragged(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent me) {
            mouseOldX = mousePosX;
            mouseOldY = mousePosY;
            mousePosX = me.getSceneX();
            mousePosY = me.getSceneY();
            mouseDeltaX = (mousePosX - mouseOldX);
            mouseDeltaY = (mousePosY - mouseOldY);

            double modifier = 1.0;
            double modifierFactor = 0.1;

            if (me.isControlDown()) {
                modifier = 0.1;
            }
            if (me.isShiftDown()) {
                modifier = 10.0;
            }
            if (me.isPrimaryButtonDown()) {
                cameraXform.ry
                        .setAngle(cameraXform.ry.getAngle() - mouseDeltaX * modifierFactor * modifier * 2.0); // +
                cameraXform.rx
                        .setAngle(cameraXform.rx.getAngle() + mouseDeltaY * modifierFactor * modifier * 2.0); // -
            } else if (me.isSecondaryButtonDown()) {
                double z = camera.getTranslateZ();
                double newZ = z + mouseDeltaX * modifierFactor * modifier;
                camera.setTranslateZ(newZ);
            } else if (me.isMiddleButtonDown()) {
                cameraXform2.t.setX(cameraXform2.t.getX() + mouseDeltaX * modifierFactor * modifier * 0.3); // -
                cameraXform2.t.setY(cameraXform2.t.getY() + mouseDeltaY * modifierFactor * modifier * 0.3); // -
            }
        }
    });
}

From source file:com.rockhoppertech.symchords.fx.SymChordsController.java

protected void setupDragonDrop() {
    Image image = new Image(getClass().getResourceAsStream("/images/rocky-32-trans.png"));
    dragImageView = new ImageView(image);
    dragImageView.setFitHeight(32);//from w  w  w  .ja v  a 2s  . c om
    dragImageView.setFitWidth(32);

    grandStaff.setOnDragDetected(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent me) {

            if (!root.getChildren().contains(dragImageView)) {
                root.getChildren().add(dragImageView);
            }

            // dragImageView.setOpacity(0.5);
            dragImageView.toFront();
            dragImageView.setMouseTransparent(true);
            dragImageView.setVisible(true);
            dragImageView.relocate((int) (me.getSceneX() - dragImageView.getBoundsInLocal().getWidth() / 2),
                    (int) (me.getSceneY() - dragImageView.getBoundsInLocal().getHeight() / 2));

            Dragboard db = grandStaff.startDragAndDrop(TransferMode.ANY);

            // TODO remove the custom image nonsense in javafx 8
            // javafx 8
            // db.setDragView(dragImageView);

            ClipboardContent content = new ClipboardContent();
            // MIDITrack track = grandStaff.getMIDITrack();
            MIDITrack track = model.getMIDITrack();
            content.put(midiTrackDataFormat, track);
            db.setContent(content);
            me.consume();
        }
    });

    grandStaff.setOnDragDone(new EventHandler<DragEvent>() {
        public void handle(DragEvent e) {
            dragImageView.setVisible(false);
            e.consume();
        }
    });

    // Parent root = grandStaff.getScene().getRoot();
    // stage.getScene().getRoot();

    if (root != null) {
        root.setOnDragOver(new EventHandler<DragEvent>() {
            public void handle(DragEvent e) {
                Point2D localPoint = grandStaff.getScene().getRoot()
                        .sceneToLocal(new Point2D(e.getSceneX(), e.getSceneY()));
                dragImageView.relocate(
                        (int) (localPoint.getX() - dragImageView.getBoundsInLocal().getWidth() / 2),
                        (int) (localPoint.getY() - dragImageView.getBoundsInLocal().getHeight() / 2));
                e.consume();
            }
        });
    }

    trackList.setOnDragOver(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /*
             * data is dragged over the target; accept it only if it is not
             * dragged from the same node and if it has MIDITrack data
             */
            if (event.getGestureSource() != trackList && event.getDragboard().hasContent(midiTrackDataFormat)) {
                logger.debug("drag over");
                /* allow for both copying and moving, whatever user chooses */
                event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
            }

            // Don't consume the event. Let the layers below process the
            // DragOver event as well so that the
            // translucent container image will follow the cursor.
            // event.consume();
        }
    });

    trackList.setOnDragEntered(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* the drag-and-drop gesture entered the target */
            /* show to the user that it is an actual gesture target */
            logger.debug("drag entered");
            if (event.getGestureSource() != trackList && event.getDragboard().hasContent(midiTrackDataFormat)) {
                DropShadow dropShadow = new DropShadow();
                dropShadow.setRadius(5.0);
                dropShadow.setOffsetX(3.0);
                dropShadow.setOffsetY(3.0);
                dropShadow.setColor(Color.color(0.4, 0.5, 0.5));
                trackList.setEffect(dropShadow);
            }
            event.consume();
        }
    });

    trackList.setOnDragExited(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* mouse moved away, remove the graphical cues */
            trackList.setEffect(null);
            event.consume();
        }
    });

    trackList.setOnDragDropped(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {

            Dragboard db = event.getDragboard();
            boolean success = false;
            if (db.hasContent(midiTrackDataFormat)) {
                MIDITrack track = (MIDITrack) db.getContent(midiTrackDataFormat);
                trackList.getItems().add(track);
                success = true;

            }
            /*
             * let the source know whether the data was successfully
             * transferred and used
             */
            event.setDropCompleted(success);
            event.consume();
        }
    });

    logger.debug("jvm mime {}", DataFlavor.javaJVMLocalObjectMimeType);
}

From source file:editeurpanovisu.EditeurPanovisu.java

private void gereSourisPanoramique(MouseEvent me) {
    if (me.getButton() == MouseButton.SECONDARY) {
        if (me.isShiftDown()) {
            panoChoixNord(me.getSceneX() - imagePanoramique.getLayoutX());
            me.consume();/*from   w  w  w .  ja  v  a  2  s.co m*/
        } else if (me.isControlDown()) {
        } else {
            panoChoixRegard(me.getSceneX() - imagePanoramique.getLayoutX(), me.getSceneY());
            me.consume();
        }
    }
    if (me.getButton() == MouseButton.PRIMARY) {
        if (me.isShiftDown()) {
            if (!me.isControlDown()) {
                if (!dragDrop) {
                    panoAjouteImage(me.getSceneX() - imagePanoramique.getLayoutX(), me.getSceneY());
                } else {
                    dragDrop = false;
                }
            } else {

            }
        } else if (!(me.isControlDown()) && estCharge) {
            if (!dragDrop) {
                panoMouseClic(me.getSceneX() - imagePanoramique.getLayoutX(), me.getSceneY());
            } else {
                dragDrop = false;
            }
        }
    }
}

From source file:editeurpanovisu.EditeurPanovisu.java

private void afficheNord(double longitude) {
    double largeur = imagePanoramique.getFitWidth();
    double X = (longitude + 180.0d) * largeur / 360.0d + imagePanoramique.getLayoutX();
    Node ancPoV = (Node) pano.lookup("#Nord");
    if (ancPoV != null) {
        pano.getChildren().remove(ancPoV);
    }//from w  ww .  j  a  v a 2  s. co  m
    Line ligne = new Line(0, 0, 0, imagePanoramique.getFitHeight());
    ligne.setCursor(Cursor.DEFAULT);

    ligne.setLayoutX(X);
    ligne.setStroke(Color.RED);
    ligne.setStrokeWidth(4);
    ligne.setId("Nord");
    ligne.setOnDragDetected((MouseEvent me1) -> {
        ligne.setStroke(Color.BLUEVIOLET);
        dragDrop = true;
        me1.consume();
    });
    ligne.setOnMouseDragged((MouseEvent me1) -> {

        double XX = me1.getSceneX() - imagePanoramique.getLayoutX();
        if (XX < 0) {
            XX = 0;
        }
        if (XX > imagePanoramique.getFitWidth()) {
            XX = imagePanoramique.getFitWidth();
        }
        ligne.setLayoutX(XX + imagePanoramique.getLayoutX());
        me1.consume();

    });
    ligne.setOnMouseReleased((MouseEvent me1) -> {
        double X1 = me1.getSceneX();
        double mouseX1 = X1 - imagePanoramique.getLayoutX();
        if (mouseX1 < 0) {
            mouseX1 = 0;
        }
        if (mouseX1 > imagePanoramique.getFitWidth()) {
            mouseX1 = imagePanoramique.getFitWidth();
        }
        double regardX = 360.0f * mouseX1 / largeur - 180;
        panoramiquesProjet[panoActuel].setZeroNord(regardX);
        ligne.setStroke(Color.RED);
        me1.consume();

    });

    pano.getChildren().add(ligne);
}

From source file:editeurpanovisu.EditeurPanovisu.java

/**
 *
 *//*from w  ww  . ja  v a2  s.com*/
private void installeEvenements() {
    /**
     *
     */
    scene.widthProperty().addListener(
            (ObservableValue<? extends Number> observableValue, Number oldSceneWidth, Number newSceneWidth) -> {
                double largeur = (double) newSceneWidth - 320.0d;
                vuePanoramique.setPrefWidth(largeur);
            });
    /**
     *
     */
    scene.heightProperty().addListener((ObservableValue<? extends Number> observableValue,
            Number oldSceneHeight, Number newSceneHeight) -> {
        vuePanoramique.setPrefHeight((double) newSceneHeight - 70.0d);
        panneauOutils.setPrefHeight((double) newSceneHeight - 70.0d);
    });

    /**
     *
     */
    pano.setOnMouseClicked((MouseEvent me) -> {
        gereSourisPanoramique(me);
    });
    /**
     *
     */
    pano.setOnMouseMoved((MouseEvent me) -> {
        if (estCharge) {
            double mouseX = me.getSceneX() - imagePanoramique.getLayoutX();
            if (mouseX < 0) {
                mouseX = 0;
            }
            if (mouseX > imagePanoramique.getFitWidth()) {
                mouseX = imagePanoramique.getFitWidth();
            }
            double mouseY = me.getSceneY() - pano.getLayoutY() - 109;
            if (mouseY < 0) {
                mouseY = 0;
            }
            if (mouseY > imagePanoramique.getFitHeight()) {
                mouseY = imagePanoramique.getFitHeight();
            }

            double longitude, latitude;
            double largeur = imagePanoramique.getFitWidth() * pano.getScaleX();
            longitude = 360.0f * mouseX / largeur - 180;
            latitude = 90.0d - 2.0f * mouseY / largeur * 180.0f;
            String chLong = "Long : " + String.format("%.1f", longitude);
            String chLat = "Lat : " + String.format("%.1f", latitude);
            lblLong.setText(chLong);
            lblLat.setText(chLat);
        }
    });
    /*
            
     */
    listeChoixPanoramiqueEntree.valueProperty().addListener(new ChangeListenerImplEntree());
    listeChoixPanoramique.valueProperty().addListener(new ChangeListenerImpl());

}

From source file:editeurpanovisu.EditeurPanovisu.java

private void affichePoV(double longitude, double latitude) {
    double largeur = imagePanoramique.getFitWidth();
    double X = (longitude + 180.0d) * largeur / 360.0d + imagePanoramique.getLayoutX();
    double Y = (90.0d - latitude) * largeur / 360.0d;
    Node ancPoV = (Node) pano.lookup("#PoV");
    if (ancPoV != null) {
        pano.getChildren().remove(ancPoV);
    }/*  w  w  w.j  ava  2 s .  c o  m*/
    Polygon polygon = new Polygon();
    polygon.getPoints().addAll(new Double[] { 20.0, 2.0, 2.0, 2.0, 2.0, 20.0, -2.0, 20.0, -2.0, 2.0, -20.0, 2.0,
            -20.0, -2.0, -2.0, -2.0, -2.0, -20.0, 2.0, -20.0, 2.0, -2.0, 20.0, -2.0 });
    polygon.setStrokeLineJoin(StrokeLineJoin.MITER);
    polygon.setFill(Color.BLUEVIOLET);
    polygon.setStroke(Color.YELLOW);
    polygon.setId("PoV");
    polygon.setLayoutX(X);
    polygon.setLayoutY(Y);
    polygon.setCursor(Cursor.DEFAULT);
    polygon.setOnDragDetected((MouseEvent me1) -> {
        polygon.setFill(Color.YELLOW);
        polygon.setStroke(Color.BLUEVIOLET);
        dragDrop = true;
        me1.consume();

    });
    polygon.setOnMouseDragged((MouseEvent me1) -> {

        double XX = me1.getSceneX() - imagePanoramique.getLayoutX();
        if (XX < 0) {
            XX = 0;
        }
        if (XX > imagePanoramique.getFitWidth()) {
            XX = imagePanoramique.getFitWidth();
        }
        polygon.setLayoutX(XX + imagePanoramique.getLayoutX());
        double YY = me1.getSceneY() - pano.getLayoutY() - 109;
        if (YY < 0) {
            YY = 0;
        }
        if (YY > imagePanoramique.getFitHeight()) {
            YY = imagePanoramique.getFitHeight();
        }
        polygon.setLayoutY(YY);

        me1.consume();

    });
    polygon.setOnMouseReleased((MouseEvent me1) -> {
        double X1 = me1.getSceneX();
        double Y1 = me1.getSceneY();
        double mouseX1 = X1 - imagePanoramique.getLayoutX();
        if (mouseX1 < 0) {
            mouseX1 = 0;
        }
        if (mouseX1 > imagePanoramique.getFitWidth()) {
            mouseX1 = imagePanoramique.getFitWidth();
        }
        double mouseY1 = Y1 - pano.getLayoutY() - 109;
        if (mouseY1 < 0) {
            mouseY1 = 0;
        }
        if (mouseY1 > imagePanoramique.getFitHeight()) {
            mouseY1 = imagePanoramique.getFitHeight();
        }
        double regardX = 360.0f * mouseX1 / largeur - 180;
        double regardY = 90.0d - 2.0f * mouseY1 / largeur * 180.0f;
        panoramiquesProjet[panoActuel].setLookAtX(regardX);
        panoramiquesProjet[panoActuel].setLookAtY(regardY);
        polygon.setFill(Color.BLUEVIOLET);
        polygon.setStroke(Color.YELLOW);
        me1.consume();

    });

    pano.getChildren().add(polygon);
}

From source file:editeurpanovisu.EditeurPanovisu.java

/**
 *
 * @param i/*from   w ww. j  a  v  a2  s  .  c om*/
 * @param longitude
 * @param latitude
 */
private void afficheHSImage(int i, double longitude, double latitude) {
    double largeur = imagePanoramique.getFitWidth();
    double X = (longitude + 180.0d) * largeur / 360.0d + imagePanoramique.getLayoutX();
    double Y = (90.0d - latitude) * largeur / 360.0d;
    Circle point = new Circle(X, Y, 5);
    point.setFill(Color.BLUE);
    point.setStroke(Color.YELLOW);
    point.setId("img" + i);
    point.setCursor(Cursor.DEFAULT);
    pano.getChildren().add(point);
    Tooltip t = new Tooltip("image n " + (i + 1));
    t.setStyle(tooltipStyle);
    Tooltip.install(point, t);
    point.setOnDragDetected((MouseEvent me1) -> {
        point.setFill(Color.YELLOW);
        point.setStroke(Color.BLUE);
        dragDrop = true;
        me1.consume();

    });
    point.setOnMouseDragged((MouseEvent me1) -> {
        double XX = me1.getX() - imagePanoramique.getLayoutX();
        if (XX < 0) {
            XX = 0;
        }
        if (XX > imagePanoramique.getFitWidth()) {
            XX = imagePanoramique.getFitWidth();
        }
        point.setCenterX(XX + imagePanoramique.getLayoutX());
        double YY = me1.getY();
        if (YY < 0) {
            YY = 0;
        }
        if (YY > imagePanoramique.getFitHeight()) {
            YY = imagePanoramique.getFitHeight();
        }
        point.setCenterY(YY);

        me1.consume();

    });
    point.setOnMouseReleased((MouseEvent me1) -> {
        String chPoint = point.getId();
        chPoint = chPoint.substring(3, chPoint.length());
        int numeroPoint = Integer.parseInt(chPoint);
        double X1 = me1.getSceneX();
        double Y1 = me1.getSceneY();
        double mouseX = X1 - imagePanoramique.getLayoutX();
        if (mouseX < 0) {
            mouseX = 0;
        }
        if (mouseX > imagePanoramique.getFitWidth()) {
            mouseX = imagePanoramique.getFitWidth();
        }
        double mouseY = Y1 - pano.getLayoutY() - 109;
        if (mouseY < 0) {
            mouseY = 0;
        }
        if (mouseY > imagePanoramique.getFitHeight()) {
            mouseY = imagePanoramique.getFitHeight();
        }

        double longit, lat;
        double larg = imagePanoramique.getFitWidth();
        String chLong, chLat;
        longit = 360.0f * mouseX / larg - 180;
        lat = 90.0d - 2.0f * mouseY / larg * 180.0f;
        panoramiquesProjet[panoActuel].getHotspotImage(numeroPoint).setLatitude(lat);
        panoramiquesProjet[panoActuel].getHotspotImage(numeroPoint).setLongitude(longit);
        point.setFill(Color.BLUE);
        point.setStroke(Color.YELLOW);
        me1.consume();

    });

    point.setOnMouseClicked((MouseEvent me1) -> {
        String chPoint = point.getId();
        chPoint = chPoint.substring(3, chPoint.length());
        int numeroPoint = Integer.parseInt(chPoint);
        Node pt;
        pt = (Node) pano.lookup("#img" + chPoint);

        if (me1.isControlDown()) {
            valideHS();
            dejaSauve = false;
            stPrincipal.setTitle(stPrincipal.getTitle().replace(" *", "") + " *");
            pano.getChildren().remove(pt);

            for (int o = numeroPoint + 1; o < numImages; o++) {
                pt = (Node) pano.lookup("#img" + Integer.toString(o));
                pt.setId("img" + Integer.toString(o - 1));
            }
            /**
             * on retire les anciennes indication de HS
             */
            retireAffichageHotSpots();
            numImages--;
            panoramiquesProjet[panoActuel].removeHotspotImage(numeroPoint);
            /**
             * On les cre les nouvelles
             */
            ajouteAffichageHotspots();
            me1.consume();
        } else {
            me1.consume();
        }

    });
}