Java Code Examples for javafx.scene.input.DragEvent#acceptTransferModes()

The following examples show how to use javafx.scene.input.DragEvent#acceptTransferModes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JaceUIController.java    From jace with GNU General Public License v2.0 6 votes vote down vote up
private void processDragEnteredEvent(DragEvent evt) {
    MediaEntry media = null;
    if (evt.getDragboard().hasFiles()) {
        media = MediaCache.getMediaFromFile(getDraggedFile(evt.getDragboard().getFiles()));
    } else if (evt.getDragboard().hasUrl()) {
        media = MediaCache.getMediaFromUrl(evt.getDragboard().getUrl());
    } else if (evt.getDragboard().hasString()) {
        String path = evt.getDragboard().getString();
        try {
            URI.create(path);
            media = MediaCache.getMediaFromUrl(path);
        } catch (IllegalArgumentException ex) {
            File f = new File(path);
            if (f.exists()) {
                media = MediaCache.getMediaFromFile(f);
            }
        }
    }
    if (media != null) {
        evt.acceptTransferModes(TransferMode.LINK, TransferMode.COPY);
        startDragEvent(media);
    }
}
 
Example 2
Source File: ResourcePropertyEditorControl.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Handle drag over.
 */
@FxThread
private void dragOver(@NotNull DragEvent dragEvent) {

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

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

    var file = files.get(0);
    if (!canAccept(file)) {
        return;
    }

    var transferModes = dragboard.getTransferModes();
    var isCopy = transferModes.contains(TransferMode.COPY);

    dragEvent.acceptTransferModes(isCopy ? TransferMode.COPY : TransferMode.MOVE);
    dragEvent.consume();
}
 
Example 3
Source File: MaterialPropertyControl.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Handle drag over events.
 *
 * @param dragEvent the drag over event.
 */
@FxThread
private void handleDragOverEvent(@NotNull DragEvent dragEvent) {

    var dragboard = dragEvent.getDragboard();
    var files = EditorUtil.getFiles(dragboard);
    if (files.size() != 1) {
        return;
    }

    var file = files.get(0);

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

    var transferModes = dragboard.getTransferModes();
    var isCopy = transferModes.contains(TransferMode.COPY);

    dragEvent.acceptTransferModes(isCopy ? TransferMode.COPY : TransferMode.MOVE);
    dragEvent.consume();
}
 
Example 4
Source File: CardPileView.java    From Solitaire with GNU General Public License v2.0 6 votes vote down vote up
private EventHandler<DragEvent> createDragOverHandler(final ImageView pImageView, final Card pCard)
{
	return new EventHandler<DragEvent>()
	{
		@Override
		public void handle(DragEvent pEvent) 
		{
			if(pEvent.getGestureSource() != pImageView && pEvent.getDragboard().hasString())
			{
				CardTransfer transfer = new CardTransfer(pEvent.getDragboard().getString());
				if( GameModel.instance().isLegalMove(transfer.getTop(), aIndex) )
				{
					pEvent.acceptTransferModes(TransferMode.MOVE);
				}
			}
			pEvent.consume();
		}
	};
}
 
Example 5
Source File: SuitStack.java    From Solitaire with GNU General Public License v2.0 6 votes vote down vote up
private EventHandler<DragEvent> createOnDragOverHandler(final ImageView pView)
{
	return new EventHandler<DragEvent>()
   	{
   	    public void handle(DragEvent pEvent) 
   	    {
   	    	if(pEvent.getGestureSource() != pView && pEvent.getDragboard().hasString())
   	    	{
   	    		CardTransfer transfer = new CardTransfer(pEvent.getDragboard().getString());
   	    		if( transfer.size() == 1 && GameModel.instance().isLegalMove(transfer.getTop(), aIndex) )
   	    		{
   	    			pEvent.acceptTransferModes(TransferMode.MOVE);
   	    		}
   	    	}

   	    	pEvent.consume();
   	    }
   	};
}
 
Example 6
Source File: RcmController.java    From ns-usbloader with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Drag-n-drop support (dragOver consumer)
 * */
@FXML
private void handleDragOver(DragEvent event){
    if (event.getDragboard().hasFiles())
        event.acceptTransferModes(TransferMode.ANY);
    event.consume();
}
 
Example 7
Source File: SplitMergeController.java    From ns-usbloader with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Drag-n-drop support (dragOver consumer)
 * */
@FXML
private void handleDragOver(DragEvent event){
    if (event.getDragboard().hasFiles() && ! MediatorControl.getInstance().getTransferActive())
        event.acceptTransferModes(TransferMode.ANY);
    event.consume();
}
 
Example 8
Source File: MZmineGUI.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The method activateSetOnDragOver controlling what happens when something is dragged over.
 * Implemented activateSetOnDragOver to accept when files are dragged over it.
 * @param event - DragEvent
 */
public static void activateSetOnDragOver(DragEvent event){
  Dragboard dragBoard = event.getDragboard();
  if (dragBoard.hasFiles()) {
    event.acceptTransferModes(TransferMode.COPY);
  } else {
    event.consume();
  }
}
 
Example 9
Source File: DockPane.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** Accept dock items */
private void handleDragOver(final DragEvent event)
{
    if (!isFixed()  &&
        DockItem.dragged_item.get() != null)
        event.acceptTransferModes(TransferMode.MOVE);
    event.consume();
}
 
Example 10
Source File: DockItem.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** Accept other items that are dropped onto this one */
private void handleDragOver(final DragEvent event)
{
    // Don't suggest dropping into a 'fixed' pane
    if (getDockPane().isFixed())
        return;

    final DockItem item = dragged_item.get();
    if (item != null  &&  item != this)
        event.acceptTransferModes(TransferMode.MOVE);
    event.consume();
}
 
Example 11
Source File: DeckBuilderWindow.java    From Cardshifter with Apache License 2.0 5 votes vote down vote up
private void completeDragToActiveDeck(DragEvent event, boolean dropped) {
event.acceptTransferModes(TransferMode.MOVE);
if (dropped) {
	this.addCardToActiveDeck(null, this.cardBeingDragged);
}
event.consume();
}
 
Example 12
Source File: MarkdownEditorPane.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void onDragOver(DragEvent event) {
	// check whether we can accept a drop
	Dragboard db = event.getDragboard();
	if (db.hasString() || db.hasFiles())
		event.acceptTransferModes(TransferMode.COPY);

	// move drag caret to mouse location
	if (event.isAccepted()) {
		CharacterHit hit = textArea.hit(event.getX(), event.getY());
		dragCaret.moveTo(hit.getInsertionIndex());
	}

	event.consume();
}
 
Example 13
Source File: ModulesDashboardTile.java    From pdfsam with GNU Affero General Public License v3.0 4 votes vote down vote up
private Consumer<DragEvent> onDragOverConsumer() {
    return (DragEvent e) -> e.acceptTransferModes(TransferMode.COPY_OR_MOVE);
}
 
Example 14
Source File: RootLayout.java    From java_fx_node_link_demo with The Unlicense 4 votes vote down vote up
private void buildDragHandlers() {
	
	//drag over transition to move widget form left pane to right pane
	mIconDragOverRoot = new EventHandler <DragEvent>() {

		@Override
		public void handle(DragEvent event) {
			
			Point2D p = right_pane.sceneToLocal(event.getSceneX(), event.getSceneY());

			//turn on transfer mode and track in the right-pane's context 
			//if (and only if) the mouse cursor falls within the right pane's bounds.
			if (!right_pane.boundsInLocalProperty().get().contains(p)) {
				
				event.acceptTransferModes(TransferMode.ANY);
				mDragOverIcon.relocateToPoint(new Point2D(event.getSceneX(), event.getSceneY()));
				return;
			}

			event.consume();
		}
	};
	
	mIconDragOverRightPane = new EventHandler <DragEvent> () {

		@Override
		public void handle(DragEvent event) {

			event.acceptTransferModes(TransferMode.ANY);
			
			//convert the mouse coordinates to scene coordinates,
			//then convert back to coordinates that are relative to 
			//the parent of mDragIcon.  Since mDragIcon is a child of the root
			//pane, coodinates must be in the root pane's coordinate system to work
			//properly.
			mDragOverIcon.relocateToPoint(
							new Point2D(event.getSceneX(), event.getSceneY())
			);
			event.consume();
		}
	};
			
	mIconDragDropped = new EventHandler <DragEvent> () {

		@Override
		public void handle(DragEvent event) {
			
			DragContainer container = 
					(DragContainer) event.getDragboard().getContent(DragContainer.AddNode);
			
			container.addData("scene_coords", 
					new Point2D(event.getSceneX(), event.getSceneY()));
			
			ClipboardContent content = new ClipboardContent();
			content.put(DragContainer.AddNode, container);
			
			event.getDragboard().setContent(content);
			event.setDropCompleted(true);
		}
	};

	this.setOnDragDone (new EventHandler <DragEvent> (){
		
		@Override
		public void handle (DragEvent event) {
			
			right_pane.removeEventHandler(DragEvent.DRAG_OVER, mIconDragOverRightPane);
			right_pane.removeEventHandler(DragEvent.DRAG_DROPPED, mIconDragDropped);
			base_pane.removeEventHandler(DragEvent.DRAG_OVER, mIconDragOverRoot);
							
			mDragOverIcon.setVisible(false);
			
			DragContainer container = 
					(DragContainer) event.getDragboard().getContent(DragContainer.AddNode);
			
			if (container != null) {
				if (container.getValue("scene_coords") != null) {
				
					DragIcon droppedIcon = new DragIcon();
					
					droppedIcon.setType(DragIconType.valueOf(container.getValue("type")));
					right_pane.getChildren().add(droppedIcon);

					Point2D cursorPoint = container.getValue("scene_coords");

					droppedIcon.relocateToPoint(
							new Point2D(cursorPoint.getX() - 32, cursorPoint.getY() - 32)
							);
				}
			}

			event.consume();
		}
	});
}
 
Example 15
Source File: BrowsableDirectoryField.java    From pdfsam with GNU Affero General Public License v3.0 4 votes vote down vote up
private Consumer<DragEvent> onDragOverConsumer() {
    return (DragEvent e) -> e.acceptTransferModes(TransferMode.COPY_OR_MOVE);
}
 
Example 16
Source File: BrowsableFileField.java    From pdfsam with GNU Affero General Public License v3.0 4 votes vote down vote up
private Consumer<DragEvent> onDragOverConsumer() {
    return (DragEvent e) -> e.acceptTransferModes(TransferMode.COPY_OR_MOVE);
}
 
Example 17
Source File: MainController.java    From qiniu with MIT License 4 votes vote down vote up
/**
 * 开始拖曳文件
 */
public void dragFileOver(DragEvent event) {
    event.acceptTransferModes(TransferMode.ANY);
}
 
Example 18
Source File: WorkspaceNavigator.java    From Recaf with MIT License 4 votes vote down vote up
private void onDragOver(DragEvent e) {
	// Allow drag-drop content
	if (e.getGestureSource() != this && e.getDragboard().hasFiles())
		e.acceptTransferModes(TransferMode.COPY_OR_MOVE);
	e.consume();
}
 
Example 19
Source File: SearchBox.java    From mdict-java with GNU General Public License v3.0 4 votes vote down vote up
protected void enterDrag(DragEvent event) {
event.acceptTransferModes(TransferMode.MOVE);
   event.consume();
  }
 
Example 20
Source File: SelectionTable.java    From pdfsam with GNU Affero General Public License v3.0 4 votes vote down vote up
private Consumer<DragEvent> onDragOverConsumer() {
    return (DragEvent e) -> e.acceptTransferModes(TransferMode.COPY_OR_MOVE);
}