Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open extra file types with SCIFIO enabled #253

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions src/main/java/net/imagej/legacy/plugin/DefaultLegacyOpener.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

package net.imagej.legacy.plugin;

import ij.ImagePlus;

import io.scif.Metadata;
import io.scif.app.SCIFIOApp;
import io.scif.img.SCIFIOImgPlus;
Expand Down Expand Up @@ -62,6 +60,9 @@
import org.scijava.options.OptionsService;
import org.scijava.plugin.Plugin;
import org.scijava.service.Service;
import org.scijava.ui.UIService;

import ij.ImagePlus;

/**
* The default {@link LegacyOpener} plugin.
Expand All @@ -84,6 +85,7 @@ public class DefaultLegacyOpener implements LegacyOpener {
private AppService appService;
private IOService ioService;
private LogService logService;
private UIService uiService;

@Override
public Object open(String path, final int planeIndex,
Expand All @@ -92,14 +94,7 @@ public Object open(String path, final int planeIndex,
final Context c = IJ1Helper.getLegacyContext();
ImagePlus imp = null;

legacyService = getCached(legacyService, LegacyService.class, c);
displayService = getCached(displayService, DisplayService.class, c);
moduleService = getCached(moduleService, ModuleService.class, c);
commandService = getCached(commandService, CommandService.class, c);
optionsService = getCached(optionsService, OptionsService.class, c);
appService = getCached(appService, AppService.class, c);
ioService = getCached(ioService, IOService.class, c);
logService = getCached(logService, LogService.class, c);
initServices(c);

// Check to see if SCIFIO has been disabled
final boolean newStyleIO =
Expand Down Expand Up @@ -205,13 +200,30 @@ public Object open(String path, final int planeIndex,
return imp;
}
}
else if (displayResult) {
// Attempt to display non-dataset data
uiService.show(data);
}
return data;
}
return path;
}


// -- Helper methods --

private void initServices(final Context c) {
legacyService = getCached(legacyService, LegacyService.class, c);
displayService = getCached(displayService, DisplayService.class, c);
moduleService = getCached(moduleService, ModuleService.class, c);
commandService = getCached(commandService, CommandService.class, c);
optionsService = getCached(optionsService, OptionsService.class, c);
appService = getCached(appService, AppService.class, c);
ioService = getCached(ioService, IOService.class, c);
logService = getCached(logService, LogService.class, c);
uiService = getCached(uiService, UIService.class, c);
}

private <T extends Service> T getCached(T service, Class<T> serviceClass, Context ctx) {
if (service != null) return service;
return ctx.getService(serviceClass);
Expand Down