Java 类javafx.scene.input.TransferMode 实例源码

项目:plep    文件:CustomTreeCell.java   
/**
 * When the dragging is detected, we place the content of the LabelCell
 * in the DragBoard.
 */
void setOnDragDetected() {
    setOnDragDetected(event -> {

        boolean isParentTask = getTreeItem().getParent().equals(root);

        boolean isEmpty = getTreeItem().getValue().getText().equals("");

        if (!isEmpty && isParentTask) {
            Dragboard db = startDragAndDrop(TransferMode.MOVE);
            ClipboardContent content = new ClipboardContent();
            content.put(controller.DATA_FORMAT, getTreeItem()
                    .getValue());
            db.setContent(content);
        }
        event.consume();
    });
}
项目:JavaFX-FrameRateMeter    文件:OldFXCanvas.java   
Set<TransferMode> getTransferModes(int bits) {
    Set<TransferMode> set = new HashSet<>();
    if ((bits & DND.DROP_COPY) != 0) {
      set.add(TransferMode.COPY);
    }
    if ((bits & DND.DROP_MOVE) != 0) {
      set.add(TransferMode.MOVE);
    }
    if ((bits & DND.DROP_TARGET_MOVE) != 0) {
      set.add(TransferMode.MOVE);
    }
    if ((bits & DND.DROP_LINK) != 0) {
      set.add(TransferMode.LINK);
    }
    return set;
}
项目:shuffleboard    文件:WidgetGalleryController.java   
@FXML
private void initialize() throws IOException {
  root.getChildren().addListener((ListChangeListener<? super Node>) change -> {
    while (change.next()) {
      for (Node node : change.getAddedSubList()) {
        if (node instanceof WidgetGallery.WidgetGalleryItem) {
          WidgetGallery.WidgetGalleryItem galleryItem = (WidgetGallery.WidgetGalleryItem) node;
          galleryItem.setOnDragDetected(event -> {
            Dragboard dragboard = galleryItem.startDragAndDrop(TransferMode.COPY);

            // TODO type safety
            ClipboardContent clipboard = new ClipboardContent();
            clipboard.put(DataFormats.widgetType, galleryItem.getWidget().getName());
            dragboard.setContent(clipboard);
            event.consume();
          });
        }
      }
    }
  });
}
项目:ScrabbleGame    文件:DraggableLetterManager.java   
/**
 * Adds to the letter the possibility to be dragged on another element.
 *
 * @param letterElement The element to be dragged
 * @param letter        The corresponding letter object
 */
public static void makeLetterDraggable(Node letterElement, LetterInterface letter) {
    // When an user starts to drag a letter
    letterElement.setOnDragDetected(event -> {
        Dragboard dragboard = letterElement.startDragAndDrop(TransferMode.ANY);
        dragboard.setDragView(letterElement.snapshot(null, null));
        letterElement.setVisible(false);

        ClipboardContent clipboardContent = new ClipboardContent();
        clipboardContent.put(LetterInterface.DATA_FORMAT, letter);

        dragboard.setContent(clipboardContent);

        event.consume();
    });

    // When the user has dropped the letter
    letterElement.setOnDragDone(event -> letterElement.setVisible(true));
}
项目:vars-annotation    文件:DragPaneDecorator.java   
public Pane decorate(Pane pane) {
    pane.setOnDragOver(evt -> {
        if (evt.getGestureSource() != pane &&
                evt.getDragboard().hasString()) {
            evt.acceptTransferModes(TransferMode.ANY);
        }
        evt.consume();
    });

    pane.setOnDragDropped(evt -> {
        Dragboard db = evt.getDragboard();
        boolean success = false;
        if (db.hasString()) {
            // Create a button and add to pane
            if (!locked) {
                addButton(db.getString(), pane, evt.getScreenX(), evt.getScreenY());
            }
            success = true;
        }
        // Let the source know whether the string was dropped successfully
        evt.setDropCompleted(success);
        evt.consume();
    });

    return pane;
}
项目:jmonkeybuilder    文件:ResourcePropertyEditorControl.java   
/**
 * Handle drag over.
 */
@FXThread
private void dragOver(@NotNull final DragEvent dragEvent) {

    final Dragboard dragboard = dragEvent.getDragboard();
    final List<File> files = unsafeCast(dragboard.getContent(DataFormat.FILES));

    if (files == null || files.size() != 1) {
        return;
    }

    final File file = files.get(0);
    if (!canAccept(file)) return;

    final Set<TransferMode> transferModes = dragboard.getTransferModes();
    final boolean isCopy = transferModes.contains(TransferMode.COPY);

    dragEvent.acceptTransferModes(isCopy ? TransferMode.COPY : TransferMode.MOVE);
    dragEvent.consume();
}
项目:jmonkeybuilder    文件:MaterialPropertyControl.java   
/**
 * Handle drag over events.
 *
 * @param dragEvent the drag over event.
 */
@FXThread
private void handleDragOverEvent(@NotNull final DragEvent dragEvent) {

    final Dragboard dragboard = dragEvent.getDragboard();
    final List<File> files = unsafeCast(dragboard.getContent(DataFormat.FILES));

    if (files == null || files.size() != 1) {
        return;
    }

    final File file = files.get(0);

    if (!file.getName().endsWith(FileExtensions.JME_MATERIAL)) {
        return;
    }

    final Set<TransferMode> transferModes = dragboard.getTransferModes();
    final boolean isCopy = transferModes.contains(TransferMode.COPY);

    dragEvent.acceptTransferModes(isCopy ? TransferMode.COPY : TransferMode.MOVE);
    dragEvent.consume();
}
项目:Game-Engine-Vooga    文件:DesignBoard.java   
/**
 * Mouse dragover event.
 * 
 * @param event
 */
private void mouseDragOver (final DragEvent event) {
    if (event.getGestureSource() != contentPane &&
        (event.getDragboard().hasContent(VoogaFileFormat.getInstance()))) {
        VoogaFile content =
                (VoogaFile) event.getDragboard().getContent(VoogaFileFormat.getInstance());
        String color = "";
        if (content.getType() != VoogaFileType.FOLDER) {
            color = designboardProperties.getString("NonVoogaFileColor");
        }
        else {
            color = designboardProperties.getString("VoogaFileColor");
        }
        contentPane.setStyle(String
                .format(designboardProperties.getString("ContentPaneStringStyle"), color));
        event.acceptTransferModes(TransferMode.ANY);
    }
    else if (event.getDragboard().hasString()) {
        event.acceptTransferModes(TransferMode.ANY);
    }

    event.consume();
}
项目:Incubator    文件:ProjectItemCell.java   
private void initializeSetOnDragDetected() {
//        LoggerFacade.INSTANCE.debug(this.getClass(), "Initialize setOnDragDetected"); // NOI18N

        super.setOnDragDetected(event -> {
            if (super.getItem() == null) {
                return;
            }

            final Dragboard dragboard = startDragAndDrop(TransferMode.MOVE);
            final ClipboardContent content = new ClipboardContent();
            content.putString(String.valueOf(super.getItem().getProjectId()));
//            dragboard.setDragView(
//                    birdImages.get(
//                            items.indexOf(
//                                    getItem()
//                            )
//                    )
//            );
            dragboard.setContent(content);
            event.consume();
        });
    }
项目:Gargoyle    文件:DefaultFileDragDropHelper.java   
/*********************************************************/
// 파일 드래그 드롭 처리.

/* (non-Javadoc)
 * @see com.kyj.fx.voeditor.visual.component.text.AbstractDragDropHelper#onDagOver(javafx.scene.input.DragEvent)
 */
@Override
public void onDagOver(DragEvent ev) {
    if (ev.isConsumed())
        return;

    if (ev.getDragboard().hasFiles()) {
        ev.acceptTransferModes(TransferMode.LINK);
        ev.consume();
    }

}
项目:Gargoyle    文件:SystemLayoutViewController.java   
/**
 * 트리 드래그 디텍트 이벤트 처리. <br/>
 * 트리내에 구성된 파일의 위치정보를 드래그 드롭 기능으로 <br/>
 * 전달해주는 역할을 수행한다.<br/>
 * <br/>
 * 
 * @작성자 : KYJ
 * @작성일 : 2017. 11. 21.
 * @param ev
 */
public void treeProjectFileOnDragDetected(MouseEvent ev) {
    TreeItem<JavaProjectFileWrapper> selectedItem = treeProjectFile.getSelectionModel().getSelectedItem();
    if (selectedItem == null || selectedItem.getValue() == null) {
        return;
    }

    File file = selectedItem.getValue().getFile();
    if (file == null || !file.exists())
        return;

    Dragboard board = treeProjectFile.startDragAndDrop(TransferMode.LINK);
    ClipboardContent content = new ClipboardContent();
    content.putFiles(Arrays.asList(file));
    board.setContent(content);

    ev.consume();
}
项目:Gargoyle    文件:CodeAreaFileDragDropHelper.java   
/*********************************************************/
// 파일 드래그 드롭 처리.

/*
 * (non-Javadoc)
 * 
 * @see com.kyj.fx.voeditor.visual.component.text.AbstractDragDropHelper#
 * onDagOver(javafx.scene.input.DragEvent)
 */
@Override
public void onDagOver(DragEvent ev) {
    if (ev.isConsumed())
        return;

    if (ev.getDragboard().hasFiles()) {
        ev.acceptTransferModes(TransferMode.LINK);
        ev.consume();
    }

}
项目:Synth    文件:CoreController.java   
@Override
public void handle(final MouseEvent event) {
    final Pane pane = (Pane) event.getSource();
    final ImageView view = (ImageView) pane.getChildren().get(0);
    final Dragboard db = view.startDragAndDrop(TransferMode.COPY);
    final ClipboardContent content = new ClipboardContent();
    content.putString(view.getId());
    final ComponentPane componentPane = loadComponent(pane.getChildren().get(0).getId().toLowerCase());
    workspace.getChildren().add(componentPane);
    componentPane.applyCss();
    final WritableImage w  = componentPane.snapshot(null,null);
    workspace.getChildren().remove(componentPane);
    content.putImage(w);
    db.setContent(content);
    event.consume();
}
项目:openjfx-8u-dev-tests    文件:DragDropWithControls.java   
private Node createTMSelect(final Set<TransferMode> tms) {
    VBox box = new VBox();

    for (final TransferMode tm : TransferMode.values()) {
        CheckBox cb = new CheckBox(tm.toString());
        cb.selectedProperty().addListener(new ChangeListener<Boolean>() {
            @Override
            public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
                if (t1) {
                    tms.add(tm);
                } else {
                    tms.remove(tm);
                }
            }
        });
        if (tm == TransferMode.COPY) {
            cb.selectedProperty().set(true);
        }
        box.getChildren().add(cb);
    }

    return box;
}
项目:bktail2    文件:TabbedMainController.java   
@FXML void mouseDragOver(final DragEvent e) {
    final Dragboard db = e.getDragboard();

    final boolean isAccepted = db.getFiles().get(0).getName().toLowerCase().endsWith(".log")
            || db.getFiles().get(0).getName().toLowerCase().endsWith(".txt");

    if (db.hasFiles()) {
        if (isAccepted) {
            tabpane.setStyle("-fx-border-color: red;"
          + "-fx-border-width: 5;"
          + "-fx-background-color: #C6C6C6;"
          + "-fx-border-style: solid;");//TODO move to css
            e.acceptTransferModes(TransferMode.COPY);
        }
    } else {
        e.consume();
    }
}
项目:GPXEditor    文件:GPXTreeTableView.java   
private void onDragOver(final TreeTableRow<GPXLineItem> row, final DragEvent event) {
    Dragboard db = event.getDragboard();
    if (db.getContent(SERIALIZED_MIME_TYPE) != null) {
        if (!row.isEmpty()) {
            event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
            event.consume();
        }
    } else {
        if (db.hasFiles()) {
            for (File file:db.getFiles()) {
                // accept only gpx files
                if (GPXEditorWorker.GPX_EXT.equals(FilenameUtils.getExtension(file.getName()).toLowerCase())) {
                    event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
                    break;
                }
            }
        } else {
            event.consume();
        }
    }
}
项目:rpmjukebox    文件:PlaylistListCellFactoryTest.java   
@Test
public void shouldTriggerDragEntered() {
    ListCell<Playlist> listCell = cellFactory.call(getListView());
    listCell.setItem(new Playlist(1, "Playlist", 10));
    listCell.setStyle(null);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true);

    DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, new Object()));

    listCell.onDragEnteredProperty().get().handle(spyDragEvent);

    assertThat("List cell style should not be empty", listCell.getStyle(), not(isEmptyString()));
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:PlaylistListCellFactoryTest.java   
@Test
public void shouldNotTriggerDragEnterdWithSameSource() {
    ListCell<Playlist> listCell = cellFactory.call(getListView());
    listCell.setItem(new Playlist(1, "Playlist", 10));
    listCell.setStyle(null);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true);

    DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, listCell));

    listCell.onDragEnteredProperty().get().handle(spyDragEvent);

    assertThat("List cell style should be empty", listCell.getStyle(), isEmptyString());
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:PlaylistListCellFactoryTest.java   
@Test
public void shouldNotTriggerDragEnteredWithNoContent() {
    ListCell<Playlist> listCell = cellFactory.call(getListView());
    listCell.setItem(new Playlist(1, "Playlist", 10));
    listCell.setStyle(null);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(false);

    DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, new Object()));

    listCell.onDragEnteredProperty().get().handle(spyDragEvent);

    assertThat("List cell style should be empty", listCell.getStyle(), isEmptyString());
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:PlaylistListCellFactoryTest.java   
@Test
public void shouldNotTriggerDragEnteredWithNoPlaylist() {
    ListCell<Playlist> listCell = cellFactory.call(getListView());
    listCell.setItem(null);
    listCell.setStyle(null);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true);

    DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, new Object()));

    listCell.onDragEnteredProperty().get().handle(spyDragEvent);

    assertThat("List cell style should be empty", listCell.getStyle(), isEmptyString());
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:PlaylistListCellFactoryTest.java   
@Test
public void shouldNotTriggerDragEnteredWithReservedPlaylist() {
    ListCell<Playlist> listCell = cellFactory.call(getListView());
    listCell.setItem(new Playlist(PLAYLIST_ID_FAVOURITES, "Favourites", 10));
    listCell.setStyle(null);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true);

    DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, new Object()));

    listCell.onDragEnteredProperty().get().handle(spyDragEvent);

    assertThat("List cell style should be empty", listCell.getStyle(), isEmptyString());
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:PlaylistListCellFactoryTest.java   
@Test
public void shouldTriggerDragExited() {
    ListCell<Playlist> listCell = cellFactory.call(getListView());
    listCell.setStyle("some-style");

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true);

    DragEvent spyDragEvent = spy(
        getDragEvent(DragEvent.DRAG_EXITED, mockDragboard, TransferMode.COPY, new Object()));

    listCell.onDragExitedProperty().get().handle(spyDragEvent);

    assertThat("List cell style should be empty", listCell.getStyle(), isEmptyString());
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:PlaylistListCellFactoryTest.java   
@Test
public void shouldTriggerDragDropped() {
    ListCell<Playlist> listCell = cellFactory.call(getListView());
    listCell.setItem(new Playlist(1, "Playlist", 10));

    Track mockTrack = mock(Track.class);
    when(mockTrack.clone()).thenReturn(mockTrack);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true);
    when(mockDragboard.getContent(DND_TRACK_DATA_FORMAT)).thenReturn(mockTrack);

    DragEvent spyDragEvent = spy(
        getDragEvent(DragEvent.DRAG_DROPPED, mockDragboard, TransferMode.COPY, new Object()));

    listCell.onDragDroppedProperty().get().handle(spyDragEvent);

    verify(mockPlaylistManager, times(1)).addTrackToPlaylist(1, mockTrack);
    verify(spyDragEvent, times(1)).setDropCompleted(true);
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:PlaylistListCellFactoryTest.java   
@Test
public void shouldNotTriggerDragDroppedWithNoContent() {
    ListCell<Playlist> listCell = cellFactory.call(getListView());
    listCell.setItem(new Playlist(1, "Playlist", 10));

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(false);

    DragEvent spyDragEvent = spy(
        getDragEvent(DragEvent.DRAG_DROPPED, mockDragboard, TransferMode.COPY, new Object()));

    listCell.onDragDroppedProperty().get().handle(spyDragEvent);

    verify(mockPlaylistManager, never()).addTrackToPlaylist(anyInt(), any());
    verify(spyDragEvent, never()).setDropCompleted(true);
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:TrackTableCellFactoryTest.java   
@Test
public void shouldTriggerDragOver() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    Track track = getTrack();
    updateTableCell(tableCell, track);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true);

    DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, new Object()));

    tableCell.onDragOverProperty().get().handle(spyDragEvent);

    verify(spyDragEvent, times(1)).acceptTransferModes(TransferMode.MOVE);
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:TrackTableCellFactoryTest.java   
@Test
public void shouldNotTriggerDragOverWithSameSource() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    Track track = getTrack();
    updateTableCell(tableCell, track);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true);

    DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, tableCell));

    tableCell.onDragOverProperty().get().handle(spyDragEvent);

    verify(spyDragEvent, never()).acceptTransferModes(TransferMode.MOVE);
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:TrackTableCellFactoryTest.java   
@Test
public void shouldNotTriggerDragOverWithNoContent() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    Track track = getTrack();
    updateTableCell(tableCell, track);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(false);

    DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, new Object()));

    tableCell.onDragOverProperty().get().handle(spyDragEvent);

    verify(spyDragEvent, never()).acceptTransferModes(TransferMode.MOVE);
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:TrackTableCellFactoryTest.java   
@Test
@SuppressWarnings("unchecked")
public void shouldNotTriggerDragOverWithNoTrackTableModel() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    Track track = getTrack();
    updateTableCell(tableCell, track);
    tableCell.getTableRow().setItem(null);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true);

    DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, new Object()));

    tableCell.onDragOverProperty().get().handle(spyDragEvent);

    verify(spyDragEvent, never()).acceptTransferModes(TransferMode.MOVE);
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:TrackTableCellFactoryTest.java   
@Test
public void shouldNotTriggerDragOverWithSearchPlaylist() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    Track track = getTrack();
    track.setPlaylistId(PLAYLIST_ID_SEARCH);
    updateTableCell(tableCell, track);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true);

    DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_OVER, mockDragboard, TransferMode.COPY, new Object()));

    tableCell.onDragOverProperty().get().handle(spyDragEvent);

    verify(spyDragEvent, never()).acceptTransferModes(TransferMode.MOVE);
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:TrackTableCellFactoryTest.java   
@Test
public void shouldTriggerDragEntered() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    Track track = getTrack();
    updateTableCell(tableCell, track);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true);

    DragEvent spyDragEvent = spy(
        getDragEvent(DragEvent.DRAG_ENTERED, mockDragboard, TransferMode.COPY, new Object()));

    tableCell.onDragEnteredProperty().get().handle(spyDragEvent);

    assertThat("Table row style should not be empty", tableCell.getTableRow().getStyle(), not(isEmptyString()));
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:TrackTableCellFactoryTest.java   
@Test
public void shouldNotTriggerDragEnteredWithSameSource() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    Track track = getTrack();
    updateTableCell(tableCell, track);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true);

    DragEvent spyDragEvent = spy(getDragEvent(DragEvent.DRAG_ENTERED, mockDragboard, TransferMode.COPY, tableCell));

    tableCell.onDragEnteredProperty().get().handle(spyDragEvent);

    assertThat("Table row style should be empty", tableCell.getTableRow().getStyle(), isEmptyString());
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:TrackTableCellFactoryTest.java   
@Test
public void shouldNotTriggerDragEnteredWithNoContent() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    Track track = getTrack();
    updateTableCell(tableCell, track);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(false);

    DragEvent spyDragEvent = spy(
        getDragEvent(DragEvent.DRAG_ENTERED, mockDragboard, TransferMode.COPY, new Object()));

    tableCell.onDragEnteredProperty().get().handle(spyDragEvent);

    assertThat("Table row style should be empty", tableCell.getTableRow().getStyle(), isEmptyString());
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:TrackTableCellFactoryTest.java   
@Test
@SuppressWarnings("unchecked")
public void shouldNotTriggerDragEnteredWithNoTrackTableModel() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    Track track = getTrack();
    updateTableCell(tableCell, track);
    tableCell.getTableRow().setItem(null);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true);

    DragEvent spyDragEvent = spy(
        getDragEvent(DragEvent.DRAG_ENTERED, mockDragboard, TransferMode.COPY, new Object()));

    tableCell.onDragEnteredProperty().get().handle(spyDragEvent);

    assertThat("Table row style should be empty", tableCell.getTableRow().getStyle(), isEmptyString());
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:TrackTableCellFactoryTest.java   
@Test
public void shouldNotTriggerDragEnteredWithSearchPlaylist() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    Track track = getTrack();
    track.setPlaylistId(PLAYLIST_ID_SEARCH);
    updateTableCell(tableCell, track);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true);

    DragEvent spyDragEvent = spy(
        getDragEvent(DragEvent.DRAG_ENTERED, mockDragboard, TransferMode.COPY, new Object()));

    tableCell.onDragEnteredProperty().get().handle(spyDragEvent);

    assertThat("Table row style should be empty", tableCell.getTableRow().getStyle(), isEmptyString());
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:TrackTableCellFactoryTest.java   
@Test
public void shouldTriggerDragExited() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    Track track = getTrack();
    updateTableCell(tableCell, track);
    tableCell.getTableRow().setStyle("some-style");

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true);

    DragEvent spyDragEvent = spy(
        getDragEvent(DragEvent.DRAG_EXITED, mockDragboard, TransferMode.COPY, new Object()));

    tableCell.onDragExitedProperty().get().handle(spyDragEvent);

    assertThat("Table row style should be empty", tableCell.getTableRow().getStyle(), isEmptyString());
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:TrackTableCellFactoryTest.java   
@Test
public void shouldTriggerDragDropped() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    Track target = getTrack();
    updateTableCell(tableCell, target);

    Track source = new Track("1231", "Artist Name 1", "Artist Image 1", "4561", "Album Name 1", "Album Image 1",
        2001, "7891", "Track Name 1", 2, "Location 1", true, Arrays.asList("Genre 1", "Genre 2"));
    source.setPlaylistId(2);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(true);
    when(mockDragboard.getContent(DND_TRACK_DATA_FORMAT)).thenReturn(source);

    DragEvent spyDragEvent = spy(
        getDragEvent(DragEvent.DRAG_DROPPED, mockDragboard, TransferMode.COPY, new Object()));

    tableCell.onDragDroppedProperty().get().handle(spyDragEvent);

    verify(mockPlaylistManager, times(1)).moveTracksInPlaylist(source.getPlaylistId(), source, target);
    verify(spyDragEvent, times(1)).setDropCompleted(true);
    verify(spyDragEvent, times(1)).consume();
}
项目:rpmjukebox    文件:TrackTableCellFactoryTest.java   
@Test
public void shouldNotTriggerDragDroppedWithNoContent() {
    TableCell<TrackTableModel, String> tableCell = cellFactory.call(new TableColumn<>());
    Track target = getTrack();
    updateTableCell(tableCell, target);

    Track source = new Track("1231", "Artist Name 1", "Artist Image 1", "4561", "Album Name 1", "Album Image 1",
        2001, "7891", "Track Name 1", 2, "Location 1", true, Arrays.asList("Genre 1", "Genre 2"));
    source.setPlaylistId(2);

    Dragboard mockDragboard = mock(Dragboard.class);
    when(mockDragboard.hasContent(DND_TRACK_DATA_FORMAT)).thenReturn(false);

    DragEvent spyDragEvent = spy(
        getDragEvent(DragEvent.DRAG_DROPPED, mockDragboard, TransferMode.COPY, new Object()));

    tableCell.onDragDroppedProperty().get().handle(spyDragEvent);

    verify(mockPlaylistManager, never()).moveTracksInPlaylist(source.getPlaylistId(), source, target);
    verify(spyDragEvent, never()).setDropCompleted(true);
    verify(spyDragEvent, times(1)).consume();
}
项目:LuoYing    文件:AssetsForm.java   
private void doDragDetected(MouseEvent e) {
    ObservableList<TreeItem<File>> items = assetTree.getSelectionModel().getSelectedItems();
    if (items.isEmpty()) {
        e.consume();
        return;
    }
    List<File> files = new ArrayList<>(items.size());
    items.filtered(t -> t.getValue() != null).forEach(t -> {files.add(t.getValue());});
    if (files.size() <= 0) {
        e.consume();
        return;
    } 
    Dragboard db = assetTree.startDragAndDrop(TransferMode.COPY_OR_MOVE);
    ClipboardContent clipboardContent = new ClipboardContent();
    clipboardContent.put(DataFormat.FILES, files);
    db.setContent(clipboardContent);
    e.consume();
}
项目:supernovae    文件:SceneView.java   
private void configureDragAndDrop(){
    setOnDragDetected(e -> {});

    setOnDragEntered(e -> {});

    setOnDragExited(e -> {});

    setOnDragOver(e -> {
        if(Dragpool.containsType(Blueprint.class)) {
            e.acceptTransferModes(TransferMode.ANY);
        }
        e.consume();
    });

    setOnDragDropped(e -> {
        if(Dragpool.containsType(Blueprint.class)) {
            presenter.createEntityAt(Dragpool.grabContent(Blueprint.class), new Point2D(e.getX(), this.getHeight()-e.getY()));
        }
    });
}
项目:Gamma-Music-Manager    文件:MusicPlayerPlaybackQueueUI.java   
/**
 * Function to set the dragging actions for the Queuing list.
 *
 * @param musicPlayerManager    The music player manager to interact with.
 * @param songManager           The Song manager to get the select song that is being dragged.
 * @param queuingList           The queuing list to set the actions on.
 */
private void setQueuingDragActions(
        MusicPlayerManager musicPlayerManager,
        SongManager songManager,
        TitledPane queuingList) {

    queuingList.setOnDragDone((event) -> {
        songManager.setM_itemsToMove(null);
        event.consume();
    });

    queuingList.setOnDragDropped((event) -> {
        for (Item itemToMove : songManager.getM_itemsToMove()) {
            musicPlayerManager.placeSongOnBackOfPlaybackQueue((Song) itemToMove);
        }
        event.consume();
    });

    queuingList.setOnDragOver((event) -> {
        if (songManager.itemsToMoveAreAllSongs()) {
            event.acceptTransferModes(TransferMode.MOVE);
            event.consume();
        }
    });
}