Skip to content

Instantly share code, notes, and snippets.

@xulman
Created February 6, 2022 12:31
Show Gist options
  • Save xulman/83dfea575266e355383f033aef67f372 to your computer and use it in GitHub Desktop.
Save xulman/83dfea575266e355383f033aef67f372 to your computer and use it in GitHub Desktop.
drag&drop handler of BDV's xml (should be part of BDV-core distro)
package cz.ulman.dnd;
import org.scijava.Priority;
import org.scijava.io.IOService;
import org.scijava.io.location.FileLocation;
import org.scijava.io.location.Location;
import org.scijava.plugin.Plugin;
import org.scijava.io.IOPlugin;
import org.scijava.io.AbstractIOPlugin;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
@Plugin(type = IOPlugin.class, priority = Priority.FIRST)
public class BdvIoPlugin extends AbstractIOPlugin<Object> {
@Override
public boolean supportsOpen(final Location source) {
if (!(source instanceof FileLocation)) return false;
if (!(source.getName().endsWith(".xml"))) return false;
//is the content really that of BDV?
try (BufferedReader file = new BufferedReader(new FileReader(
((FileLocation)source).getFile().getAbsolutePath() ))) {
file.readLine();
return file.readLine().trim().startsWith("<SpimData version");
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
@Override
public Object open(final Location source) throws IOException {
//BDV call here...
return IOService.GOVERNING_APP_STARTED;
}
@Override
public Class<Object> getDataType() {
return Object.class;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment