Example usage for javafx.scene.input DragEvent consume

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

Introduction

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

Prototype

public void consume() 

Source Link

Document

Marks this Event as consumed.

Usage

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 551, 400);
    scene.setOnDragOver(new EventHandler<DragEvent>() {
        @Override/*from   w  w w. java  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:at.ac.tuwien.qse.sepm.gui.controller.impl.GridViewImpl.java

private void handleDragOver(DragEvent event) {
    event.acceptTransferModes(TransferMode.LINK);
    event.consume();
}

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

private void handleDragEntered(DragEvent event) {
    LOGGER.debug("drag entered");
    folderDropTarget.setVisible(true);
    event.consume();
}

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

private void handleDragExited(DragEvent event) {
    LOGGER.debug("drag exited");
    folderDropTarget.setVisible(false);
    event.consume();
}

From source file:com.loop81.fxcomparer.FXComparerController.java

/** Enabled drag & drop support on the anchor-panels for the file selections. */
private void initiateDragNDropp() {
    anchorPaneDropFile1.setOnDragOver(new EventHandler<DragEvent>() {
        @Override/*  w w w.j a v  a 2  s  .c o  m*/
        public void handle(DragEvent event) {
            if (event.getDragboard().hasFiles()
                    && comparer.isFileSupported(event.getDragboard().getFiles().get(0))) {
                event.acceptTransferModes(TransferMode.COPY);
            } else {
                event.consume();
            }
        }
    });

    anchorPaneDropFile1.setOnDragDropped(new EventHandler<DragEvent>() {
        @Override
        public void handle(DragEvent event) {
            if (event.getDragboard().hasFiles()
                    && comparer.isFileSupported(event.getDragboard().getFiles().get(0))) {
                try {
                    archive1 = new ComparableArchive(event.getDragboard().getFiles().get(0));
                    handleFile(archive1, textFieldArchive1, labelArchive1Info);
                } catch (ArchiveException e) {
                    new AlertDialog(MessageBundle.getString("exceptions.archive.open")).show();
                }
            }
        }
    });

    anchorPaneDropFile2.setOnDragOver(new EventHandler<DragEvent>() {
        @Override
        public void handle(DragEvent event) {
            if (event.getDragboard().hasFiles()
                    && comparer.isFileSupported(event.getDragboard().getFiles().get(0))) {
                event.acceptTransferModes(TransferMode.COPY);
            } else {
                event.consume();
            }
        }
    });

    anchorPaneDropFile2.setOnDragDropped(new EventHandler<DragEvent>() {
        @Override
        public void handle(DragEvent event) {
            if (event.getDragboard().hasFiles()
                    && comparer.isFileSupported(event.getDragboard().getFiles().get(0))) {
                try {
                    archive2 = new ComparableArchive(event.getDragboard().getFiles().get(0));
                    handleFile(archive2, textFieldArchive2, labelArchive2Info);
                } catch (ArchiveException e) {
                    new AlertDialog(MessageBundle.getString("exceptions.archive.open")).show();
                }
            }
        }
    });
}

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

@FXML
protected void onDragExitedInput(DragEvent event) throws Exception {
    inputText.getStyleClass().remove("on-drag");
    event.consume();
}

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

@FXML
protected void onDragEnteredInput(DragEvent event) throws Exception {
    if (acceptedFiles(event.getDragboard(), getController().getAcceptedExetsniosn(), true)) {
        inputText.getStyleClass().add("on-drag");
    }/*from ww  w .ja v  a2s . c o m*/
    event.consume();
}

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

@FXML
protected void onDragOverInput(DragEvent event) throws Exception {
    // Filter accepted files
    if (acceptedFiles(event.getDragboard(), getController().getAcceptedExetsniosn(), true)) {
        event.acceptTransferModes(TransferMode.MOVE);
    }/*w  w  w.  ja  v  a2 s .  co  m*/
    event.consume();
}

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;/*  w  w w.j a  va  2 s. 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:AudioPlayer3.java

private void initSceneDragAndDrop(Scene scene) {
    scene.setOnDragOver(new EventHandler<DragEvent>() {
        @Override//from ww w  .  jav a 2 s .com
        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();
        }
    });
}