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

The following examples show how to use javafx.scene.input.DragEvent#consume() . 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: 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 2
Source File: CardPileView.java    From Solitaire with GNU General Public License v2.0 6 votes vote down vote up
private EventHandler<DragEvent> createDragDroppedHandler(final ImageView pImageView, final Card pCard)
{
	return new EventHandler<DragEvent>() 
	{
		@Override
		public void handle(DragEvent pEvent)
		{
			Dragboard db = pEvent.getDragboard();
			boolean success = false;
			if(db.hasString()) 
			{
				GameModel.instance().getCardMove(new CardTransfer(db.getString()).getTop(), aIndex).perform(); 
				success = true;
			}

			pEvent.setDropCompleted(success);

			pEvent.consume();
		}
	};
}
 
Example 3
Source File: FrontController.java    From ns-usbloader with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Drag-n-drop support (drop consumer)
 * */
@FXML
private void handleDrop(DragEvent event){
    List<File> filesDropped = event.getDragboard().getFiles();

    if (getSelectedProtocol().equals("TinFoil") && MediatorControl.getInstance().getContoller().getSettingsCtrlr().getTfXciNszXczSupport())
        filesDropped.removeIf(file -> ! file.getName().toLowerCase().matches("(.*\\.nsp$)|(.*\\.xci$)|(.*\\.nsz$)|(.*\\.xcz$)"));
    else if (getSelectedProtocol().equals("GoldLeaf") && (! MediatorControl.getInstance().getContoller().getSettingsCtrlr().getNSPFileFilterForGL()))
        filesDropped.removeIf(file -> (file.isDirectory() && ! file.getName().toLowerCase().matches(".*\\.nsp$")));
    else
        filesDropped.removeIf(file -> ! file.getName().toLowerCase().matches(".*\\.nsp$"));

    if ( ! filesDropped.isEmpty() )
        tableFilesListController.setFiles(filesDropped);

    event.setDropCompleted(true);
    event.consume();
}
 
Example 4
Source File: DockItem.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** Handle that this tab was dragged elsewhere, or drag aborted */
private void handleDragDone(final DragEvent event)
{
    final DockItem item = dragged_item.getAndSet(null);
    if (item != null  &&  !event.isDropCompleted())
    {
        // Would like to position new stage where the mouse was released,
        // but event.getX(), getSceneX(), getScreenX() are all 0.0.
        // --> Using MouseInfo, which is actually AWT code
        final Stage other = item.detach();
        final PointerInfo pi = MouseInfo.getPointerInfo();
        if (pi != null)
        {
            final Point loc = pi.getLocation();
            other.setX(loc.getX());
            other.setY(loc.getY());
        }
    }
    event.consume();
}
 
Example 5
Source File: CardPileView.java    From Solitaire with GNU General Public License v2.0 6 votes vote down vote up
private EventHandler<DragEvent> createDragEnteredHandler(final ImageView pImageView, final Card pCard)
{
	return new EventHandler<DragEvent>()
	{
		@Override
		public void handle(DragEvent pEvent)
		{
			CardTransfer transfer = new CardTransfer(pEvent.getDragboard().getString());
			if( GameModel.instance().isLegalMove(transfer.getTop(), aIndex) )
			{
				pImageView.setEffect(new DropShadow());
			}
			pEvent.consume();
		}
	};
}
 
Example 6
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 7
Source File: RcmController.java    From ns-usbloader with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Drag-n-drop support (drop consumer)
 * */
@FXML
private void handleDrop(DragEvent event){
    Node sourceNode = (Node) event.getSource();
    File fileDrpd = event.getDragboard().getFiles().get(0);

    if (fileDrpd.isDirectory()){
        event.setDropCompleted(true);
        event.consume();
        return;
    }

    String fileNameDrpd = fileDrpd.getAbsolutePath();

    switch (sourceNode.getId()){
        case "plHbox1":
            setPayloadFile( 1, fileNameDrpd);
            break;
        case "plHbox2":
            setPayloadFile( 2, fileNameDrpd);
            break;
        case "plHbox3":
            setPayloadFile( 3, fileNameDrpd);
            break;
        case "plHbox4":
            setPayloadFile( 4, fileNameDrpd);
            break;
        case "plHbox5":
            setPayloadFile( 5, fileNameDrpd);
    }
    event.setDropCompleted(true);
    event.consume();
}
 
Example 8
Source File: DockItem.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** Highlight while 'drop' is possible */
private void handleDragEntered(final DragEvent event)
{
    // Drop not possible into a 'fixed' pane
    if (getDockPane().isFixed())
        return;

    final DockItem item = dragged_item.get();
    if (item != null  &&  item != this)
    {
        name_tab.setBorder(DROP_ZONE_BORDER);
        name_tab.setTextFill(Color.GREEN);
    }
    event.consume();
}
 
Example 9
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 10
Source File: DockPane.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** Highlight while 'drop' is possible */
private void handleDragEntered(final DragEvent event)
{
    if (!isFixed()  &&
        DockItem.dragged_item.get() != null)
        setBorder(DockItem.DROP_ZONE_BORDER);
    event.consume();
}
 
Example 11
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 12
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 13
Source File: BrowsableDirectoryField.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
private void dragConsume(DragEvent e, Consumer<DragEvent> c) {
    List<File> files = e.getDragboard().getFiles();
    if (files != null && !files.isEmpty()) {
        c.accept(e);
    }
    e.consume();
}
 
Example 14
Source File: ApkInfoPrinterActivity.java    From ApkToolPlus with Apache License 2.0 5 votes vote down vote up
public void onDragOverLinkFile(DragEvent event){
    Dragboard db = event.getDragboard();
    if (db.hasFiles()) {
        event.acceptTransferModes(TransferMode.LINK);
    } else {
        event.consume();
    }
}
 
Example 15
Source File: FrontController.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 16
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 17
Source File: DockPane.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
/** Remove Highlight */
private void handleDragExited(final DragEvent event)
{
    setBorder(Border.EMPTY);
    event.consume();
}
 
Example 18
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 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: 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();
}