Example usage for javafx.scene.input DragEvent acceptTransferModes

List of usage examples for javafx.scene.input DragEvent acceptTransferModes

Introduction

In this page you can find the example usage for javafx.scene.input DragEvent acceptTransferModes.

Prototype

public void acceptTransferModes(TransferMode... transferModes) 

Source Link

Document

Accepts this DragEvent , choosing the transfer mode for the drop operation.

Usage

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 551, 400);
    scene.setOnDragOver(new EventHandler<DragEvent>() {
        @Override/*from   w w w  . j  av a2s .c o  m*/
        public void handle(DragEvent event) {
            Dragboard db = event.getDragboard();
            if (db.hasFiles()) {
                event.acceptTransferModes(TransferMode.COPY);
            } else {
                event.consume();
            }
        }
    });

    // Dropping over surface
    scene.setOnDragDropped(new EventHandler<DragEvent>() {
        @Override
        public void handle(DragEvent event) {
            Dragboard db = event.getDragboard();
            boolean success = false;
            if (db.hasFiles()) {
                success = true;
                String filePath = null;
                for (File file : db.getFiles()) {
                    filePath = file.getAbsolutePath();
                    System.out.println(filePath);
                }
            }
            event.setDropCompleted(success);
            event.consume();
        }
    });

    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

private void initializeListeners() {
    // drag from left to right
    leftListView.setOnDragDetected(new EventHandler<MouseEvent>() {
        @Override/*from w ww .j  a v a  2  s .  c  om*/
        public void handle(MouseEvent event) {
            if (leftListView.getSelectionModel().getSelectedItem() == null) {
                return;
            }

            Dragboard dragBoard = leftListView.startDragAndDrop(TransferMode.MOVE);
            ClipboardContent content = new ClipboardContent();
            content.putString(leftListView.getSelectionModel().getSelectedItem().getName());
            dragBoard.setContent(content);
        }
    });

    rightListView.setOnDragOver(new EventHandler<DragEvent>() {
        @Override
        public void handle(DragEvent dragEvent) {
            dragEvent.acceptTransferModes(TransferMode.MOVE);
        }
    });

    rightListView.setOnDragDropped(new EventHandler<DragEvent>() {
        @Override
        public void handle(DragEvent dragEvent) {
            String player = dragEvent.getDragboard().getString();
            rightListView.getItems().addAll(new Student(player));
            leftList.remove(new Student(player));
            leftListView.setItems(leftList);
            dragEvent.setDropCompleted(true);
        }
    });
    // drag from right to left
    rightListView.setOnDragDetected(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            Dragboard dragBoard = rightListView.startDragAndDrop(TransferMode.MOVE);
            ClipboardContent content = new ClipboardContent();
            content.putString(rightListView.getSelectionModel().getSelectedItem().getName());
            dragBoard.setContent(content);
        }
    });

    leftListView.setOnDragOver(new EventHandler<DragEvent>() {
        @Override
        public void handle(DragEvent dragEvent) {
            dragEvent.acceptTransferModes(TransferMode.MOVE);
        }
    });

    leftListView.setOnDragDropped(new EventHandler<DragEvent>() {
        @Override
        public void handle(DragEvent dragEvent) {
            String player = dragEvent.getDragboard().getString();
            leftListView.getItems().remove(new Student(player));

            rightList.remove(new Student(player));
            dragEvent.setDropCompleted(true);
        }
    });
}

From source file:at.ac.tuwien.qse.sepm.gui.controller.impl.GridViewImpl.java

private void handleDragOver(DragEvent event) {
    event.acceptTransferModes(TransferMode.LINK);
    event.consume();
}

From source file:com.heliosdecompiler.helios.gui.controller.FileTreeController.java

@FXML
public void startDrop(DragEvent event) {
    Dragboard db = event.getDragboard();
    if (db.hasFiles()) {
        event.acceptTransferModes(TransferMode.ANY);
    }//from w  ww .j a v  a  2  s.c  om
}

From source file:com.loop81.fxcomparer.FXComparerController.java

/** Enabled drag & drop support on the anchor-panels for the file selections. */
private void initiateDragNDropp() {
    anchorPaneDropFile1.setOnDragOver(new EventHandler<DragEvent>() {
        @Override/*from   ww  w. j  av  a  2 s. c om*/
        public void handle(DragEvent event) {
            if (event.getDragboard().hasFiles()
                    && comparer.isFileSupported(event.getDragboard().getFiles().get(0))) {
                event.acceptTransferModes(TransferMode.COPY);
            } else {
                event.consume();
            }
        }
    });

    anchorPaneDropFile1.setOnDragDropped(new EventHandler<DragEvent>() {
        @Override
        public void handle(DragEvent event) {
            if (event.getDragboard().hasFiles()
                    && comparer.isFileSupported(event.getDragboard().getFiles().get(0))) {
                try {
                    archive1 = new ComparableArchive(event.getDragboard().getFiles().get(0));
                    handleFile(archive1, textFieldArchive1, labelArchive1Info);
                } catch (ArchiveException e) {
                    new AlertDialog(MessageBundle.getString("exceptions.archive.open")).show();
                }
            }
        }
    });

    anchorPaneDropFile2.setOnDragOver(new EventHandler<DragEvent>() {
        @Override
        public void handle(DragEvent event) {
            if (event.getDragboard().hasFiles()
                    && comparer.isFileSupported(event.getDragboard().getFiles().get(0))) {
                event.acceptTransferModes(TransferMode.COPY);
            } else {
                event.consume();
            }
        }
    });

    anchorPaneDropFile2.setOnDragDropped(new EventHandler<DragEvent>() {
        @Override
        public void handle(DragEvent event) {
            if (event.getDragboard().hasFiles()
                    && comparer.isFileSupported(event.getDragboard().getFiles().get(0))) {
                try {
                    archive2 = new ComparableArchive(event.getDragboard().getFiles().get(0));
                    handleFile(archive2, textFieldArchive2, labelArchive2Info);
                } catch (ArchiveException e) {
                    new AlertDialog(MessageBundle.getString("exceptions.archive.open")).show();
                }
            }
        }
    });
}

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

@FXML
void overlayViewFlowPane_DragOver(DragEvent event) {
    if (event.getDragboard().hasImage() || event.getDragboard().hasFiles() || event.getDragboard().hasUrl()) {
        // TODO: Set Pane color to an alpha green
        event.acceptTransferModes(TransferMode.COPY);
    } else {// ww  w  .  j  a va  2s.  c o  m
        // TODO: Set Pane color to an alpha red?
        event.acceptTransferModes(TransferMode.ANY);
    }
}

From source file:dpfmanager.shell.interfaces.gui.component.dessign.DessignView.java

@FXML
protected void onDragOverInput(DragEvent event) throws Exception {
    // Filter accepted files
    if (acceptedFiles(event.getDragboard(), getController().getAcceptedExetsniosn(), true)) {
        event.acceptTransferModes(TransferMode.MOVE);
    }/*from w w  w.  ja v a  2s . c  o  m*/
    event.consume();
}

From source file:AudioPlayer3.java

private void initSceneDragAndDrop(Scene scene) {
    scene.setOnDragOver(new EventHandler<DragEvent>() {
        @Override//w w  w. ja  v  a  2 s  .c o m
        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.TokenTool_Controller.java

@FXML
void compositeTokenPane_DragOver(DragEvent event) {
    if (event.getDragboard().hasImage() || event.getDragboard().hasFiles() || event.getDragboard().hasUrl()) {
        // Set Pane color to an alpha green
        event.acceptTransferModes(TransferMode.COPY);
    } else {//from  ww  w  .  jav a 2 s.  c  om
        // Set Pane color to an alpha red?
        event.acceptTransferModes(TransferMode.ANY);
    }
}

From source file:com.rockhoppertech.symchords.fx.SymChordsController.java

protected void setupDragonDrop() {
    Image image = new Image(getClass().getResourceAsStream("/images/rocky-32-trans.png"));
    dragImageView = new ImageView(image);
    dragImageView.setFitHeight(32);/*from www .  ja va  2  s  .co  m*/
    dragImageView.setFitWidth(32);

    grandStaff.setOnDragDetected(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent me) {

            if (!root.getChildren().contains(dragImageView)) {
                root.getChildren().add(dragImageView);
            }

            // dragImageView.setOpacity(0.5);
            dragImageView.toFront();
            dragImageView.setMouseTransparent(true);
            dragImageView.setVisible(true);
            dragImageView.relocate((int) (me.getSceneX() - dragImageView.getBoundsInLocal().getWidth() / 2),
                    (int) (me.getSceneY() - dragImageView.getBoundsInLocal().getHeight() / 2));

            Dragboard db = grandStaff.startDragAndDrop(TransferMode.ANY);

            // TODO remove the custom image nonsense in javafx 8
            // javafx 8
            // db.setDragView(dragImageView);

            ClipboardContent content = new ClipboardContent();
            // MIDITrack track = grandStaff.getMIDITrack();
            MIDITrack track = model.getMIDITrack();
            content.put(midiTrackDataFormat, track);
            db.setContent(content);
            me.consume();
        }
    });

    grandStaff.setOnDragDone(new EventHandler<DragEvent>() {
        public void handle(DragEvent e) {
            dragImageView.setVisible(false);
            e.consume();
        }
    });

    // Parent root = grandStaff.getScene().getRoot();
    // stage.getScene().getRoot();

    if (root != null) {
        root.setOnDragOver(new EventHandler<DragEvent>() {
            public void handle(DragEvent e) {
                Point2D localPoint = grandStaff.getScene().getRoot()
                        .sceneToLocal(new Point2D(e.getSceneX(), e.getSceneY()));
                dragImageView.relocate(
                        (int) (localPoint.getX() - dragImageView.getBoundsInLocal().getWidth() / 2),
                        (int) (localPoint.getY() - dragImageView.getBoundsInLocal().getHeight() / 2));
                e.consume();
            }
        });
    }

    trackList.setOnDragOver(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /*
             * data is dragged over the target; accept it only if it is not
             * dragged from the same node and if it has MIDITrack data
             */
            if (event.getGestureSource() != trackList && event.getDragboard().hasContent(midiTrackDataFormat)) {
                logger.debug("drag over");
                /* allow for both copying and moving, whatever user chooses */
                event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
            }

            // Don't consume the event. Let the layers below process the
            // DragOver event as well so that the
            // translucent container image will follow the cursor.
            // event.consume();
        }
    });

    trackList.setOnDragEntered(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* the drag-and-drop gesture entered the target */
            /* show to the user that it is an actual gesture target */
            logger.debug("drag entered");
            if (event.getGestureSource() != trackList && event.getDragboard().hasContent(midiTrackDataFormat)) {
                DropShadow dropShadow = new DropShadow();
                dropShadow.setRadius(5.0);
                dropShadow.setOffsetX(3.0);
                dropShadow.setOffsetY(3.0);
                dropShadow.setColor(Color.color(0.4, 0.5, 0.5));
                trackList.setEffect(dropShadow);
            }
            event.consume();
        }
    });

    trackList.setOnDragExited(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* mouse moved away, remove the graphical cues */
            trackList.setEffect(null);
            event.consume();
        }
    });

    trackList.setOnDragDropped(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {

            Dragboard db = event.getDragboard();
            boolean success = false;
            if (db.hasContent(midiTrackDataFormat)) {
                MIDITrack track = (MIDITrack) db.getContent(midiTrackDataFormat);
                trackList.getItems().add(track);
                success = true;

            }
            /*
             * let the source know whether the data was successfully
             * transferred and used
             */
            event.setDropCompleted(success);
            event.consume();
        }
    });

    logger.debug("jvm mime {}", DataFlavor.javaJVMLocalObjectMimeType);
}