Skip to content

Instantly share code, notes, and snippets.

@xulman
Created February 5, 2022 19:53
Show Gist options
  • Save xulman/b558f36bdff88b7fe9f7136b62b9e01e to your computer and use it in GitHub Desktop.
Save xulman/b558f36bdff88b7fe9f7136b62b9e01e to your computer and use it in GitHub Desktop.
starting Mastodon with Drag&Drop onto Fiji window
package cz.ulman.dnd;
import org.scijava.plugin.Plugin;
import org.scijava.io.IOPlugin;
import org.scijava.io.AbstractIOPlugin;
import org.scijava.io.location.FileLocation;
import org.scijava.io.location.Location;
import java.io.IOException;
import java.util.ArrayList;
import mpicbg.spim.data.SpimDataException;
import org.mastodon.mamut.MainWindow;
import org.mastodon.mamut.WindowManager;
import org.mastodon.mamut.project.MamutProjectIO;
@Plugin(type = IOPlugin.class)
public class MastodonIoPlugin extends AbstractIOPlugin<Object> {
@Override
public boolean supportsOpen(final Location source) {
if (!(source instanceof FileLocation)) return false;
if (!(source.getName().endsWith(".mastodon"))) return false;
return true;
}
@Override
public Object open(final Location source) throws IOException {
final FileLocation fsource = source instanceof FileLocation ? (FileLocation)source : null;
if (fsource == null) return null; //NB: shouldn't happen...
startMastodon(fsource.getFile().getAbsolutePath());
return FAKEINPUT;
}
//the "innocent" product of the (hypothetical) file reading...
private static final Object FAKEINPUT = new ArrayList<Object>(0);
@Override
public Class<Object> getDataType() {
return Object.class;
}
void startMastodon(final String projectFile) {
try {
System.setProperty("apple.laf.useScreenMenuBar", "true");
final WindowManager windowManager = new WindowManager(getContext());
windowManager.getProjectManager().open( new MamutProjectIO().load(projectFile) );
new MainWindow(windowManager).setVisible(true);
} catch (IOException | SpimDataException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment