public final class LegacyService extends AbstractService implements ImageJService
The legacy service overrides the behavior of various legacy ImageJ methods, inserting seams so that (e.g.) the modern UI is aware of legacy ImageJ events as they occur.
It also maintains an image map between legacy ImageJ ImagePlus
objects and modern ImageJ ImageDisplay
s.
In this fashion, when a legacy command is executed on a ImageDisplay
,
the service transparently translates it into an ImagePlus
, and
vice versa, enabling backward compatibility with legacy commands.
Constructor and Description |
---|
LegacyService() |
Modifier and Type | Method and Description |
---|---|
void |
dispose() |
App |
getApp() |
IJ1Helper |
getIJ1Helper()
Gets the helper class responsible for direct interfacing with ImageJ1.
|
LegacyImageMap |
getImageMap()
Gets the LegacyImageMap associated with this LegacyService.
|
static LegacyService |
getInstance()
Returns the legacy service associated with the ImageJ 1.x instance in the
current class loader.
|
Map<String,ModuleInfo> |
getScriptsAndNonLegacyCommands()
This is not part of the public API.
|
String |
getVersion()
Gets the version of ImageJ 1.x being used.
|
void |
handleException(Throwable e) |
void |
initialize() |
boolean |
isActive()
Gets whether this
LegacyService is fully operational, linked to the
ImageJ 1.x singleton instance. |
boolean |
isInitialized()
Returns true if this LegacyService has been initialized already and false
if not.
|
boolean |
isLegacyMode()
States whether we're running in legacy ImageJ 1.x mode.
|
boolean |
isProcessingEvents()
This is not part of the public API.
|
boolean |
isSyncEnabled()
States whether ImageJ1 and ImageJ2 data structures should be kept in sync.
|
LogService |
log()
Gets the LogService associated with this LegacyService.
|
TextEditor |
openScriptInTextEditor(ScriptInfo script) |
static void |
preinit()
Deprecated.
use
LegacyInjector.preinit() instead |
void |
runLegacyCommand(String ij1ClassName,
String argument)
Runs a legacy command programmatically.
|
Object |
runLegacyCompatibleCommand(String key)
Runs the legacy compatible command with the given identifier.
|
void |
setIJ1Helper(IJ1Helper ij1Helper)
This is not part of the public API.
|
boolean |
setProcessingEvents(boolean processing)
This is not part of the public API.
|
StatusService |
status()
Gets the StatusService associated with this LegacyService.
|
void |
syncActiveImage()
Ensures that the currently active
ImagePlus matches the
currently active ImageDisplay . |
void |
toggleLegacyMode(boolean wantIJ1)
Switches to/from running legacy ImageJ 1.x mode.
|
void |
toggleLegacyMode(boolean wantIJ1,
boolean initializing) |
UIService |
uiService() |
getContext, setContext, toString
getInfo, getPriority, setInfo, setPriority
context
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
registerEventHandlers
getIdentifier
context, getContext, setContext
compareTo, getPriority, setPriority
getInfo, setInfo
getLocation
public LogService log()
log
in interface Logged
log
in interface RichPlugin
public StatusService status()
public UIService uiService()
public boolean isActive()
LegacyService
is fully operational, linked to the
ImageJ 1.x singleton instance. Inactive LegacyService
s are dummies,
which are not tied to ImageJ 1.x.LegacyService
is the active one, tied to the
singleton instance of ImageJ 1.x.public IJ1Helper getIJ1Helper()
ij.*
classes should be done through this
helper class, to avoid class loader woes.IJ1Helper
, or null
if this
LegacyService
is inactive (see isActive()
).public LegacyImageMap getImageMap()
public void runLegacyCommand(String ij1ClassName, String argument)
ij1ClassName
- The name of the plugin class you want to run e.g.
"ij.plugin.Clipboard"argument
- The argument string to pass to the plugin e.g. "copy"public Object runLegacyCompatibleCommand(String key)
key
- The identifier of the command to execute.Future
of the command execution; or if the identifier
describes a script and the shift key is down, then the
TextEditor
of the new Script Editor window which was
opened.Identifiable
public void syncActiveImage()
ImagePlus
matches the
currently active ImageDisplay
. Does not perform any harmonization.public boolean isInitialized()
public boolean isSyncEnabled()
While synchronization is supposed to be as cheap as possible, in practice
there are limitations with it currently which impact performance. So such
synchronization is off by default. The main consequence is that it becomes
harder to "mix and match" ImageJ1 and ImageJ2 APIs: you cannot open an
ImagePlus
and then reference it later from an ImageJ2
Command
as a Dataset
unless
synchronization is enabled.
public boolean isLegacyMode()
To support work flows which are incompatible with ImageJ2, we want to allow users to run in legacy ImageJ 1.x mode, where the ImageJ2 GUI is hidden and the ImageJ 1.x GUI is shown. During this time, no synchronization should take place.
public void toggleLegacyMode(boolean wantIJ1)
public void toggleLegacyMode(boolean wantIJ1, boolean initializing)
public App getApp()
public void handleException(Throwable e)
public void initialize()
initialize
in interface Initializable
initialize
in interface Service
public void dispose()
dispose
in interface Disposable
public String getVersion()
getVersion
in interface Versioned
public static LegacyService getInstance()
public void setIJ1Helper(IJ1Helper ij1Helper)
This method makes it possible to override the IJ1Helper
behavior,
to facilitate unit testing.
public boolean setProcessingEvents(boolean processing)
This method toggles a ThreadLocal
flag as to whether or not legacy
UI components are in the process of handling StatusEvents
.
public boolean isProcessingEvents()
ThreadLocal
check to see if components are in the middle of
processing events.
LegacyService
.public Map<String,ModuleInfo> getScriptsAndNonLegacyCommands()
Adds all legacy compatible commands to the ImageJ1 menus. The nested menu structure of each command is preserved.
public TextEditor openScriptInTextEditor(ScriptInfo script)
@Deprecated public static void preinit()
LegacyInjector.preinit()
insteadWe absolutely require that the LegacyInjector did its job before we use the ImageJ 1.x classes.
Just loading the LegacyService
class is not enough; it will not
necessarily get initialized. So we provide this method just to force class
initialization (and thereby the LegacyInjector to patch ImageJ 1.x).
Copyright © 2014–2022 ImageJ. All rights reserved.