CodeHacker: use the default ClassPool

This is required to interact collegially with Fiji's class patching.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Hold a reference to the current LegacyService in ij.IJ itself

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Add a dummy LegacyService

We would like to be able to run ImageJ 1.x even when patched with
the LegacyInjector, without having to have to test whether there
is a LegacyService or not. To make that happen, let's always have a
LegacyService (even if it does not do anything).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Make sure that there is always a LegacyService available in ImageJ 1.x

... even if it is only a DummyLegacyService...

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Deprecate imagej.legacy.Utils#isLegacyMode()

Now that we always have a LegacyService, we can ask it directly
whether we're running in legacy mode or not.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Only instantiate a new ImageJ 1.x if there is none yet

This change is needed for Fiji to be able to start in legacy mode
and then to switch to modern mode (just after creating a new Context).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Legacy Service: Do not add commands without a menuPath

We should make such commands available, just be prepared that they
might not have a menuPath.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
LegacyInjector: inject ij.IJ.getContext()

This will be convenient for scripts.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
LegacyInjector: special-case Context and LegacyService in IJ.runPlugIn

Now you can call

	legacyService = (LegacyService)
		IJ.runPlugIn(LegacyService.class.getName(), null);

to obtain the current LegacyService. Likewise, you can call

	context = (Context)IJ.runPlugIn(Context.class.getName(), null);

to retrieve the Context whose LegacyService is connected to the
current ij.IJ class.

It is not quite the intended use for the IJ.runPlugIn method but it
helps immensely ImageJ 1.x plugins requiring ImageJ2 services.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
SwitchToModernMode: use a better way to obtain the LegacyService

We just introduced a hack to IJ.runPlugIn which allows us to obtain
the LegacyService associated with a given ij.IJ class easily. We
might just as well eat our own dog food.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
SwitchToModernMode: initialize Context if necessary

We want this plugin to work even if there was no SciJava Context
yet... i.e. if this plugin is run from ImageJ 1.x without ImageJ2
running before that, we still want things to work nicely.

This will be needed for the upcoming Help>Switch To Modern Mode
support in Fiji.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
SwitchToModernMode: make the menu label public

This change Was intended to help Fiji but is actually not needed.
However, there is no need to revert this change; why not make the label
public anyway?

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
SwitchToModernMode: no need for a LegacyService to register the plugin

While at it, make it public for use by Fiji.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
SwitchToModernMode: avoid instantiating a MenuItem in headless mode

When registering the plugin in headless mode, we need not care about
menus to begin with.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
SwitchToModernMode: leave the 'Update Fiji' and 'Fiji Wiki' on the bottom

Users are probably comfortable with seeing the 'Update' and the Wiki
entry at the bottom of the help menu; let's not let the modern mode
switcher interfere with that expectation.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
DefaultLegacyService#toggleLegacyMode: an appFrame might not yet exist...

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Enable the IJ1 ROI Manager in legacy mode

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Merge branch 'ij-legacy-fiji-compat'

This is only a preliminary support for the legacy mode, in particular an
early-bird preview of supporting Fiji to start up in ImageJ 1.x mode and
switch to ImageJ2 mode later on.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>

Conflicts:
	core/legacy/src/main/java/imagej/legacy/DefaultLegacyService.java
	core/legacy/src/main/java/imagej/legacy/LegacyInjector.java
Also needed fixing:
	core/legacy/src/main/java/imagej/legacy/CodeHacker.java