DefaultLegacyService: add event processing API

Added isProcessingEvents and setProcessingEvents. These set and return
ThreadLocal values for whether or not status events are being processed.

Note that this API is public but not really intended for public
consumption.
LegacyStatusBar: don't double process events

The LegacyStatusBar now takes advantage of the DefaultLegacyService's
API for setting and checking if a given thread is already processing
status events. If so, we know that we have already entered the given
method of the status bar on that thread, so it is the same event being
processed and we should not re-process it.

Doing so will cause endless numbers of threads to be spawned.
DefaultLegacyHooks: don't process the same event

Similar to the changes to the LegacyStatusBar, if an event has already
been processed by the IJ2 framework, we do not want to trigger its
processing again via the legacy hooks.
Add LegacyCompatibleCommands to IJ1 menus

The LegacyCompatibleCommand is now a marker interface to designate IJ2
commands that should be added to the ImageJ1 menu structure.

The DefaultLegacyService will now find these commands and, preserving
their menu structure, insert them into the ImageJ1 menus. Existing,
overlapping menu structure will be reused where avilable, and created if
it does not already exist.
DefaultLegacyService: try, catch module creation

Apparently there are scenarios where ModuleService.createModule can
still throw exceptions. So we will catch them and just not add those
modules to the IJ1 menu.
Teach IJ1Helper to add legacy-compatible commands to the menu bar

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
LegacyCompatibleCommands really *are* Commands

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

Instead of making DefaultLegacyService an ActionListener, we now use the
interceptRunPlugIn() method to run the legacy-compatible commands.

This solves a couple of issues:

- it runs in headless mode, too

- it keeps DefaultLegacyService clean of ImageJ 1.x and AWT classes

- the way we do it now, we avoid instantiating the command classes when
  populating the menu structure (and thereby avoid the problem where
  some legacy-compatible command might require a service that has not been
  initialized at the time DefaultLegacyService is initialized; thank you
  so much, Jennis Jenkins!)

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Merge branch 'legacy-compatible-commands'

This topic branch restructures the way we handle legacy-compatible
commands such that they work also in headless mode (and such that the
initialization is quicker by avoiding to instantiate all of the command
classes).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
IJ1Helper: fix IJ1MenuWrapper#get

Corrected the implementation of the get method in IJ1MenuWrapper. Key
fixes include:

* Ignore trailing whitespace on menu names (as "Edit > ..." was being
  cut to "Edit " and not matching the "Edit" menu, for example).
* Test against existing menu labels and not names (IJ1 menus are named
  "menu1", "menu2", etc... but their labels, such as "File", "Edit",
  etc.. are what we want to compare.
* Added documentation to explain what this method is doing.

IJ2 menus should now be properly translated to IJ1 menu structures.
IJ1Helper: add javadoc for menu translation

Adds some basic javadoc for the methods used in translating IJ2 menus to
IJ1 menus.
DefaultLegacyService: remove unused import

Don't need the ShadowMenu import here any more.
IJ1Helper: also need to trim the leaf command

When adding the final leaf item to our menu structure, it was not being
trimmed of whitespace. This caused it to not match the name that was
registered as an IJ1 command and thus have no associated operation when
selected from the menu (and also causing 2 entries in the IJ1 plugin
list - one with whitespace, one without).

By trimming the actual command name, the menu item now matches the
command and executes properly when selected from the IJ1 menu.
LegacyOpener: Facilitate canceling

If the OpenFile command is canceled (e.g. by canceling the file chooser
dialog) then we will now return an object (Boolean.TRUE) indicating the
call was canceled. This should prevent duplicate dialogs from popping up
(once by IJ2, and then by IJ1).
LegacyImageMap: do not create a new ImageWindow

First, it is wrong to always create just an "ImageWindow". If we have a
hyperstack then we should be creating a "StackWindow".

Second, there are other things that happen in ImagePlus.show, for
example, regarding Window creation. It's possible that we want those
things to happen (e.g. when using the LegacyUI).

Third, creating this window actually prevents consumers (e.g.
LegacyImageDisplayViewer) from calling show(), because the ImagePlus
thinks it's visible already.

So let's just register the given display, and let consuming code decide
what needs to be done with the new ImagePlus.
Merge pull request #13 from imagej/dont-create-imagewindow

Removed code blocking ImagePlus.show from functioning after registering a Display.
Add LegacyInputHarvester

Needed a trivial LegacyInputHarvester. This can function the same as the
SwingInputHarvester (since IJ1 and thus the LegacyUI is effectively a
Swing UI). Just needed to tie it to the LegacyUI.
Fix license header

This file was copied from scripting-java, which has a *slightly*
different license header (although the same type of license: BSD-2).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Add script editor templates from Fiji's Script Editor

With ImageJ2's script editor, every component can ship their own
templates simply by bundling things in the /script-editor/ directory
of the .jar file. To provide everything needed for Fiji to switch
to the new script editor, imagej-legacy needs to take custody of the
templates for use with the legacy ImageJ 1.x classes.

This commit brings a verbatim copy of the templates from Fiji's
Script Editor. In the next commits, we will work on them more.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Add a TestDrive for the editor in legacy mode

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