Example usage for javafx.scene.input Dragboard getImage

List of usage examples for javafx.scene.input Dragboard getImage

Introduction

In this page you can find the example usage for javafx.scene.input Dragboard getImage.

Prototype

public final Image getImage() 

Source Link

Document

Gets the Image from the clipboard which had previously been registered.

Usage

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 .j  a  v a2  s.  c  o m*/
            // 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: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);
            }// www  .  j a  v a2s .  co m
        });
        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);
    }
}