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

The following examples show how to use javafx.scene.input.DragEvent#setDropCompleted() . 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: 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 2
Source File: SuitStack.java    From Solitaire with GNU General Public License v2.0 6 votes vote down vote up
private EventHandler<DragEvent> createOnDragDroppedHandler()
{
	return new EventHandler<DragEvent>() 
   	{
   		public void handle(DragEvent pEvent)
   		{
   			Dragboard db = pEvent.getDragboard();
   			boolean success = false;
   			if(db.hasString()) 
   			{
   				CardTransfer transfer = new CardTransfer(pEvent.getDragboard().getString());
   				GameModel.instance().getCardMove(transfer.getTop(), aIndex).perform();
   				success = true;
   			}
   			pEvent.setDropCompleted(success);
   			pEvent.consume();
   		}
   	};
}
 
Example 3
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 4
Source File: MarkdownEditorPane.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void onDragDropped(DragEvent event) {
	Dragboard db = event.getDragboard();
	if (db.hasFiles()) {
		// drop files (e.g. from project file tree)
		List<File> files = db.getFiles();
		if (!files.isEmpty())
			smartEdit.insertLinkOrImage(dragCaret.getPosition(), files.get(0).toPath());
	} else if (db.hasString()) {
		// drop text
		String newText = db.getString();
		int insertPosition = dragCaret.getPosition();
		SmartEdit.insertText(textArea, insertPosition, newText);
		SmartEdit.selectRange(textArea, insertPosition, insertPosition + newText.length());
	}

	textArea.requestFocus();

	event.setDropCompleted(true);
	event.consume();
}
 
Example 5
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 6
Source File: SplitMergeController.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())
        mergeRad.fire();
    else
        splitRad.fire();
    fileFolderActualPathLbl.setText(fileDrpd.getAbsolutePath());
    convertBtn.setDisable(false);
    event.setDropCompleted(true);
    event.consume();
}
 
Example 7
Source File: MZmineGUI.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The method activateSetOnDragDropped controlling what happens when something is dropped on window.
 * Implemented activateSetOnDragDropped to select the module according to the dropped file type and open dropped file
 * @param event - DragEvent
 */

public static void activateSetOnDragDropped(DragEvent event){
  Dragboard dragboard = event.getDragboard();
  boolean hasFileDropped = false;
  if (dragboard.hasFiles()) {
    hasFileDropped = true;
    for (File selectedFile:dragboard.getFiles()) {

      final String extension = FilenameUtils.getExtension(selectedFile.getName());
      String[] rawDataFile = {"cdf","nc","mzData","mzML","mzXML","raw"};
      final Boolean isRawDataFile = Arrays.asList(rawDataFile).contains(extension);
      final Boolean isMZmineProject = extension.equals("mzmine");

      Class<? extends MZmineRunnableModule> moduleJavaClass = null;
      if(isMZmineProject)
      {
        moduleJavaClass = ProjectLoadModule.class;
      } else if(isRawDataFile){
        moduleJavaClass = RawDataImportModule.class;
      }

      if(moduleJavaClass != null){
        ParameterSet moduleParameters =
                MZmineCore.getConfiguration().getModuleParameters(moduleJavaClass);
        if(isMZmineProject){
          moduleParameters.getParameter(projectFile).setValue(selectedFile);
        } else if (isRawDataFile){
          File fileArray[] = { selectedFile };
          moduleParameters.getParameter(fileNames).setValue(fileArray);
        }
        ParameterSet parametersCopy = moduleParameters.cloneParameterSet();
        MZmineCore.runMZmineModule(moduleJavaClass, parametersCopy);
      }
    }
  }
  event.setDropCompleted(hasFileDropped);
  event.consume();
}
 
Example 8
Source File: ApkInfoPrinterActivity.java    From ApkToolPlus with Apache License 2.0 5 votes vote down vote up
public void onDragDroppedHandleFiles(DragEvent event){
    Dragboard db = event.getDragboard();
    boolean success = false;
    if (db.hasFiles()) {
        success = true;
        for (File file : db.getFiles()) {
            showManifest(file);
            break;
        }
    }
    event.setDropCompleted(success);
    event.consume();
}
 
Example 9
Source File: ModulesDashboardTile.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
private Consumer<DragEvent> onDragDropped(Function<List<File>, ? extends BaseFilesDroppedEvent> provider) {
    return (DragEvent e) -> {
        eventStudio().broadcast(activeteModule(id));
        eventStudio().broadcast(provider.apply(e.getDragboard().getFiles()));
        e.setDropCompleted(true);
    };
}
 
Example 10
Source File: BrowsableDirectoryField.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
private Consumer<DragEvent> onDragDropped() {
    return (DragEvent e) -> {
        e.getDragboard().getFiles().stream().filter(f -> f.isDirectory()).findFirst()
                .ifPresent(file -> setTextFromFile(file));
        e.setDropCompleted(true);
    };
}
 
Example 11
Source File: BrowsableFileField.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
private Consumer<DragEvent> onDragDropped() {
    return (DragEvent e) -> {
        e.getDragboard().getFiles().stream().filter(f -> fileType.matches(f.getName())).findFirst()
                .ifPresent(file -> setTextFromFile(file));
        e.setDropCompleted(true);
    };
}
 
Example 12
Source File: DockPane.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
/** Accept a dropped tab */
private void handleDrop(final DragEvent event)
{
    final DockItem item = DockItem.dragged_item.getAndSet(null);
    if (item == null)
        logger.log(Level.SEVERE, "Empty drop, " + event);
    else
    {
        logger.log(Level.INFO, "Somebody dropped " + item + " into " + this);
        final TabPane old_parent = item.getTabPane();

        // Unexpected, but would still "work" at this time
        if (! (old_parent instanceof DockPane))
            logger.log(Level.SEVERE, "DockItem is not in DockPane but " + old_parent);

        // When moving to a new scene,
        // assert that styles used in old scene are still available
        final Scene old_scene = old_parent.getScene();
        final Scene scene = getScene();
        if (scene != old_scene)
            for (String css : old_scene.getStylesheets())
                Styles.set(scene, css);



        // Move tab. In principle,
        // (1) first remove from old parent,
        // (2) then add to new parent.
        // But modifying tabs triggers tab listener, which registers SplitPane.merge()
        // in Platform.runLater(). The merge could re-arrange tab panes,
        // we when we later want to add the tab, we'll face a different scene graph.
        // Issue the tab addition (2) with runlater right now so it'll happen before any
        // split pane cleanup.
        Platform.runLater(() ->
        {
            // When adding the tab to its new parent (this dock) right away,
            // the tab would sometimes not properly render until the pane is resized.
            // Moving to the next UI tick helps
            logger.log(Level.INFO, "Adding " + item + " to " + this);
            addTab(item);
            Platform.runLater(this::autoHideTabs);
        });

        // With tab addition already in the UI thread queue, remove item from old tab
        logger.log(Level.INFO, "Removing " + item + " from " + old_parent);
        old_parent.getTabs().remove(item);
    }
    event.setDropCompleted(true);
    event.consume();
}
 
Example 13
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 14
Source File: SelectionTable.java    From pdfsam with GNU Affero General Public License v3.0 4 votes vote down vote up
private Consumer<DragEvent> onDragDropped() {
    return (DragEvent e) -> {
        eventStudio().broadcast(new MultipleFilesDroppedEvent(ownerModule, e.getDragboard().getFiles()));
        e.setDropCompleted(true);
    };
}