Example usage for javafx.scene.input TransferMode ANY

List of usage examples for javafx.scene.input TransferMode ANY

Introduction

In this page you can find the example usage for javafx.scene.input TransferMode ANY.

Prototype

TransferMode[] ANY

To view the source code for javafx.scene.input TransferMode ANY.

Click Source Link

Document

Array containing all transfer modes.

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    stage.setTitle("Hello Drag And Drop");

    Group root = new Group();
    Scene scene = new Scene(root, 400, 200);
    scene.setFill(Color.LIGHTGREEN);

    final Text source = new Text(50, 100, "DRAG ME");
    source.setScaleX(2.0);/*from www  . ja  v a  2 s.co  m*/
    source.setScaleY(2.0);

    final Text target = new Text(250, 100, "DROP HERE");
    target.setScaleX(2.0);
    target.setScaleY(2.0);

    source.setOnDragDetected(new EventHandler<MouseEvent>() {
        public void handle(MouseEvent event) {
            /* drag was detected, start drag-and-drop gesture*/
            System.out.println("onDragDetected");

            /* allow any transfer mode */
            Dragboard db = source.startDragAndDrop(TransferMode.ANY);

            /* put a string on dragboard */
            ClipboardContent content = new ClipboardContent();
            content.putString(source.getText());
            db.setContent(content);

            event.consume();
        }
    });

    target.setOnDragOver(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* data is dragged over the target */
            System.out.println("onDragOver");

            /* accept it only if it is  not dragged from the same node 
             * and if it has a string data */
            if (event.getGestureSource() != target && event.getDragboard().hasString()) {
                /* allow for both copying and moving, whatever user chooses */
                event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
            }

            event.consume();
        }
    });

    target.setOnDragEntered(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* the drag-and-drop gesture entered the target */
            System.out.println("onDragEntered");
            /* show to the user that it is an actual gesture target */
            if (event.getGestureSource() != target && event.getDragboard().hasString()) {
                target.setFill(Color.GREEN);
            }

            event.consume();
        }
    });

    target.setOnDragExited(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* mouse moved away, remove the graphical cues */
            target.setFill(Color.BLACK);

            event.consume();
        }
    });

    target.setOnDragDropped(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* data dropped */
            System.out.println("onDragDropped");
            /* if there is a string data on dragboard, read it and use it */
            Dragboard db = event.getDragboard();
            boolean success = false;
            if (db.hasString()) {
                target.setText(db.getString());
                success = true;
            }
            /* let the source know whether the string was successfully 
             * transferred and used */
            event.setDropCompleted(success);

            event.consume();
        }
    });

    source.setOnDragDone(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* the drag-and-drop gesture ended */
            System.out.println("onDragDone");
            /* if the data was successfully moved, clear it */
            if (event.getTransferMode() == TransferMode.MOVE) {
                source.setText("");
            }

            event.consume();
        }
    });

    root.getChildren().add(source);
    root.getChildren().add(target);
    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 300, 250);
    root.getChildren().addAll(source, target);

    source.setOnDragDetected(new EventHandler<MouseEvent>() {
        public void handle(MouseEvent event) {
            /* drag was detected, start a drag-and-drop gesture*/
            /* allow any transfer mode */
            Dragboard db = source.startDragAndDrop(TransferMode.ANY);

            /* Put a string on a dragboard */
            ClipboardContent content = new ClipboardContent();
            content.putString(source.getText());
            db.setContent(content);/*from  w  w  w.ja va  2s . co m*/

            event.consume();
        }
    });
    target.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 a string data */
            if (event.getGestureSource() != target && event.getDragboard().hasString()) {
                /* allow for moving */
                event.acceptTransferModes(TransferMode.MOVE);
            }

            event.consume();
        }
    });
    target.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 */
            if (event.getGestureSource() != target && event.getDragboard().hasString()) {
                target.setFill(Color.GREEN);
            }

            event.consume();
        }
    });
    target.setOnDragExited(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* mouse moved away, remove the graphical cues */
            target.setFill(Color.BLACK);

            event.consume();
        }
    });
    target.setOnDragDropped(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* data dropped */
            /* if there is a string data on dragboard, read it and use it */
            Dragboard db = event.getDragboard();
            boolean success = false;
            if (db.hasString()) {
                target.setText(db.getString());
                success = true;
            }
            /* let the source know whether the string was successfully 
             * transferred and used */
            event.setDropCompleted(success);

            event.consume();
        }
    });
    source.setOnDragDone(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* the drag and drop gesture ended */
            /* if the data was successfully moved, clear it */
            if (event.getTransferMode() == TransferMode.MOVE) {
                source.setText("");
            }
            event.consume();
        }
    });

    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:AudioPlayer3.java

private void initSceneDragAndDrop(Scene scene) {
    scene.setOnDragOver(new EventHandler<DragEvent>() {
        @Override//from   w ww.ja v  a  2s  . c  o  m
        public void handle(DragEvent event) {
            Dragboard db = event.getDragboard();
            if (db.hasFiles() || db.hasUrl()) {
                event.acceptTransferModes(TransferMode.ANY);
            }
            event.consume();
        }
    });

    scene.setOnDragDropped(new EventHandler<DragEvent>() {
        @Override
        public void handle(DragEvent event) {
            Dragboard db = event.getDragboard();
            String url = null;

            if (db.hasFiles()) {
                url = db.getFiles().get(0).toURI().toString();
            } else if (db.hasUrl()) {
                url = db.getUrl();
            }

            if (url != null) {
                songModel.setURL(url);
                songModel.getMediaPlayer().play();
            }

            event.setDropCompleted(url != null);
            event.consume();
        }
    });
}

From source file:com.heliosdecompiler.helios.gui.controller.FileTreeController.java

@FXML
public void startDrop(DragEvent event) {
    Dragboard db = event.getDragboard();
    if (db.hasFiles()) {
        event.acceptTransferModes(TransferMode.ANY);
    }
}

From source file:net.rptools.tokentool.controller.ManageOverlays_Controller.java

@FXML
void overlayViewFlowPane_DragOver(DragEvent event) {
    if (event.getDragboard().hasImage() || event.getDragboard().hasFiles() || event.getDragboard().hasUrl()) {
        // TODO: Set Pane color to an alpha green
        event.acceptTransferModes(TransferMode.COPY);
    } else {//from w ww  . j a  v  a  2 s .  c  o m
        // TODO: Set Pane color to an alpha red?
        event.acceptTransferModes(TransferMode.ANY);
    }
}

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);//  w  w  w  .j a v a2s . c  o m
    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:net.rptools.tokentool.controller.TokenTool_Controller.java

@FXML
void compositeTokenPane_DragOver(DragEvent event) {
    if (event.getDragboard().hasImage() || event.getDragboard().hasFiles() || event.getDragboard().hasUrl()) {
        // Set Pane color to an alpha green
        event.acceptTransferModes(TransferMode.COPY);
    } else {/*from  w w w.j a va 2  s.  c  om*/
        // Set Pane color to an alpha red?
        event.acceptTransferModes(TransferMode.ANY);
    }
}

From source file:net.rptools.tokentool.controller.TokenTool_Controller.java

@FXML
void tokenImageView_OnDragDetected(MouseEvent event) {
    Dragboard db = tokenImageView.startDragAndDrop(TransferMode.ANY);
    ClipboardContent content = new ClipboardContent();

    boolean saveAsToken = false;

    try {//  w w w  . j a va  2  s . c o  m
        File tempTokenFile = fileSaveUtil.getTempFileName(saveAsToken, useFileNumberingCheckbox.isSelected(),
                fileNameTextField.getText(), fileNameSuffixTextField);

        writeTokenImage(tempTokenFile);
        content.putFiles(java.util.Collections.singletonList(tempTokenFile));
        tempTokenFile.deleteOnExit();
    } catch (Exception e) {
        log.error(e);
    } finally {
        content.putImage(tokenImageView.getImage());
        db.setContent(content);
        event.consume();
    }
}

From source file:editeurpanovisu.EquiCubeDialogController.java

/**
 *
 * @param strTypeTransf/* w  ww . j a v a  2s  . co  m*/
 * @throws Exception Exceptions
 */
public void afficheFenetre(String strTypeTransf) throws Exception {
    lvListeFichier.getItems().clear();
    stTransformations = new Stage(StageStyle.UTILITY);
    apTransformations = new AnchorPane();
    stTransformations.initModality(Modality.APPLICATION_MODAL);
    stTransformations.setResizable(true);
    apTransformations.setStyle("-fx-background-color : #ff0000;");

    VBox vbFenetre = new VBox();
    HBox hbChoix = new HBox();
    Pane paneChoixFichier = new Pane();
    btnAjouteFichiers = new Button("Ajouter des Fichiers");
    paneChoixTypeFichier = new Pane();
    Label lblType = new Label("Type des Fichiers de sortie");
    rbJpeg = new RadioButton("JPEG (.jpg)");
    rbBmp = new RadioButton("BMP (.bmp)");
    rbTiff = new RadioButton("TIFF (.tif)");
    cbSharpen = new CheckBox("Masque de nettet");
    cbSharpen.setSelected(EditeurPanovisu.isbNetteteTransf());
    slSharpen = new Slider(0, 2, EditeurPanovisu.getNiveauNetteteTransf());
    lblSharpen = new Label();
    double lbl = (Math.round(EditeurPanovisu.getNiveauNetteteTransf() * 20.d) / 20.d);
    lblSharpen.setText(lbl + "");
    slSharpen.setDisable(!EditeurPanovisu.isbNetteteTransf());
    lblSharpen.setDisable(!EditeurPanovisu.isbNetteteTransf());
    Pane paneboutons = new Pane();
    btnAnnuler = new Button("Fermer la fentre");
    btnValider = new Button("Lancer le traitement");

    strTypeTransformation = strTypeTransf;
    Image imgTransf;
    if (strTypeTransf.equals(EquiCubeDialogController.EQUI2CUBE)) {
        stTransformations.setTitle("Transformation d'quirectangulaire en faces de cube");
        imgTransf = new Image(
                "file:" + EditeurPanovisu.getStrRepertAppli() + File.separator + "images/equi2cube.png");
    } else {
        stTransformations.setTitle("Transformation de faces de cube en quirectangulaire");
        imgTransf = new Image(
                "file:" + EditeurPanovisu.getStrRepertAppli() + File.separator + "images/cube2equi.png");
    }
    ImageView ivTypeTransfert = new ImageView(imgTransf);
    ivTypeTransfert.setLayoutX(35);
    ivTypeTransfert.setLayoutY(280);
    paneChoixTypeFichier.getChildren().add(ivTypeTransfert);
    apTransformations.setPrefHeight(EditeurPanovisu.getHauteurE2C());
    apTransformations.setPrefWidth(EditeurPanovisu.getLargeurE2C());

    paneChoixFichier.setPrefHeight(350);
    paneChoixFichier.setPrefWidth(410);
    paneChoixFichier.setStyle("-fx-background-color: #d0d0d0; -fx-border-color: #bbb;");
    paneChoixTypeFichier.setPrefHeight(350);
    paneChoixTypeFichier.setPrefWidth(180);
    paneChoixTypeFichier.setStyle("-fx-background-color: #d0d0d0; -fx-border-color: #bbb;");
    hbChoix.getChildren().addAll(paneChoixFichier, paneChoixTypeFichier);
    vbFenetre.setPrefHeight(400);
    vbFenetre.setPrefWidth(600);
    apTransformations.getChildren().add(vbFenetre);
    hbChoix.setPrefHeight(350);
    hbChoix.setPrefWidth(600);
    hbChoix.setStyle("-fx-background-color: #d0d0d0;");
    paneboutons.setPrefHeight(50);
    paneboutons.setPrefWidth(600);
    paneboutons.setStyle("-fx-background-color: #d0d0d0;");
    vbFenetre.setStyle("-fx-background-color: #d0d0d0;");
    btnAnnuler.setLayoutX(296);
    btnAnnuler.setLayoutY(10);
    btnValider.setLayoutX(433);
    btnValider.setLayoutY(10);
    lvListeFichier.setPrefHeight(290);
    lvListeFichier.setPrefWidth(380);
    lvListeFichier.setEditable(true);
    lvListeFichier.setLayoutX(14);
    lvListeFichier.setLayoutY(14);
    btnAjouteFichiers.setLayoutX(259);
    btnAjouteFichiers.setLayoutY(319);
    paneChoixFichier.getChildren().addAll(lvListeFichier, btnAjouteFichiers);
    if (strTypeTransf.equals(EquiCubeDialogController.EQUI2CUBE)) {
        lblDragDropE2C = new Label(rbLocalisation.getString("transformation.dragDropE2C"));
    } else {
        lblDragDropE2C = new Label(rbLocalisation.getString("transformation.dragDropC2E"));
    }
    lblDragDropE2C.setMinHeight(lvListeFichier.getPrefHeight());
    lblDragDropE2C.setMaxHeight(lvListeFichier.getPrefHeight());
    lblDragDropE2C.setMinWidth(lvListeFichier.getPrefWidth());
    lblDragDropE2C.setMaxWidth(lvListeFichier.getPrefWidth());
    lblDragDropE2C.setLayoutX(14);
    lblDragDropE2C.setLayoutY(14);
    lblDragDropE2C.setAlignment(Pos.CENTER);
    lblDragDropE2C.setTextFill(Color.web("#c9c7c7"));
    lblDragDropE2C.setTextAlignment(TextAlignment.CENTER);
    lblDragDropE2C.setWrapText(true);
    lblDragDropE2C.setStyle("-fx-font-size : 24px");
    lblDragDropE2C.setStyle("-fx-background-color : rgba(128,128,128,0.1)");
    paneChoixFichier.getChildren().add(lblDragDropE2C);

    lblType.setLayoutX(14);
    lblType.setLayoutY(14);
    rbBmp.setLayoutX(43);
    rbBmp.setLayoutY(43);
    rbBmp.setUserData("bmp");
    if (EditeurPanovisu.getStrTypeFichierTransf().equals("bmp")) {
        rbBmp.setSelected(true);
    }
    rbBmp.setToggleGroup(tgTypeFichier);
    rbJpeg.setLayoutX(43);
    rbJpeg.setLayoutY(71);
    rbJpeg.setUserData("jpg");
    if (EditeurPanovisu.getStrTypeFichierTransf().equals("jpg")) {
        rbJpeg.setSelected(true);
    }
    rbJpeg.setToggleGroup(tgTypeFichier);
    if (EditeurPanovisu.getStrTypeFichierTransf().equals("tif")) {
        rbTiff.setSelected(true);
    }
    rbTiff.setLayoutX(43);
    rbTiff.setLayoutY(99);
    rbTiff.setToggleGroup(tgTypeFichier);
    rbTiff.setUserData("tif");
    tgTypeFichier.selectedToggleProperty().addListener((ov, old_toggle, new_toggle) -> {
        EditeurPanovisu.setStrTypeFichierTransf(tgTypeFichier.getSelectedToggle().getUserData().toString());
    });
    cbSharpen.setLayoutX(43);
    cbSharpen.setLayoutY(127);
    cbSharpen.selectedProperty().addListener((ov, old_val, new_val) -> {
        slSharpen.setDisable(!new_val);
        lblSharpen.setDisable(!new_val);
        EditeurPanovisu.setbNetteteTransf(new_val);
    });

    slSharpen.setShowTickMarks(true);
    slSharpen.setShowTickLabels(true);
    slSharpen.setMajorTickUnit(0.5f);
    slSharpen.setMinorTickCount(4);
    slSharpen.setBlockIncrement(0.05f);
    slSharpen.setSnapToTicks(true);
    slSharpen.setLayoutX(23);
    slSharpen.setLayoutY(157);
    slSharpen.setTooltip(new Tooltip("Choisissez le niveau d'accentuation de l'image"));
    slSharpen.valueProperty().addListener((observableValue, oldValue, newValue) -> {
        if (newValue == null) {
            lblSharpen.setText("");
            return;
        }
        DecimalFormat dfArrondi = new DecimalFormat();
        dfArrondi.setMaximumFractionDigits(2); //arrondi  2 chiffres apres la virgules
        dfArrondi.setMinimumFractionDigits(2);
        dfArrondi.setDecimalSeparatorAlwaysShown(true);

        lblSharpen.setText(dfArrondi.format(Math.round(newValue.floatValue() * 20.f) / 20.f) + "");
        EditeurPanovisu.setNiveauNetteteTransf(newValue.doubleValue());
    });

    slSharpen.setPrefWidth(120);
    lblSharpen.setLayoutX(150);
    lblSharpen.setLayoutY(150);
    lblSharpen.setMinWidth(30);
    lblSharpen.setMaxWidth(30);
    lblSharpen.setTextAlignment(TextAlignment.RIGHT);

    paneChoixTypeFichier.getChildren().addAll(lblType, rbBmp, rbJpeg, rbTiff, cbSharpen, slSharpen, lblSharpen);
    pbBarreImage.setLayoutX(40);
    pbBarreImage.setLayoutY(190);
    pbBarreImage.setStyle("-fx-accent : #0000bb");
    pbBarreImage.setVisible(false);
    paneChoixTypeFichier.getChildren().add(pbBarreImage);
    pbBarreAvancement = new ProgressBar();
    pbBarreAvancement.setLayoutX(40);
    pbBarreAvancement.setLayoutY(220);
    pbBarreImage.setStyle("-fx-accent : #00bb00");
    paneChoixTypeFichier.getChildren().add(pbBarreAvancement);
    pbBarreAvancement.setVisible(false);

    paneboutons.getChildren().addAll(btnAnnuler, btnValider);
    vbFenetre.getChildren().addAll(hbChoix, paneboutons);
    Scene scnTransformations = new Scene(apTransformations);
    stTransformations.setScene(scnTransformations);
    stTransformations.show();

    btnAnnuler.setOnAction((e) -> {
        annulerE2C();
    });
    btnValider.setOnAction((e) -> {
        if (!bTraitementEffectue) {
            validerE2C();
        }
    });
    btnAjouteFichiers.setOnAction((e) -> {
        lblTermine.setText("");
        fileLstFichier = choixFichiers();
        if (fileLstFichier != null) {
            if (bTraitementEffectue) {
                lvListeFichier.getItems().clear();
                bTraitementEffectue = false;
            }
            for (File fileLstFichier1 : fileLstFichier) {
                String strNomFich = fileLstFichier1.getAbsolutePath();
                lvListeFichier.getItems().add(strNomFich);
            }
        }
    });
    lvListeFichier.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
        @Override
        public ListCell<String> call(ListView<String> list) {
            return new ListeTransformationCouleur();
        }
    });
    apTransformations.setOnDragOver((event) -> {
        Dragboard dbFichiersTransformation = event.getDragboard();
        if (dbFichiersTransformation.hasFiles()) {
            event.acceptTransferModes(TransferMode.ANY);
        } else {
            event.consume();
        }
    });
    stTransformations.widthProperty().addListener((arg0, arg1, arg2) -> {
        EditeurPanovisu.setLargeurE2C(stTransformations.getWidth());
        apTransformations.setPrefWidth(stTransformations.getWidth());
        vbFenetre.setPrefWidth(stTransformations.getWidth());
        btnAnnuler.setLayoutX(stTransformations.getWidth() - 314);
        btnValider.setLayoutX(stTransformations.getWidth() - 157);
        paneChoixFichier.setPrefWidth(stTransformations.getWidth() - 200);
        lvListeFichier.setPrefWidth(stTransformations.getWidth() - 240);
        lblDragDropE2C.setMinWidth(lvListeFichier.getPrefWidth());
        lblDragDropE2C.setMaxWidth(lvListeFichier.getPrefWidth());

        btnAjouteFichiers.setLayoutX(stTransformations.getWidth() - 341);
    });

    stTransformations.heightProperty().addListener((arg0, arg1, arg2) -> {
        EditeurPanovisu.setHauteurE2C(stTransformations.getHeight());
        apTransformations.setPrefHeight(stTransformations.getHeight());
        vbFenetre.setPrefHeight(stTransformations.getHeight());
        paneChoixFichier.setPrefHeight(stTransformations.getHeight() - 80);
        hbChoix.setPrefHeight(stTransformations.getHeight() - 80);
        lvListeFichier.setPrefHeight(stTransformations.getHeight() - 140);
        lblDragDropE2C.setMinHeight(lvListeFichier.getPrefHeight());
        lblDragDropE2C.setMaxHeight(lvListeFichier.getPrefHeight());
        btnAjouteFichiers.setLayoutY(stTransformations.getHeight() - 121);
    });
    stTransformations.setWidth(EditeurPanovisu.getLargeurE2C());
    stTransformations.setHeight(EditeurPanovisu.getHauteurE2C());
    apTransformations.setOnDragDropped((event) -> {
        Dragboard dbFichiersTransformation = event.getDragboard();
        boolean bSucces = false;
        File[] fileLstFich;
        fileLstFich = null;
        if (dbFichiersTransformation.hasFiles()) {
            lblTermine.setText("");
            bSucces = true;
            String[] stringFichiersPath = new String[200];
            int i = 0;
            for (File file1 : dbFichiersTransformation.getFiles()) {
                stringFichiersPath[i] = file1.getAbsolutePath();
                i++;
            }
            int iNb = i;
            i = 0;
            boolean bAttention = false;
            File[] fileLstFich1 = new File[stringFichiersPath.length];
            for (int j = 0; j < iNb; j++) {

                String strNomfich = stringFichiersPath[j];
                File fileTransf = new File(strNomfich);
                String strExtension = strNomfich.substring(strNomfich.lastIndexOf(".") + 1, strNomfich.length())
                        .toLowerCase();
                if (strExtension.equals("bmp") || strExtension.equals("jpg") || strExtension.equals("tif")) {
                    if (i == 0) {
                        strRepertFichier = fileTransf.getParent();
                    }
                    Image img = null;
                    if (strExtension != "tif") {
                        img = new Image("file:" + fileTransf.getAbsolutePath());
                    } else {
                        try {
                            img = ReadWriteImage.readTiff(strNomfich);
                        } catch (ImageReadException ex) {
                            Logger.getLogger(EquiCubeDialogController.class.getName()).log(Level.SEVERE, null,
                                    ex);
                        } catch (IOException ex) {
                            Logger.getLogger(EquiCubeDialogController.class.getName()).log(Level.SEVERE, null,
                                    ex);
                        }
                    }
                    if (strTypeTransformation.equals(EquiCubeDialogController.EQUI2CUBE)) {
                        if (img.getWidth() == 2 * img.getHeight()) {
                            fileLstFich1[i] = fileTransf;
                            i++;
                        } else {
                            bAttention = true;
                        }
                    } else {
                        if (img.getWidth() == img.getHeight()) {
                            String strNom = fileTransf.getAbsolutePath().substring(0,
                                    fileTransf.getAbsolutePath().length() - 6);
                            boolean bTrouve = false;
                            for (int ik = 0; ik < i; ik++) {
                                String strNom1 = fileLstFich1[ik].getAbsolutePath().substring(0,
                                        fileTransf.getAbsolutePath().length() - 6);
                                if (strNom.equals(strNom1)) {
                                    bTrouve = true;
                                }
                            }
                            if (!bTrouve) {
                                fileLstFich1[i] = fileTransf;
                                i++;
                            }
                        } else {
                            bAttention = true;
                        }

                    }
                }
            }
            if (bAttention) {
                Alert alert = new Alert(AlertType.ERROR);
                alert.setTitle(rbLocalisation.getString("transformation.traiteImages"));
                alert.setHeaderText(null);
                alert.setContentText(rbLocalisation.getString("transformation.traiteImagesType"));
                alert.showAndWait();
            }
            fileLstFichier = new File[i];
            System.arraycopy(fileLstFich1, 0, fileLstFichier, 0, i);
        }
        if (fileLstFichier != null) {
            if (bTraitementEffectue) {
                lvListeFichier.getItems().clear();
                bTraitementEffectue = false;
            }
            for (File lstFichier1 : fileLstFichier) {
                String nomFich = lstFichier1.getAbsolutePath();
                lvListeFichier.getItems().add(nomFich);
            }
        }
        lblDragDropE2C.setVisible(false);
        event.setDropCompleted(bSucces);
        event.consume();
    });

}

From source file:editeurpanovisu.EditeurPanovisu.java

/**
 *
 *//*from  w  ww.  j a va  2  s  .  c  om*/
private void projetsNouveau() {
    Action reponse = null;
    Localization.setLocale(locale);
    if (!dejaSauve) {
        reponse = Dialogs.create().owner(null).title("Nouveau projet")
                .masthead("Vous n'avez pas sauvegard votre projet").message("Voulez vous le sauver ?")
                .showConfirm();

    }
    if (reponse == Dialog.Actions.YES) {
        try {
            projetSauve();

        } catch (IOException ex) {
            Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    if ((reponse == Dialog.Actions.YES) || (reponse == Dialog.Actions.NO) || (reponse == null)) {
        panoEntree = "";
        deleteDirectory(repertTemp);
        String repertPanovisu = repertTemp + File.separator + "panovisu";
        File rptPanovisu = new File(repertPanovisu);
        rptPanovisu.mkdirs();
        copieDirectory(repertAppli + File.separator + "panovisu", repertPanovisu);
        menuPanoramique.setDisable(false);

        imgAjouterPano.setDisable(false);
        imgAjouterPano.setOpacity(1.0);
        imgSauveProjet.setDisable(false);
        imgSauveProjet.setOpacity(1.0);
        sauveProjet.setDisable(false);
        sauveSousProjet.setDisable(false);
        visiteGenere.setDisable(false);
        fichProjet = null;
        paneChoixPanoramique.setVisible(false);
        panoramiquesProjet = new Panoramique[50];
        nombrePanoramiques = 0;
        retireAffichageLigne();
        retireAffichageHotSpots();
        retireAffichagePointsHotSpots();
        numPoints = 0;
        numImages = 0;
        numHTML = 0;
        gestionnaireInterface.nombreImagesFond = 0;
        gestionnairePlan.planActuel = -1;
        imagePanoramique.setImage(null);
        listeChoixPanoramique.getItems().clear();
        listeChoixPanoramiqueEntree.getItems().clear();
        lblDragDrop.setVisible(true);
        Node ancNord = (Node) pano.lookup("#Nord");
        if (ancNord != null) {
            pano.getChildren().remove(ancNord);
        }
        Node ancPoV = (Node) pano.lookup("#PoV");
        if (ancPoV != null) {
            pano.getChildren().remove(ancPoV);
        }

        gestionnairePlan.lblDragDropPlan.setVisible(true);
        nombrePlans = 0;
        plans = new Plan[100];
        gestionnairePlan.creeInterface(largeurInterface, hauteurInterface - 60);
        Pane panneauPlan = gestionnairePlan.tabInterface;
        affichagePlan.setDisable(true);
        tabPlan.setDisable(true);
        tabPlan.setContent(panneauPlan);
        vuePanoramique.setOnDragOver((DragEvent event) -> {
            Dragboard db = event.getDragboard();
            if (db.hasFiles()) {
                event.acceptTransferModes(TransferMode.ANY);
            } else {
                event.consume();
            }
        });

        // Dropping over surface
        vuePanoramique.setOnDragDropped((DragEvent event) -> {
            Platform.runLater(() -> {
                paneAttends.setVisible(true);
            });
            Dragboard db = event.getDragboard();
            boolean success = false;
            if (db.hasFiles()) {
                success = true;
                String filePath = null;
                File[] list = new File[100];
                int i = 0;
                for (File file1 : db.getFiles()) {
                    filePath = file1.getAbsolutePath();
                    list[i] = file1;
                    i++;
                }
                int nb = i;
                if (list != null) {
                    i = 0;
                    File[] lstFich1 = new File[list.length];
                    String[] typeFich1 = new String[list.length];
                    for (int jj = 0; jj < nb; jj++) {
                        File file = list[jj];
                        String nomfich = file.getAbsolutePath();
                        String extension = nomfich.substring(nomfich.lastIndexOf(".") + 1, nomfich.length())
                                .toLowerCase();
                        //                            if (extension.equals("bmp") || extension.equals("jpg")) {
                        if (extension.equals("jpg") || extension.equals("bmp") || extension.equals("tif")) {
                            Image img = null;
                            if (extension.equals("tif")) {
                                try {
                                    img = ReadWriteImage.readTiff(file.getAbsolutePath());
                                } catch (ImageReadException ex) {
                                    Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null,
                                            ex);
                                } catch (IOException ex) {
                                    Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null,
                                            ex);
                                }
                            } else {
                                img = new Image("file:" + file.getAbsolutePath());
                            }
                            typeFich1[i] = "";
                            if (img.getWidth() == 2 * img.getHeight()) {
                                lstFich1[i] = file;
                                typeFich1[i] = Panoramique.SPHERE;
                                i++;
                            }
                            if (img.getWidth() == img.getHeight()) {
                                String nom = file.getAbsolutePath().substring(0,
                                        file.getAbsolutePath().length() - 6);
                                boolean trouve = false;
                                for (int j = 0; j < i; j++) {
                                    String nom1 = "";
                                    if (lstFich1[j].getAbsolutePath().length() == file.getAbsolutePath()
                                            .length()) {
                                        nom1 = lstFich1[j].getAbsolutePath().substring(0,
                                                file.getAbsolutePath().length() - 6);
                                    }
                                    if (nom.equals(nom1)) {
                                        trouve = true;
                                    }
                                }
                                if (!trouve) {
                                    lstFich1[i] = file;
                                    typeFich1[i] = Panoramique.CUBE;
                                    i++;
                                }
                            }

                        }
                    }
                    File[] lstFich = new File[i];
                    System.arraycopy(lstFich1, 0, lstFich, 0, i);

                    for (int ii = 0; ii < lstFich.length; ii++) {
                        File file1 = lstFich[ii];
                        dejaSauve = false;
                        stPrincipal.setTitle(stPrincipal.getTitle().replace(" *", "") + " *");
                        sauveProjet.setDisable(false);
                        currentDir = file1.getParent();
                        File imageRepert = new File(repertTemp + File.separator + "panos");

                        if (!imageRepert.exists()) {

                            imageRepert.mkdirs();
                        }
                        repertPanos = imageRepert.getAbsolutePath();
                        try {
                            //                            try {
                            //                                if (typeFich1[ii].equals(Panoramique.SPHERE)) {
                            //                                    copieFichierRepertoire(file1.getPath(), repertPanos);
                            //                                } else {
                            //                                    String nom = file1.getAbsolutePath().substring(0, file1.getAbsolutePath().length() - 6);
                            //                                    copieFichierRepertoire(nom + "_u.jpg", repertPanos);
                            //                                    copieFichierRepertoire(nom + "_d.jpg", repertPanos);
                            //                                    copieFichierRepertoire(nom + "_f.jpg", repertPanos);
                            //                                    copieFichierRepertoire(nom + "_b.jpg", repertPanos);
                            //                                    copieFichierRepertoire(nom + "_r.jpg", repertPanos);
                            //                                    copieFichierRepertoire(nom + "_l.jpg", repertPanos);
                            //                                }
                            //                            } catch (IOException ex) {
                            //                                Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex);
                            //                            }
                            if (typeFich1[ii] == Panoramique.CUBE || typeFich1[ii] == Panoramique.SPHERE) {
                                ajoutePanoramiqueProjet(file1.getPath(), typeFich1[ii]);
                            }
                        } catch (InterruptedException ex) {
                            Logger.getLogger(EditeurPanovisu.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }

                    installeEvenements();

                    imgVisiteGenere.setOpacity(1.0);
                    imgVisiteGenere.setDisable(false);
                    lblDragDrop.setVisible(false);
                }

            }
            Platform.runLater(() -> {
                paneAttends.setVisible(false);
            });
            event.setDropCompleted(success);
            event.consume();
        });

    }
}