Example usage for javafx.scene.input Clipboard getUrl

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

Introduction

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

Prototype

public final String getUrl() 

Source Link

Document

Gets the URL String from the clipboard which had previously been registered.

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();/*w  w w.  java  2s . c  o m*/
            }
        });
    } 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);
        }
    }
}