Java Code Examples for javafx.scene.input.Dragboard#hasFiles()

The following examples show how to use javafx.scene.input.Dragboard#hasFiles() . 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: 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 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: 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 4
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 5
Source File: GroupResource.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean droppable(Dragboard dragboard) {
    if (dragboard.hasFiles()) {
        return type.droppable(dragboard.getFiles(), getFilePath());
    }
    return false;
}
 
Example 6
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 7
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 8
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 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();
}