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

The following examples show how to use javafx.scene.input.DragEvent#getDragboard() . 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: 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 2
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 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: 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 5
Source File: ResourceConfigurationView.java    From beatoraja with GNU General Public License v3.0 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()) {
				final String defaultPath = new File(".").getAbsoluteFile().getParent() + File.separatorChar;;
				String targetPath = f.getAbsolutePath();
				if(targetPath.startsWith(defaultPath)) {
					targetPath = f.getAbsolutePath().substring(defaultPath.length());
				}
				boolean unique = true;
				for (String path : bmsroot.getItems()) {
					if (path.equals(targetPath) || targetPath.startsWith(path + File.separatorChar)) {
						unique = false;
						break;
					}
				}
				if (unique) {
					bmsroot.getItems().add(targetPath);
					main.loadBMSPath(targetPath);
				}
			}
		}
	}
}
 
Example 6
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 7
Source File: ResourcePropertyEditorControl.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Handle dropped files to editor.
 */
@FxThread
private void dragDropped(@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;
    }

    handleFile(file);
}
 
Example 8
Source File: WidgetTransfer.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @param event The {@link DragEvent} containing the dragged data.
 * @param selection_tracker Used to get the grid steps from its model to be
 *            used in offsetting multiple widgets.
 * @param widgets The container of the created widgets.
 */
private static void installWidgetsFromString (
    final DragEvent event,
    final SelectedWidgetUITracker selection_tracker,
    final List<Widget> widgets
) {

    final Dragboard db = event.getDragboard();
    final String xmlOrText = db.getString();

    try {
        widgets.addAll(ModelReader.parseXML(xmlOrText).getChildren());
    } catch ( Exception ex ) {
        installWidgetsFromString(event, xmlOrText, selection_tracker, widgets);
    }

}
 
Example 9
Source File: SearchBox.java    From mdict-java with GNU General Public License v3.0 5 votes vote down vote up
protected void handleDrop(DragEvent event) {
    Dragboard db = event.getDragboard();
    if(db.hasContent(DataFormat.PLAIN_TEXT)) {
    	String val = (String) db.getContent(DataFormat.PLAIN_TEXT);
    	((TextField)event.getSource()).setText(val);
    	event.consume();
    }
}
 
Example 10
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 11
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 12
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 13
Source File: ResourceConfigurationView.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
@FXML
public void onSongPathDragOver(DragEvent ev) {
	Dragboard db = ev.getDragboard();
	if (db.hasFiles()) {
		ev.acceptTransferModes(TransferMode.COPY_OR_MOVE);
	}
	ev.consume();
}
 
Example 14
Source File: NBTTreeView.java    From mcaselector with MIT License 5 votes vote down vote up
private void onDragDone(DragEvent e) {
	Dragboard db = e.getDragboard();
	if (db.hasContent(CLIPBOARD_DATAFORMAT)) {
		dragboardContent = null;
	}

	if (dropTargetCell != null) {
		dropTargetCell.setInsertCssClass("drop-target", null);
	}
	setInsertParentCss(false);
}
 
Example 15
Source File: NBTTreeView.java    From mcaselector with MIT License 5 votes vote down vote up
private void onDragDropped(DragEvent e) {
	Dragboard db = e.getDragboard();
	if (db.hasContent(CLIPBOARD_DATAFORMAT)) {
		// this treecell receives a foreign drop
		// get content and insert into this tag, before this tag or after this tag
		// and remove dropped tag from old location

		// we also don't want to do anything if the tag is dropped onto itself or if the target is invalid
		if (getTreeItem() != null && dragboardContent != getTreeItem() && dropTarget != null) {
			((NBTTreeItem) dropTarget).moveHere(dropIndex, (NBTTreeItem) dragboardContent, getTreeView());
		}
		dragboardContent = null;
	}
}
 
Example 16
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 17
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();
}