ScriptService: add eval(name, reader)

Not always do we want to run scripts which are stored in files;
allowing to execute scripts from InputStreams adds the option to run
scripts from Strings via a StringReader.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
ScriptService: discover and add javax.scripting engines

In the future, we will add more interfaces for the Script interpreters
which the javax.scripting engines do not support, such as letting us
redirect input/output, support single-stepping and breakpoints and
importing classes/packages by default. But these are just capabilities we
will add using duck-typing, and the javax.scripting engines simply will
not support those capabilities.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
ScriptPlugin: catch all Throwables, not just ScriptException

There is no default display for exceptions, so let's make extra sure that
the user is notified of problems.

While at it, show only the target exception for ScriptExceptions.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
ScriptPlugin: avoid using the deprecated Log class

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Add abstract base classes for ScriptEngine and ScriptEngineFactory

We will need only a fraction of the functionality offered by Java's
Scripting support.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
AbstractScriptEngine: implement engine scope bindings

This will be needed to support proper file attributions for stack traces,
as well as making the current ImageJ context available as a local
variable.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
AbstractEngine: remove minimal bindings, add script context

The engine-scope bindings need to be implemented by every script
language adapter, as the global variables are set that way.

Also, we need a minimal script context unfortunately, to redirect stdin,
stderr and stdout.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
AbstractScriptEngineFactory: make the class name the default language name

... and also the default engine name.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Script Service: offer an API to set file name and stdout/stderr

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Make the ImageJ context known to scripts

Scripts can now access the current context via the local variable called
'imagej'.

Suggested by Lee Kamentsky.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Add convenience method ImageJ#getService(String)

In some scripting language (Javascript, I am looking at you!), it is
pretty difficult to get at the java.lang.Class instance of a Java class
give its name. In such a case, the method added by this commit comes in
real handy. Now, we can call

	service = imagej.getService("imagej.display.DisplayService");

instead of the quite unwieldy

	loader = Thread.currentThread().getContextClassLoader();
	clazz = loader.loadClass("imagej.display.DisplayService");
	service = imagej.getService(clazz);

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
ScriptService: Test the Javascript backend

Javascript should be available in every Java 1.6 compliant system,
so let's just test the ScriptService using that backend.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Add the top-level 'script' project with the 'script-beanshell' child

This commit may serve as example what it takes to add other Script
languages in the future.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Add the Beanshell scripting adapter

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
TODO: Scripting: add a tag for compiled languages

This interface serves as a duct-typing-interface to label
ScriptEngineFactory implementations to tell ImageJ2 that the language
actually needs compilation prior to execution.

It might still require a companion interface (to be done in the future)
for ScriptEngine to add the compile() method returning a list of compile
products. But maybe it is enough to add that method to CompiledLanguage;
we will see when porting Refresh_Javas to ImageJ2 ;-)

Note: the ScriptEngineFactory must be labeled so that e.g. the Script
Editor can decide even without a ScriptEngine instance that there need to
be different labels in the Run menu (Compile and Run, as opposed to Run).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Add a stub for the macro interpreter

For the moment, only getDimensions() is implemented. But it is a proof of
concept: this function disagrees with the syntax of most Java/C-like
languages as it does not use the values of the passed parameters, but
rather the variable names. It does not even complain when the variables
were not defined previously.

With that task done we will now implement all of the macro language's
built-in functions in the class imagej.script.MacroFunctions.

Of course, the way we do it will also give plugin programmers all the
macro functions for free, something which was not possible with IJ1.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
IJ_Macro: make sure javassist knows where Beanshell lives

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Start to implement macro functions

For the moment, most of the functions are stubs throwing Exceptions, but
the math-related functions are already implemented.

As a proof of concept, bitDepth() is also implemented.

For errors such as when there is no current image, but the currently
executed function requires one, it is nicer to tell the user what is
happening, so we also introduce a new exception, MacroException.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Implement a few more macro functions

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
wip: Implement the mouse & keyboard related macro functions

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