Example usage for javafx.scene.input Dragboard hasImage

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

Introduction

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

Prototype

public final boolean hasImage() 

Source Link

Document

Gets whether an Image (DataFormat.IMAGE) has been registered on this Clipboard.

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 {/*w w  w .jav a 2s  . 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);
            }//from  w  w w. jav a  2  s  . c o  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);
    }
}