Start up legacy service in legacy mode

While the LegacyService is being initialized, we cannot rely on any
ImageJ2 services yet. So the best idea is to say that we're in legacy
mode. If an ImageJ 1.x instance is currently running, our best bet is
to stay in legacy mode. Otherwise, let's switch to modern mode just
after initialization is complete -- toggleLegacyMode() knows that it
should not try to show anything if no UI is available.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Switch To Modern Mode: toggle all ImagePluses WindowManager knows about

When starting Fiji in ImageJ 1.x mode, switching to modern mode after
opening images should take them to modern mode, too.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
CodeHacker: mark classes explicitly as frozen after loading them

This hopefully helps a little bit with the upcoming move of stuff from
Fiji's IJ1Hacker to ij-legacy.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
CodeHacker: commit all handled classes at the end

That should help with the upcoming move of stuff from fiji-compat:
some classes are handled multiple times and in different ways, so we
should only define the classes at the very end.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Move some backwards-compatible legacy stuff from fiji-compat to ij-legacy

This adds back some legacy methods that should have been marked as
@Deprecated instead of removed without warning.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Move fiji-compat's special handling for Apple's Mighty Mouse

On some Linuxes, the horizontal scroll wheel of the Mighty Mouse is
mistaken for a popup trigger. This change adds a work-around.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
ij-legacy: add back some legacy ij.ImagePlus methods

These methods went away at some stage without being marked as
@Deprecated first.

Moved from fiji-compat.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Move some ij.IJ patches over from fiji-compat

This change makes sure that ImageJ 1.x is properly initialized when
calling macros in batch mode.

It also adds the ij.log.file handling: when this property is set,
IJ.log() will log not only to the Log window but also to the file
pointed to by the property.

While at it, runUserPlugIn() sets the context class loader for the
benefit of scripting languages and SezPoz (and therefore ImageJ2).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Fix ImageJ 1.x quitting in legacy mode

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Move the headless legacy code from Fiji to ImageJ2

It is in general a very hard problem to let code run headlessly that
relies on GUI classes.

In Fiji (actually, before that, in ImageJA), we started to support that by
replacing GUI classes by non-GUI classes so that ImageJ could run without
a graphical desktop.

Later, we converted that code to use Javassist for easier maintenance.

Now, let's add unit tests to ensure a certain level of reliability of the
legacy headless mode; it will never be a 100% complete, but hopefully good
enough for many applications. For those where the legacy headless mode is
not good enough, there is simply no good excuse: they need to be ported to
leverage the ImageJ2 architecture.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Add unit tests for the legacy headless support

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Improve LegacyHeadless' javadoc

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
OverlayHarmonizerTest: we really, really have to give CodeHacker
a chance

Same as in the other legacy tests: we *need* to give CodeHacker a
chance to patch the legacy classes, otherwise the other tests *will*
fail (and the error message will not point back to the real culprit.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
CodeHacker: optionally use a separate ClassPool

When running the unit tests, we need to run a few tests with a different
class loader, most notably the headless legacy tests. In that case, our
headless patching *needs* to use a different ClassPool (otherwise the
ImageJ 1.x classes are considered to be frozen).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Use the new CodeHacker constructor in the LegacyHeadlessTest

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Fix compile warnings in ij-legacy

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

The merged changes fall into three categories:

- support Fiji's upcoming Help>Switch To Modern Mode

- move some compatibility patches from fiji-compat's IJHacker into
  ImageJ2

- move fiji-compat's Headless patches for (limited) headless legacy
  support: this will allow many legacy plugins to operate in headless
  mode

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