Difference between revisions of "Scripting with BeanShell"

From OpenJUMP Wiki
Jump to navigation Jump to search
Line 45: Line 45:
 
* [[Beanshell:Fill in a JUMP column]]
 
* [[Beanshell:Fill in a JUMP column]]
 
* [[Beanshell:Setting North Arrow options]]
 
* [[Beanshell:Setting North Arrow options]]
 +
* [[Beanshell:Setting Scale Bar options]]

Revision as of 16:30, 17 February 2010

What is BeanShell?

BeanShell is a small, free, embeddable Java source interpreter with object scripting language features, written in Java. BeanShell dynamically executes standard Java syntax and extends it with common scripting conveniences such as loose types, commands, and method closures like those in Perl and JavaScript.

In the context of Jump, BeanShell enables the automation of repetative tasks or to accomplish tasks that are not possible using the GUI without the need for plugin modules or modification of the application source code.

See http://www.beanshell.org/ for more information on BeanShell.

BeanShell in OpenJUMP

To open the BeanShell scripting window select the following menu option:

View -> BeanShell...

It is a good idea to surround all your scripts in a set of braces. I.e.

{
  script...
}


In BeanShell you may access JavaBean properties as if they were fields. For example wc.layerManager is the same as wc.getLayerManager().

There is no facility to save and load a script. If you plan to reuse your scripts, develop the script in a text editor and then paste into the BeanShell window as needed.

If you want to write Beanshell scripts you can also use the Beanshell-Editor-JUMP Plugin that has been written by Michael Michaud.

JUMP BeanShell examples

Some of the following scripts are not very useful. Instead they are indented as examples which can be easily adapted to perform useful tasks.