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:editeurpanovisu.EditeurPanovisu.java

/**
 *
 * @param i/*from   w  w w.  ja va  2  s  .  c  o m*/
 * @param longitude
 * @param latitude
 */
private void afficheHS(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.YELLOW);
    point.setStroke(Color.RED);
    point.setId("point" + i);
    point.setCursor(Cursor.DEFAULT);
    pano.getChildren().add(point);

    Tooltip t = new Tooltip("point n " + (i + 1));
    t.setStyle(tooltipStyle);
    Tooltip.install(point, t);
    point.setOnDragDetected((MouseEvent me1) -> {
        point.setFill(Color.RED);
        point.setStroke(Color.YELLOW);
        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(5, 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].getHotspot(numeroPoint).setLatitude(lat);
        panoramiquesProjet[panoActuel].getHotspot(numeroPoint).setLongitude(longit);
        point.setFill(Color.YELLOW);
        point.setStroke(Color.RED);
        me1.consume();

    });

    point.setOnMouseClicked((MouseEvent me1) -> {
        double mouseX = me1.getSceneX() - imagePanoramique.getLayoutX();
        if (mouseX < 0) {
            mouseX = 0;
        }
        if (mouseX > imagePanoramique.getFitWidth()) {
            mouseX = imagePanoramique.getFitWidth();
        }

        double mouseY = me1.getSceneY() - pano.getLayoutY() - 115;
        if (mouseY < 0) {
            mouseY = 0;
        }
        if (mouseY > imagePanoramique.getFitHeight()) {
            mouseY = imagePanoramique.getFitHeight();
        }

        String chPoint = point.getId();
        chPoint = chPoint.substring(5, chPoint.length());
        int numeroPoint = Integer.parseInt(chPoint);
        Node pt;
        pt = (Node) pano.lookup("#point" + chPoint);

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

            for (int o = numeroPoint + 1; o < numPoints; o++) {
                pt = (Node) pano.lookup("#point" + Integer.toString(o));
                pt.setId("point" + Integer.toString(o - 1));
            }
            /**
             * on retire les anciennes indication de HS
             */
            retireAffichageHotSpots();
            numPoints--;
            panoramiquesProjet[panoActuel].removeHotspot(numeroPoint);
            /**
             * On les cre les nouvelles
             */
            ajouteAffichageHotspots();
            me1.consume();
            valideHS();
        } else {
            if (!dragDrop) {
                if (nombrePanoramiques > 1) {
                    AnchorPane listePanoVig = afficherListePanosVignettes(numeroPoint);
                    int largeurVignettes = 4;
                    if (nombrePanoramiques < 4) {
                        largeurVignettes = nombrePanoramiques;
                    }
                    if (mouseX + largeurVignettes * 130 > pano.getWidth()) {
                        listePanoVig.setLayoutX(pano.getWidth() - largeurVignettes * 130);
                    } else {
                        listePanoVig.setLayoutX(mouseX);
                    }
                    listePanoVig.setLayoutY(mouseY);
                    pano.getChildren().add(listePanoVig);
                }
            } else {
                dragDrop = false;
            }
            valideHS();
            me1.consume();

        }

    });
}

From source file:editeurpanovisu.EditeurPanovisu.java

private void panoAjouteImage(double X, double Y) {
    if (X > 0 && X < imagePanoramique.getFitWidth()) {

        valideHS();//from  w  ww  .  j  a va 2s  .com
        dejaSauve = false;
        stPrincipal.setTitle(stPrincipal.getTitle().replace(" *", "") + " *");
        double mouseX = X;
        double mouseY = Y - pano.getLayoutY() - 115;
        double longitude, latitude;
        double largeur = imagePanoramique.getFitWidth();
        String chLong, chLat;
        longitude = 360.0f * mouseX / largeur - 180;
        latitude = 90.0d - 2.0f * mouseY / largeur * 180.0f;
        Circle point = new Circle(mouseX, mouseY, 5);
        point.setFill(Color.BLUE);
        point.setStroke(Color.YELLOW);
        point.setId("img" + numImages);
        point.setCursor(Cursor.DEFAULT);
        pano.getChildren().add(point);
        Tooltip t = new Tooltip("image n " + (numImages + 1));
        t.setStyle(tooltipStyle);
        Tooltip.install(point, t);

        //
        File repert;
        if (repertHSImages.equals("")) {
            repert = new File(currentDir + File.separator);
        } else {
            repert = new File(repertHSImages);
        }
        FileChooser fileChooser = new FileChooser();
        FileChooser.ExtensionFilter extFilterImages = new FileChooser.ExtensionFilter(
                "Fichiers Images (jpg, bmp, png)", "*.jpg", "*.bmp", "*.png");

        fileChooser.setInitialDirectory(repert);
        fileChooser.getExtensionFilters().addAll(extFilterImages);

        File fichierImage = fileChooser.showOpenDialog(null);
        if (fichierImage != null) {
            repertHSImages = fichierImage.getParent();
            numImages++;
            HotspotImage HS = new HotspotImage();
            HS.setLongitude(longitude);
            HS.setLatitude(latitude);
            HS.setUrlImage(fichierImage.getAbsolutePath());
            HS.setLienImg(fichierImage.getName());
            HS.setInfo(fichierImage.getName().split("\\.")[0]);
            File repertImage = new File(repertTemp + File.separator + "images");
            if (!repertImage.exists()) {
                repertImage.mkdirs();
            }
            try {
                copieFichierRepertoire(fichierImage.getAbsolutePath(), repertImage.getAbsolutePath());
            } catch (IOException ex) {
                Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex);
            }
            panoramiquesProjet[panoActuel].addHotspotImage(HS);
            retireAffichageHotSpots();
            Pane affHS1 = affichageHS(listePano(panoActuel), panoActuel);
            affHS1.setId("labels");
            outils.getChildren().add(affHS1);

        } else {
            String chPoint = point.getId();
            chPoint = chPoint.substring(3, chPoint.length());
            Node pt = (Node) pano.lookup("#img" + chPoint);
            pano.getChildren().remove(pt);
        }
        valideHS();
        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 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 longit, lat;
            double larg = imagePanoramique.getFitWidth();
            longit = 360.0f * mouseX1 / larg - 180;
            lat = 90.0d - 2.0f * mouseY1 / 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) -> {
            if (me1.isControlDown()) {
                dejaSauve = false;
                stPrincipal.setTitle(stPrincipal.getTitle().replace(" *", "") + " *");
                String chPoint = point.getId();
                chPoint = chPoint.substring(3, chPoint.length());
                int numeroPoint = Integer.parseInt(chPoint);
                Node pt;
                pt = (Node) pano.lookup("#img" + chPoint);
                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();
            }
            valideHS();
            me1.consume();
        });

    }
}

From source file:editeurpanovisu.EditeurPanovisu.java

private void panoMouseClic(double X, double Y) {

    if (nombrePanoramiques > 1) {
        valideHS();//  ww w.  j  a va  2 s  . co  m
        dejaSauve = false;
        stPrincipal.setTitle(stPrincipal.getTitle().replace(" *", "") + " *");
        double mouseX = X;
        double mouseY = Y - pano.getLayoutY() - 109;
        if (X > 0 && X < imagePanoramique.getFitWidth()) {
            double longitude, latitude;
            double largeur = imagePanoramique.getFitWidth();
            String chLong, chLat;
            longitude = 360.0f * mouseX / largeur - 180;
            latitude = 90.0d - 2.0f * mouseY / largeur * 180.0f;
            Circle point = new Circle(mouseX + imagePanoramique.getLayoutX(), mouseY, 5);
            point.setFill(Color.YELLOW);
            point.setStroke(Color.RED);
            point.setId("point" + numPoints);
            point.setCursor(Cursor.DEFAULT);
            pano.getChildren().add(point);
            Tooltip t = new Tooltip("point n" + (numPoints + 1));
            t.setStyle(tooltipStyle);
            Tooltip.install(point, t);
            HotSpot HS = new HotSpot();
            HS.setLongitude(longitude);
            HS.setLatitude(latitude);
            panoramiquesProjet[panoActuel].addHotspot(HS);
            retireAffichageHotSpots();
            Pane affHS1 = affichageHS(listePano(panoActuel), panoActuel);
            affHS1.setId("labels");
            outils.getChildren().add(affHS1);

            numPoints++;
            if (nombrePanoramiques > 1) {

                AnchorPane listePanoVig = afficherListePanosVignettes(
                        panoramiquesProjet[panoActuel].getNombreHotspots() - 1);
                int largeurVignettes = 4;
                if (nombrePanoramiques < 4) {
                    largeurVignettes = nombrePanoramiques;
                }
                if (mouseX + largeurVignettes * 130 > pano.getWidth()) {
                    listePanoVig.setLayoutX(pano.getWidth() - largeurVignettes * 130);
                } else {
                    listePanoVig.setLayoutX(mouseX);
                }
                listePanoVig.setLayoutY(mouseY);
                pano.getChildren().add(listePanoVig);
                valideHS();
            }
            point.setOnDragDetected((MouseEvent me1) -> {
                String chPoint = point.getId();
                chPoint = chPoint.substring(5, chPoint.length());
                int numeroPoint = Integer.parseInt(chPoint);
                Node pt;
                pt = (Node) pano.lookup("#point" + chPoint);
                point.setFill(Color.RED);
                point.setStroke(Color.YELLOW);
                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(5, chPoint.length());
                int numeroPoint = Integer.parseInt(chPoint);
                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 longit, lat;
                double larg = imagePanoramique.getFitWidth();
                longit = 360.0f * mouseX1 / larg - 180;
                lat = 90.0d - 2.0f * mouseY1 / larg * 180.0f;
                panoramiquesProjet[panoActuel].getHotspot(numeroPoint).setLatitude(lat);
                panoramiquesProjet[panoActuel].getHotspot(numeroPoint).setLongitude(longit);
                point.setFill(Color.YELLOW);
                point.setStroke(Color.RED);
                me1.consume();

            });

            point.setOnMouseClicked((MouseEvent me1) -> {
                if (me1.isControlDown()) {
                    dejaSauve = false;
                    stPrincipal.setTitle(stPrincipal.getTitle().replace(" *", "") + " *");
                    String chPoint = point.getId();
                    chPoint = chPoint.substring(5, chPoint.length());
                    int numeroPoint = Integer.parseInt(chPoint);
                    Node pt;
                    pt = (Node) pano.lookup("#point" + chPoint);
                    pano.getChildren().remove(pt);

                    for (int o = numeroPoint + 1; o < numPoints; o++) {
                        pt = (Node) pano.lookup("#point" + Integer.toString(o));
                        pt.setId("point" + Integer.toString(o - 1));
                    }
                    /**
                     * on retire les anciennes indication de HS
                     */
                    retireAffichageHotSpots();
                    numPoints--;
                    panoramiquesProjet[panoActuel].removeHotspot(numeroPoint);
                    /**
                     * On les cre les nouvelles
                     */
                    ajouteAffichageHotspots();
                    valideHS();
                    me1.consume();
                } else {
                    if (!dragDrop) {
                        String chPoint = point.getId();
                        chPoint = chPoint.substring(5, chPoint.length());
                        int numeroPoint = Integer.parseInt(chPoint);
                        if (nombrePanoramiques > 1) {
                            AnchorPane listePanoVig = afficherListePanosVignettes(numeroPoint);
                            int largeurVignettes = 4;
                            if (nombrePanoramiques < 4) {
                                largeurVignettes = nombrePanoramiques;
                            }
                            if (mouseX + largeurVignettes * 130 > pano.getWidth()) {
                                listePanoVig.setLayoutX(pano.getWidth() - largeurVignettes * 130);
                            } else {
                                listePanoVig.setLayoutX(mouseX);
                            }
                            listePanoVig.setLayoutY(mouseY);
                            pano.getChildren().add(listePanoVig);
                        }
                    } else {
                        dragDrop = false;
                    }
                    valideHS();
                    me1.consume();

                }
            });
        }
    }
}

From source file:editeurpanovisu.EditeurPanovisu.java

/**
 *
 * @param mouseEvent/*from  w  w  w  . j  ava  2s.c  om*/
 */
private static void gereSourisPanoramique(MouseEvent mouseEvent) {
    if (mouseEvent.getButton() == MouseButton.SECONDARY) {
        if (mouseEvent.isShiftDown()) {
            panoChoixNord(mouseEvent.getSceneX() - ivImagePanoramique.getLayoutX());
            mouseEvent.consume();
        } else if (mouseEvent.isControlDown()) {
        } else {
            panoChoixRegard(mouseEvent.getSceneX() - ivImagePanoramique.getLayoutX(),
                    mouseEvent.getSceneY() - getiDecalageMac());
            mouseEvent.consume();
        }
    }
    if (mouseEvent.getButton() == MouseButton.PRIMARY) {
        if (!(mouseEvent.isControlDown()) && bEstCharge) {
            if (!bDragDrop) {
                panePanoramique.setCursor(Cursor.DEFAULT);
                panePanoramique.setOnMouseClicked((me) -> {
                });
                Circle c1 = new Circle(mouseEvent.getSceneX(),
                        mouseEvent.getSceneY() - panePanoramique.getLayoutY() - 130 - getiDecalageMac(), 3);
                panePanoramique.getChildren().add(c1);
                ListView<String> lvMenuChoixTypeHotspot = new ListView<>();
                double tailleFenetre = 70;
                if (getiNombrePanoramiques() > 1) {
                    lvMenuChoixTypeHotspot.getItems().add("Panoramique");
                    tailleFenetre += 20;
                }
                lvMenuChoixTypeHotspot.getItems().add("Image");
                if (getiNombreDiapo() > 0) {
                    lvMenuChoixTypeHotspot.getItems().add("Diaporama");
                    tailleFenetre += 20;
                }
                lvMenuChoixTypeHotspot.getItems().add("HTML");
                lvMenuChoixTypeHotspot.getItems().add("Annuler");
                lvMenuChoixTypeHotspot.setMaxHeight(tailleFenetre);
                lvMenuChoixTypeHotspot.setPrefHeight(tailleFenetre);
                lvMenuChoixTypeHotspot.setMinHeight(tailleFenetre);
                lvMenuChoixTypeHotspot.setPrefWidth(120);
                lvMenuChoixTypeHotspot.setCursor(Cursor.DEFAULT);
                lvMenuChoixTypeHotspot.setLayoutX(mouseEvent.getSceneX());
                lvMenuChoixTypeHotspot.setLayoutY(
                        mouseEvent.getSceneY() - panePanoramique.getLayoutY() - 104 - getiDecalageMac());
                panePanoramique.getChildren().add(lvMenuChoixTypeHotspot);
                lvMenuChoixTypeHotspot.getSelectionModel().selectedItemProperty()
                        .addListener((ov, ancValeur, nouvValeur) -> {
                            panePanoramique.getChildren().remove(lvMenuChoixTypeHotspot);
                            panePanoramique.getChildren().remove(c1);

                            switch (nouvValeur) {
                            case "Panoramique":
                                panoMouseClic(mouseEvent.getSceneX() - ivImagePanoramique.getLayoutX(),
                                        mouseEvent.getSceneY());
                                break;
                            case "Image":
                                panoAjouteImage(mouseEvent.getSceneX() - ivImagePanoramique.getLayoutX(),
                                        mouseEvent.getSceneY());
                                break;
                            case "HTML":
                                panoAjouteHTML(mouseEvent.getSceneX() - ivImagePanoramique.getLayoutX(),
                                        mouseEvent.getSceneY());
                                break;
                            case "Diaporama":
                                panoAjouteDiaporama(mouseEvent.getSceneX() - ivImagePanoramique.getLayoutX(),
                                        mouseEvent.getSceneY());
                                break;
                            case "Annuler":
                                break;

                            }
                            panePanoramique.setCursor(Cursor.CROSSHAIR);
                            panePanoramique.setOnMouseClicked((me) -> {
                                gereSourisPanoramique(me);
                            });

                        });

            } else {
                bDragDrop = false;
            }
        }
    }
}

From source file:view.EditorView.java

@FXML
void insertRoomOnMouseDragged(MouseEvent event) {
    Bounds scrollPaneBounds = scrollPaneContainer.localToScene(scrollPane.getBoundsInLocal());
    if (event.getSceneX() >= scrollPaneBounds.getMinX() && event.getSceneX() <= scrollPaneBounds.getMaxX()
            && event.getSceneY() >= scrollPaneBounds.getMinY()
            && event.getSceneY() <= scrollPaneBounds.getMaxY()) {
        // we're in the scroll pane
        if (!isMouseOverDrawing) {
            scrollPaneOnMouseEntered(event);
        }//w w w. j  ava2  s .com
    } else {
        if (isMouseOverDrawing) {
            scrollPaneOnMouseExited(event);
        }
    }
    scrollPaneOnMouseMoved(event);
}