Example usage for javafx.scene.input Clipboard hasUrl

List of usage examples for javafx.scene.input Clipboard hasUrl

Introduction

In this page you can find the example usage for javafx.scene.input Clipboard hasUrl.

Prototype

public final boolean hasUrl() 

Source Link

Document

Gets whether a url String (DataFormat.URL) has been registered on this Clipboard.

Usage

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

@FXML
void editPasteImageMenu_onAction(ActionEvent event) {
    Clipboard clipboard = Clipboard.getSystemClipboard();
    Image originalImage = portraitImageView.getImage();

    // 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 (clipboard.hasFiles()) {
        clipboard.getFiles().forEach(file -> {
            try {
                Image cbImage = new Image(file.toURI().toURL().toExternalForm());

                if (cbImage != null)
                    updatePortrait(cbImage);

                updateFileNameTextField(FilenameUtils.getBaseName(file.toURI().toURL().toExternalForm()));
            } catch (Exception e) {
                log.error("Could not load image " + file);
                e.printStackTrace();/*from   ww  w. ja  v  a  2 s  . c om*/
            }
        });
    } else if (clipboard.hasImage()) {
        try {
            Image cbImage = clipboard.getImage();
            if (cbImage != null)
                updatePortrait(cbImage);
        } catch (IllegalArgumentException e) {
            log.info(e);
            updatePortrait(originalImage);
        }
    } else if (clipboard.hasUrl()) {
        try {
            Image cbImage = new Image(clipboard.getUrl());
            if (cbImage != null)
                updatePortrait(cbImage);

            updateFileNameTextField(FileSaveUtil.searchURL(clipboard.getUrl()));
        } catch (IllegalArgumentException e) {
            log.info(e);
        }
    } else if (clipboard.hasString()) {
        try {
            Image cbImage = new Image(clipboard.getString());
            if (cbImage != null)
                updatePortrait(cbImage);

            updateFileNameTextField(FileSaveUtil.searchURL(clipboard.getString()));
        } catch (IllegalArgumentException e) {
            log.info(e);
        }
    }
}