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

项目:GameAuthoringEnvironment    文件:OnScreenSprite.java   
private boolean checkPlaceableTile (DragEvent e) {
    double halfHeight =
            (0.5) * myScale
                    .scale((mySprite.getBounds().getBottom() - mySprite.getBounds().getTop()));
    double halfWidth =
            (0.5) * myScale
                    .scale((mySprite.getBounds().getRight() - mySprite.getBounds().getLeft()));
    for (int r =
            (int) ((e.getY() - halfHeight) / levelView.getGrids()
                    .getCurrentBlockSize()); r < (int) ((e.getY() + halfHeight) /
                                                        levelView.getGrids()
                                                                .getCurrentBlockSize()); r++) {
        for (int c =
                (int) ((e.getX() - halfWidth) / levelView.getGrids()
                        .getCurrentBlockSize()); c < (int) ((e.getX() + halfWidth) / levelView
                                .getGrids().getCurrentBlockSize()); c++) {
            if (levelView.getLevel().getPlaceableTileManager().getPlaceableMap()
                    .getBitMap()[r][c]) {
                return false;
            }
        }
    }
    return true;
}
项目:GameAuthoringEnvironment    文件:DraggableSpriteCell.java   
private boolean checkPlaceableTile (DragEvent e) {
    double halfHeight =
            (0.5) * myController.getRatio()
                    .scale((getProfilable().getProfile().getImageHeight().doubleValue()));
    double halfWidth =
            (0.5) * myController.getRatio()
                    .scale((getProfilable().getProfile().getImageWidth().doubleValue()));
    for (int r =
            (int) ((e.getY() - halfHeight) /
                   myController.getRatio().scale(50)); r < (int) ((e.getY() + halfHeight) /
                                                                  myController.getRatio()
                                                                          .scale(50)); r++) {
        for (int c =
                (int) ((e.getX() - halfWidth) / myController.getRatio()
                        .scale(50)); c < (int) ((e.getX() + halfWidth) /
                                                myController.getRatio().scale(50)); c++) {
            if (myController.getLevel().getPlaceableTileManager().getPlaceableMap()
                    .getBitMap()[r][c]) {
                return false;
            }
        }
    }
    return true;
}
项目:dracoon-dropzone    文件:DropzonePopOverUI.java   
/**
 * Handle mouse drop events
 * 
 * @param e
 */
private void mouseDragDropped(final DragEvent e) {
    final Dragboard db = e.getDragboard();
    boolean success = false;

    if (db.hasFiles()) {
        success = true;
        boolean ctrlKeyPressed = popOver.isCtrlKeyPressed();
        boolean altKeyPressed = popOver.isAltKeyPressed();

        popOver.notifyDragEventListener(new DropzoneDragEvent(e, ctrlKeyPressed, altKeyPressed));

    }
    e.setDropCompleted(success);
    e.consume();
}
项目:uPMT    文件:AddTypeCommand.java   
public AddTypeCommand(MomentExpVBox moment, DragEvent event, Main main) {
    this.event = event;
    typeName = event.getDragboard().getRtf();
    this.momentExpBorder = moment;
    this.main = main;

    for(Type t : main.getCurrentProject().getSchemaProjet().getTypes()){
        if(t.getName().equals(typeName)){
            type = (Classe) t;
        }
        else{
            setClassByName(t);
        }
    }
    setClassByName(main.getCurrentProject().getSchemaProjet());
    dup = duplicate(type);
}
项目:MakeSourceList4j    文件:Controller.java   
@FXML
private void handleDropped(DragEvent event) {
    // ドラッグボードを取得
    Dragboard board = event.getDragboard();
    if (board.hasFiles()) {
        board.getFiles().stream().forEach((f) -> {
            if (f.isDirectory()) {
                List<String> filePathList = new ArrayList<>();
                getFileRecursion(filePathList, f.getAbsolutePath()).stream().filter(s -> isTextFile(s)).collect(Collectors.toList()).forEach(s -> fileList.getItems().add(new Label(s)));
            } else {
                if (isTextFile(f.getAbsolutePath()))
                    fileList.getItems().add(new Label(f.getAbsolutePath()));
            }
        });
        // ドロップ受け入れ
        event.setDropCompleted(true);
    } else {    // ファイル以外なら
        // ドロップ受け入れ拒否
        event.setDropCompleted(false);
    }
}
项目:voogasalad-ltub    文件:ScreenObjectHolder.java   
private void targetSetOnDragDropped(ScreenMap target, DragEvent e) {
    Dragboard db = e.getDragboard();
    boolean success = false;
    if (e.getDragboard().hasImage()) {
        String imageName = db.getString();
        Point2D point = target.sceneToLocal(e.getSceneX(), e.getSceneY());
        GamePoint gameCoords = new GamePoint(point.getX()/target.getScreenWidth(), point.getY()/target.getScreenHeight());
        for (Pair<String, Image> p : myScreenObjects.keySet()) {
            String iName = p.getKey();
            if (imageName.equals(iName)) {
                XStreamHandler xstream = new XStreamHandler();
                File tempSpriteFile = new File("data/tempSprites/tempSprite.xml");
                xstream.saveToFile(myScreenObjects.get(p), tempSpriteFile);
                SpriteMakerModel xmlSprite = (SpriteMakerModel) xstream.getAttributeFromFile(tempSpriteFile);
                xmlSprite.addComponent(new Position(gameCoords, 0)); //heading 0 because all sprites default to this
                myModel.addBackgroundTile(xmlSprite);
                break;
            }
        }
        success = true;
    }
    e.setDropCompleted(success);
    e.consume();
}
项目:jmonkeybuilder    文件:ResourcePropertyEditorControl.java   
/**
 * Handle dropped files to editor.
 */
@FXThread
private void dragDropped(@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;

    handleFile(file);
}
项目: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 dropped events.
 *
 * @param dragEvent the dropped event.
 */
@FXThread
private void handleDragDroppedEvent(@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;
    }

    addMaterial(file.toPath());
}
项目: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();
}
项目:particles-in-box-java    文件:NewExperimentController.java   
/**
 * Drag dropped to the file drop area.
 *
 * @param event
 *            Event data.
 */
public final void onDragDropped(final DragEvent event) throws IOException {
    boolean success = false;
    LOG.log(Level.FINE, "Drag dropped: " + event.getDragboard().getString());
    if (event.getDragboard().hasFiles()) {
        File file = event.getDragboard().getFiles().get(0);
        // Check if file has a valid extension
        if (file.getName().endsWith(".bin")) {
            openSimulationFile(file);
            success = true;
        } else {
            String message = "Incorrect extension of the opened file (required .bin)";
            Dialog.createExceptionDialog(message, new IllegalArgumentException(message));
        }
    }
    event.setDropCompleted(success);
    event.consume();
}
项目:programmierpraktikum-abschlussprojekt-null    文件:ImportViewController.java   
/**
 * Drag dropped action
 * 
 * @param event
 */
@FXML
public void dragDropped(DragEvent event) {      
    try {
        loadConfig(event.getDragboard().getFiles().get(0));
    } catch (Exception e) {
        // TODO Auto-generated catch block
        Alert alert = new Alert(Alert.AlertType.ERROR);
        alert.setTitle("Import");
        alert.setHeaderText("Loading error");
        alert.setContentText(e.getMessage());
        alert.initModality(Modality.WINDOW_MODAL);
        alert.showAndWait();
        e.printStackTrace();
        return;
    }

    menuController.selectExerciseOverview();
    event.setDropCompleted(true);
       event.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();
}
项目:Game-Engine-Vooga    文件:DesignBoard.java   
/**
 * Method to add new element to the design board
 * 
 * @param file: file to add
 * @param event: drag and drop feature
 * @param archetype: archetype (if element has one)
 */
private void addElement (VoogaFile file, DragEvent event, String archetype) {
    String elementPath = file.getPath();
    if (elementPath != null) {
        try {
            if (ResourceDecipherer.isImage(elementPath)) {

                GameObjectBuilder builder = new GameObjectBuilder(elementManager);
                if (!archetype.isEmpty()) {
                    builder.setArchetype(archetype);
                }
                else {
                    builder.setDraggedImage(file.getPath());
                }
                builder.showAndWait();

            }
        }
        catch (VoogaException e) {
            VoogaAlert alert = new VoogaAlert(e.getMessage());
            alert.showAndWait();
        }
        elementManager.addElementId(elementPath);
    }
}
项目: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();
    }

}
项目:travelimg    文件:SlideDivider.java   
private void handleDragDropped(DragEvent event) {
    LOGGER.debug("drag dropped");

    Dragboard dragboard = event.getDragboard();
    boolean success = dragboard.hasString();
    if (success) {
        try {
            int slideId = Integer.parseInt(dragboard.getString());
            LOGGER.debug("dropped slide with id {} on divider", slideId);

            if (slideDroppedCallback != null) {
                slideDroppedCallback.accept(slideId);
            }
        } catch (NumberFormatException ex) {
            success = false;
        }

    }
    event.setDropCompleted(success);
    event.consume();
}
项目:CSVboard    文件:CSVmanager.java   
@Override
public void start(Stage stage) throws Exception {
    this.stage = stage;
    this.stage.setTitle("CSVboard");
    Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
    Scene scene = new Scene(root);
    scene.getStylesheets().add("CSVboard/style_tableview.css");
    // Dropping over surface
    scene.setOnDragDropped((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();
            }
        }
        event.setDropCompleted(success);
        event.consume();
    });
    // Give the controller access to the main app.                
    stage.setScene(scene);
    stage.show();        
}
项目:ReqTraq    文件:TreeTableHandler.java   
protected void handleRowDragDropped(TreeTableRow<T> r, DragEvent ev)
{
    Dragboard db = ev.getDragboard();
    if(isAcceptable(db, r))
    {
        int ix = (Integer)db.getContent(JAVA_DATA_FORMAT);
        TreeItem item = tree.getTreeItem(ix);
        item.getParent().getChildren().remove(item);
        getTarget(r).getChildren().add(item);
        ev.setDropCompleted(true);

        tree.getSelectionModel().clearSelection();
        tree.getSelectionModel().select(item);
        // FIX focus and selection differ after this

        ev.consume();
    }
}
项目: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();
        }
    }
}
项目:beatoraja    文件:PlayConfigurationView.java   
@FXML
public void songPathDragDropped(final DragEvent ev) {
    Dragboard db = ev.getDragboard();
    if (db.hasFiles()) {
        for (File f : db.getFiles()) {
            if (f.isDirectory()) {
                boolean unique = true;
                for (String path : bmsroot.getItems()) {
                    if (path.equals(f.getPath()) || f.getPath().startsWith(path + File.separatorChar)) {
                        unique = false;
                        break;
                    }
                }
                if (unique) {
                    bmsroot.getItems().add(f.getPath());
                }
            }
        }
    }
}
项目: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    文件: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
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();
}