Java Code Examples for javafx.scene.input.DragEvent

The following are top voted examples for showing how to use javafx.scene.input.DragEvent. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: GameAuthoringEnvironment   File: OnScreenSprite.java   View source code 6 votes vote down vote up
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;
}
 
Example 2
Project: GameAuthoringEnvironment   File: DraggableSpriteCell.java   View source code 6 votes vote down vote up
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;
}
 
Example 3
Project: dracoon-dropzone   File: DropzonePopOverUI.java   View source code 6 votes vote down vote up
/**
 * 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();
}
 
Example 4
Project: uPMT   File: AddTypeCommand.java   View source code 6 votes vote down vote up
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);
}
 
Example 5
Project: MakeSourceList4j   File: Controller.java   View source code 6 votes vote down vote up
@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);
    }
}
 
Example 6
Project: voogasalad-ltub   File: ScreenObjectHolder.java   View source code 6 votes vote down vote up
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();
}
 
Example 7
Project: jmonkeybuilder   File: ResourcePropertyEditorControl.java   View source code 6 votes vote down vote up
/**
 * 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);
}
 
Example 8
Project: jmonkeybuilder   File: ResourcePropertyEditorControl.java   View source code 6 votes vote down vote up
/**
 * 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();
}
 
Example 9
Project: jmonkeybuilder   File: MaterialPropertyControl.java   View source code 6 votes vote down vote up
/**
 * 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());
}
 
Example 10
Project: jmonkeybuilder   File: MaterialPropertyControl.java   View source code 6 votes vote down vote up
/**
 * 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();
}
 
Example 11
Project: particles-in-box-java   File: NewExperimentController.java   View source code 6 votes vote down vote up
/**
 * 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();
}
 
Example 12
Project: programmierpraktikum-abschlussprojekt-null   File: ImportViewController.java   View source code 6 votes vote down vote up
/**
 * 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();
}
 
Example 13
Project: Game-Engine-Vooga   File: DesignBoard.java   View source code 6 votes vote down vote up
/**
 * 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();
}
 
Example 14
Project: Game-Engine-Vooga   File: DesignBoard.java   View source code 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 15
Project: Gargoyle   File: CodeAreaFileDragDropHelper.java   View source code 6 votes vote down vote up
/*********************************************************/
// 파일 드래그 드롭 처리.

/*
 * (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();
	}

}
 
Example 16
Project: travelimg   File: SlideDivider.java   View source code 6 votes vote down vote up
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();
}
 
Example 17
Project: CSVboard   File: CSVmanager.java   View source code 6 votes vote down vote up
@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();        
}
 
Example 18
Project: ReqTraq   File: TreeTableHandler.java   View source code 6 votes vote down vote up
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();
	}
}
 
Example 19
Project: bktail2   File: TabbedMainController.java   View source code 6 votes vote down vote up
@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();
    }
}
 
Example 20
Project: GPXEditor   File: GPXTreeTableView.java   View source code 6 votes vote down vote up
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();
        }
    }
}
 
Example 21
Project: beatoraja   File: PlayConfigurationView.java   View source code 6 votes vote down vote up
@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());
				}
			}
		}
	}
}
 
Example 22
Project: rpmjukebox   File: PlaylistListCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 23
Project: rpmjukebox   File: PlaylistListCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 24
Project: rpmjukebox   File: PlaylistListCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 25
Project: rpmjukebox   File: PlaylistListCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 26
Project: rpmjukebox   File: PlaylistListCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 27
Project: rpmjukebox   File: PlaylistListCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 28
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 29
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 30
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 31
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 32
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 33
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 34
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 35
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 36
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 37
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 38
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 39
Project: rpmjukebox   File: TrackTableCellFactoryTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 40
Project: LuoYing   File: JfxSceneEdit.java   View source code 6 votes vote down vote up
@Override
protected void onDragDropped(DragEvent e) {
    Dragboard db = e.getDragboard();
    if (db.hasContent(DataFormatConstants.COMPONENT_ENTITY)) {
        ComponentDefine c = (ComponentDefine) db.getContent(DataFormatConstants.COMPONENT_ENTITY);
        e.setDropCompleted(true);
        e.consume();

        // 当拖动物体到3D场景的时候必须把JFX中的鼠标坐标转到到JME中的坐标.
        // 不能直接用jme场景中获取鼠标坐标的方式,因为JME是放在awt canvas上的,这时还未获得焦点,直接用
        // JME中的方式获取鼠标坐标会错位。
        lastDragXPos = e.getX();
        lastDragYPos = e.getY();

        // 必须隔一帧,即等拖放操作完成执行后再弹窗.
        // 这里不能直接执行CustomDialog,因为当CustomDialog为模态时会锁住窗口,这会导致当第二次拖放操作时发生:
        // Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: 
        // Key already associated with a running event loop: [email protected]
        Jfx.runOnJfx(() -> {
            ComponentManager.createComponent(c, this);
        });
    }
}