Example usage for javafx.scene.input DragEvent setDropCompleted

List of usage examples for javafx.scene.input DragEvent setDropCompleted

Introduction

In this page you can find the example usage for javafx.scene.input DragEvent setDropCompleted.

Prototype

public void setDropCompleted(boolean isTransferDone) 

Source Link

Document

Indicates that transfer handling of this DragEvent was completed successfully during a DRAG_DROPPED event handler.

Usage

From source file:Main.java

private void initializeListeners() {
    // drag from left to right
    leftListView.setOnDragDetected(new EventHandler<MouseEvent>() {
        @Override//from  www.j a v  a 2s  .co m
        public void handle(MouseEvent event) {
            if (leftListView.getSelectionModel().getSelectedItem() == null) {
                return;
            }

            Dragboard dragBoard = leftListView.startDragAndDrop(TransferMode.MOVE);
            ClipboardContent content = new ClipboardContent();
            content.putString(leftListView.getSelectionModel().getSelectedItem().getName());
            dragBoard.setContent(content);
        }
    });

    rightListView.setOnDragOver(new EventHandler<DragEvent>() {
        @Override
        public void handle(DragEvent dragEvent) {
            dragEvent.acceptTransferModes(TransferMode.MOVE);
        }
    });

    rightListView.setOnDragDropped(new EventHandler<DragEvent>() {
        @Override
        public void handle(DragEvent dragEvent) {
            String player = dragEvent.getDragboard().getString();
            rightListView.getItems().addAll(new Student(player));
            leftList.remove(new Student(player));
            leftListView.setItems(leftList);
            dragEvent.setDropCompleted(true);
        }
    });
    // drag from right to left
    rightListView.setOnDragDetected(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            Dragboard dragBoard = rightListView.startDragAndDrop(TransferMode.MOVE);
            ClipboardContent content = new ClipboardContent();
            content.putString(rightListView.getSelectionModel().getSelectedItem().getName());
            dragBoard.setContent(content);
        }
    });

    leftListView.setOnDragOver(new EventHandler<DragEvent>() {
        @Override
        public void handle(DragEvent dragEvent) {
            dragEvent.acceptTransferModes(TransferMode.MOVE);
        }
    });

    leftListView.setOnDragDropped(new EventHandler<DragEvent>() {
        @Override
        public void handle(DragEvent dragEvent) {
            String player = dragEvent.getDragboard().getString();
            leftListView.getItems().remove(new Student(player));

            rightList.remove(new Student(player));
            dragEvent.setDropCompleted(true);
        }
    });
}

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

@FXML
public void stopDrop(DragEvent event) {
    Dragboard db = event.getDragboard();
    boolean success = false;
    if (db.hasFiles()) {
        success = true;//from w  ww  .jav  a  2s.c  o m
        for (File file : db.getFiles()) {
            if (file.getName().endsWith(".jar") || file.getName().endsWith(".class")) {
                openedFileController.openFile(file);
            }
        }
    }
    event.setDropCompleted(success);
    event.consume();
}

From source file:at.ac.tuwien.qse.sepm.gui.controller.impl.GridViewImpl.java

private void handleDragDropped(DragEvent event) {
    LOGGER.debug("drag dropped");

    Dragboard dragboard = event.getDragboard();
    boolean success = dragboard.hasFiles();
    if (success) {
        dragboard.getFiles().forEach(f -> LOGGER.debug("dropped file {}", f));
        for (File file : dragboard.getFiles()) {
            try {
                workspaceService.addDirectory(file.toPath());
            } catch (ServiceException ex) {
                LOGGER.error("Couldn't add directory {}");
            }/*  www.  j  a  va 2  s  .  co  m*/
        }
    }
    event.setDropCompleted(success);
    event.consume();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 551, 400);
    scene.setOnDragOver(new EventHandler<DragEvent>() {
        @Override//from w w w.j  a  v a 2 s .  c  om
        public void handle(DragEvent event) {
            Dragboard db = event.getDragboard();
            if (db.hasFiles()) {
                event.acceptTransferModes(TransferMode.COPY);
            } else {
                event.consume();
            }
        }
    });

    // Dropping over surface
    scene.setOnDragDropped(new EventHandler<DragEvent>() {
        @Override
        public void handle(DragEvent event) {
            Dragboard db = event.getDragboard();
            boolean success = false;
            if (db.hasFiles()) {
                success = true;
                String filePath = null;
                for (File file : db.getFiles()) {
                    filePath = file.getAbsolutePath();
                    System.out.println(filePath);
                }
            }
            event.setDropCompleted(success);
            event.consume();
        }
    });

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

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

@FXML
void overlayViewFlowPane_DragDropped(DragEvent event) {
    Dragboard db = event.getDragboard();
    if (db.hasImage()) {
        try {/* ww  w .  ja  v  a2  s  .  c  om*/
            // Prompt for name & return file name
            File newOverlayFile = new File(currentDirectory.getCanonicalPath() + "/somefilename.png");
            ImageIO.write(SwingFXUtils.fromFXImage(db.getImage(), null), "png", newOverlayFile);
        } catch (IOException e) {
            log.error("Error writing new overlay image.", e);
        }

        loadImages(overlayTreeView.getSelectionModel().getSelectedItem());
        event.setDropCompleted(true);
    } else if (db.hasFiles()) {
        db.getFiles().forEach(file -> {
            FileSaveUtil.copyFile(file, currentDirectory);
        });
        loadImages(overlayTreeView.getSelectionModel().getSelectedItem());
        event.setDropCompleted(true);
    } else if (db.hasUrl()) {
        FileSaveUtil.copyFile(new File(db.getUrl()), currentDirectory);
        loadImages(overlayTreeView.getSelectionModel().getSelectedItem());
        event.setDropCompleted(true);
    }
}

From source file:dpfmanager.shell.interfaces.gui.component.dessign.DessignView.java

/**
 * Drag and drop input/*from   www.  j  a  va 2s  .c  om*/
 */
@FXML
protected void onDragDroppedInput(DragEvent event) throws Exception {
    // Files dropped
    Dragboard db = event.getDragboard();
    boolean success = false;
    if (db.hasFiles()) {
        success = true;
        String filePath = "";
        for (File file : db.getFiles()) {
            if (!filePath.isEmpty()) {
                filePath += ";";
            }
            filePath += file.getAbsolutePath();
        }
        String currentText = inputText.getText();
        if (!currentText.isEmpty() && !currentText.equals(bundle.getString("inputText"))) {
            inputText.setText(currentText + ";" + filePath);
        } else {
            inputText.setText(filePath);
        }
    }
    event.setDropCompleted(success);
    event.consume();
}

From source file:AudioPlayer3.java

private void initSceneDragAndDrop(Scene scene) {
    scene.setOnDragOver(new EventHandler<DragEvent>() {
        @Override/*from   w ww .j a va  2s.c om*/
        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:net.rptools.tokentool.controller.TokenTool_Controller.java

@FXML
void compositeTokenPane_DragDropped(DragEvent event) {
    Dragboard db = event.getDragboard();

    // Strangely, we get an error if we try to paste an image we put in the clipboard ourselves but File works ok?
    // -Dprism.order=sw also fixes it but not sure why...
    // So lets just check for File first...
    if (db.hasFiles()) {
        db.getFiles().forEach(file -> {
            try {
                updateFileNameTextField(FilenameUtils.getBaseName(file.toURI().toURL().toExternalForm()));
                updatePortrait(new Image(file.toURI().toURL().toExternalForm()));
            } catch (Exception e) {
                log.error("Could not load image " + file, e);
            }/*ww  w  .ja  va2  s  . c  om*/
        });
        event.setDropCompleted(true);
    } else if (db.hasImage()) {
        updatePortrait(db.getImage());
        event.setDropCompleted(true);
    } else if (db.hasUrl()) {
        updateFileNameTextField(FileSaveUtil.searchURL(db.getUrl()));
        updatePortrait(new Image(db.getUrl()));
        event.setDropCompleted(true);
    }
}

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  .  j  a v a 2s  . 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:fr.amap.lidar.amapvox.gui.MainFrameController.java

private void initPostProcessTab() {

    //initialize voxel file merging panel
    listViewVoxMergingVoxelFiles.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

    listViewVoxMergingVoxelFiles.setOnDragOver(DragAndDropHelper.dragOverEvent);

    listViewVoxMergingVoxelFiles.setOnDragDropped(new EventHandler<DragEvent>() {
        @Override//ww  w.j a  v  a 2s. co  m
        public void handle(DragEvent event) {
            Dragboard db = event.getDragboard();
            boolean success = false;
            if (db.hasFiles()) {
                success = true;
                for (File file : db.getFiles()) {

                    addVoxelFileToMergingList(file);
                }
            }
            event.setDropCompleted(success);
            event.consume();
        }
    });

    fileChooserVoxMergingList = new FileChooserContext();

    fileChooserOpenInputFileButterflyRemover = new FileChooserContext();
    fileChooserOpenOutputFileButterflyRemover = new FileChooserContext();
    fileChooserChooseOutputCfgFileButterflyRemover = new FileChooserContext();

}