The first part of this page will describe how one can make its own plugins for JUMP/OpenJUMP. In part B we will outline how the plugins are used. Either internally from Eclipse using the workbench-properties.xml file or externally as jar for distributing.
First of all: To make coding easier you should use a Integrated Developement Environment (IDE) like Eclipse or NetBeans (of course you can also use commercial IDEs). Such an IDE shows you errors in your code already during programming and has nice properties like proposing you commands or paths.
Now have a look here: FAQ OpenJump and Eclipse
Note: If you use Eclipse for the first time, then have a look on this very good tutorial on how to use the Eclipse IDE: Eclipse Tutorial
Finally lets start.. :)
If you have installed Eclipse see also How to make your plugin in ECLIPSE
Example/* * created on 04.10.2005 * last modified: 05.10.2005 comments added * * author: sstein * **/ package ch.unizh.geo.degen; import com.vividsolutions.jump.workbench.WorkbenchContext; import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn; import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory; import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck; import com.vividsolutions.jump.workbench.plugin.PlugInContext; import com.vividsolutions.jump.workbench.ui.plugin.FeatureInstaller; /** * @description: * testplugin for jump<p> * shows hello world - window in Jump * * @author sstein * */ public class HelloWorldPlugIn extends AbstractPlugIn{ public HelloWorldPlugIn() { // empty constructor } public void initialize(PlugInContext context) throws Exception { FeatureInstaller featureInstaller = new FeatureInstaller(context.getWorkbenchContext()); featureInstaller.addMainMenuItem( this, //exe new String[] {"View"}, //menu path this.getName(), //name methode .getName recieved by AbstractPlugIn false, //checkbox null, //icon createEnableCheck(context.getWorkbenchContext())); //enable check } public static MultiEnableCheck createEnableCheck(WorkbenchContext workbenchContext) { EnableCheckFactory checkFactory = new EnableCheckFactory(workbenchContext); return new MultiEnableCheck() .add(checkFactory.createWindowWithLayerNamePanelMustBeActiveCheck()); } /** * Action on menu item selection: * creates doc to show */ public boolean execute(PlugInContext context) throws Exception{ context.getWorkbenchFrame().getOutputFrame().createNewDocument(); context.getWorkbenchFrame().getOutputFrame().addText("Hello, World!"); context.getWorkbenchFrame().getOutputFrame().surface(); return true; } }
Another example, that shows how to create buffers from features in a layer has been posted here: Example Plugin For Buffering Features in a Layer
This option is a bad choice for finding errors, but necessary to deploy our work.
How does such an Extension class look like:
/* * created on 04.10.2005 * last modified: * * author: sstein * *************************************************/ package ch.unizh.geo.degen; import com.vividsolutions.jump.workbench.plugin.Extension; import com.vividsolutions.jump.workbench.plugin.PlugInContext; /** * @description * - this class loads the PlugIn into Jump <p> * - class has to be called "Extension" on the end of classname * to use the PlugIn in Jump * * @author sstein */ public class HelloWorldExtension extends Extension{ /** * calls PlugIn using class method xplugin.initialize() */ public void configure(PlugInContext context) throws Exception{ new HelloWorldPlugIn().initialize(context); } }
This option is a good choice for debugging errors but not for deployment.
note: for this version is might be good to have the original openjump sources in a project (since one can better trace errors and has good examples on programming). The Jump sources can be obtained from the jump or openjump CVS or as zip files. If you create your own Openjump project, don’t forget to include the libraries into your project (using the “Buildpath” properties). Further you have to create a dependency of the Helloi18 project on the new Jump (OpenJump) project, which can be also done in the project properties of Helloi18
the examples above use the parent class AbstractPlugIn which has disadvatanges for long computations. For such a case use implements ThreadedPlugIn. Here also a monitor can be used to send messages to the user. Apart from that a second method run() has to be implemented which contains the now the time consuming code while execute() should contain dialogs for initial interatcion. (I will make this clearer in future – hopefully)
Please don’t forget to document your plugin. I’ve done a template that can be downloaded here: http://sourceforge.net/project/showfiles.php?group_id=118054&package_id=209987
have fun,
Stefan (sstein)