Example usage for javafx.scene.input Dragboard getUrl

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

Introduction

In this page you can find the example usage for javafx.scene.input Dragboard 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:eu.over9000.skadi.ui.MainWindow.java

@Override
public void start(final Stage stage) throws Exception {
    this.stage = stage;

    this.detailPane = new ChannelDetailPane(this);

    this.bp = new BorderPane();
    this.sp = new SplitPane();
    this.sb = new StatusBar();

    this.setupTable();
    this.setupToolbar(stage);

    this.sp.getItems().add(this.table);

    this.bp.setTop(this.tb);
    this.bp.setCenter(this.sp);
    this.bp.setBottom(this.sb);

    final Scene scene = new Scene(this.bp, 1280, 720);
    scene.getStylesheets().add(this.getClass().getResource("/styles/copyable-label.css").toExternalForm());
    scene.setOnDragOver(event -> {/*from w w  w .  j  a va 2s  .  com*/
        final Dragboard d = event.getDragboard();
        if (d.hasUrl() || d.hasString()) {
            event.acceptTransferModes(TransferMode.COPY);
        } else {
            event.consume();
        }
    });
    scene.setOnDragDropped(event -> {
        final Dragboard d = event.getDragboard();
        boolean success = false;
        if (d.hasUrl()) {
            final String user = StringUtil.extractUsernameFromURL(d.getUrl());
            if (user != null) {
                success = this.channelHandler.addChannel(user, this.sb);
            } else {
                this.sb.setText("dragged url is no twitch stream");
            }
        } else if (d.hasString()) {
            success = this.channelHandler.addChannel(d.getString(), this.sb);
        }
        event.setDropCompleted(success);
        event.consume();

    });

    stage.setTitle("Skadi");
    stage.getIcons().add(new Image(this.getClass().getResourceAsStream("/icons/skadi.png")));
    stage.setScene(scene);
    stage.show();

    stage.iconifiedProperty().addListener((obs, oldV, newV) -> {
        if (this.currentState.isMinimizeToTray()) {
            if (newV) {
                stage.hide();
            }
        }
    });
    stage.setOnCloseRequest(event -> Platform.exit());

    this.bindColumnWidths();

}

From source file:AudioPlayer3.java

private void initSceneDragAndDrop(Scene scene) {
    scene.setOnDragOver(new EventHandler<DragEvent>() {
        @Override/*from   w w  w  .j  ava2  s . c  om*/
        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();
        }
    });
}

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 ww  .j  a v a 2s  . co  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.ja v a2  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);
    }
}