Difference between revisions of "Writing MIPAV plugins without MIPAV source code"

From MIPAV
Jump to: navigation, search
(Installing the plugin)
(Installing the plugin)
Line 112: Line 112:
 
| 1
 
| 1
 
| Start MIPAV using the method shown in [[#Running MIPAV with a sample plugin within Eclipse |Running MIPAV within Eclipse]].  If that's already set up, start MIPAV and navigate to Plugins->Install Plugin.  The dialog on the right will be displayed.  Once you press the Browse button, find the folder where the mipav-plugin project resides.  This should be inside the default workspace folder you noted earlier.  Once found, go to click on the mipav-plugin/classes folder.  You should see the following classes:  
 
| Start MIPAV using the method shown in [[#Running MIPAV with a sample plugin within Eclipse |Running MIPAV within Eclipse]].  If that's already set up, start MIPAV and navigate to Plugins->Install Plugin.  The dialog on the right will be displayed.  Once you press the Browse button, find the folder where the mipav-plugin project resides.  This should be inside the default workspace folder you noted earlier.  Once found, go to click on the mipav-plugin/classes folder.  You should see the following classes:  
* [http://dcb.cit.nih.gov/~senseneyj/code/PlugInDialogNewGeneric2.java PlugInDialogNewGeneric2.java]
+
* PlugInDialogNewGeneric2.class
* [http://dcb.cit.nih.gov/~senseneyj/code/PlugInAlgorithmNewGeneric2.java PlugInAlgorithmNewGeneric2.java]
+
* PlugInAlgorithmNewGeneric2.class
* [http://dcb.cit.nih.gov/~senseneyj/code/PlugInNewGeneric2.java PlugInNewGeneric2.java]
+
* PlugInNewGeneric2.class
  
Move PlugInNewGeneric2.class to the right column as shown, and then press Install.   
+
Move '''only''' PlugInNewGeneric2.class to the right column as shown, and then press Install.   
 
| [[Image:installInterface.png|thumb|500px]]
 
| [[Image:installInterface.png|thumb|500px]]
 
|-
 
|-

Revision as of 21:01, 4 August 2010

You can use Eclipse to develop plugins for MIPAV without access to the MIPAV source code.

Requirements

First, if you do not have an IDE like Eclipse, see Getting Started with Eclipse. If you already have Eclipse and Java, here is all you'll need:

Installation

Installation should be completed in the following order.

Installing MIPAV

Mipav installation is quickly completed by following the prompts. Note where you installed MIPAV, in Windows the default is in the folder C:\Program Files\mipav

Adding MIPAV JRE

Though not required, the MIPAV JRE has many features you may find useful when writing your own plugins for MIPAV.

If you would like to use the JRE bundled with an installed version of MIPAV, navigate to the following location: Window -> Preferences -> Java -> Installed JREs. In this panel you can add the MIPAV JRE using the "Add.." button. Once you have added the MIPAV JRE to Eclipse, see step 4 of Building the Eclipse Project.

Building the Eclipse project

Steps for building MIPAV.
Step Text Picture
1 Start Eclipse. A dialog will ask you where the default workspace is located. Note the location it specifies and then click OK. With Eclipse started, click File, then New, then Java Project.
New Project.jpg
2 Name your project mipav-plugin. Ensure that the button next to "Create seperate folders for source and class files" is checked. Click the Next button.

On the Source tab, change the Default output folder tab to "mipav-plugin/classes"

Java Settings.jpg
3 On the libraries tab, click "Add External Class Folder" where you'll want to navigate to where you installed MIPAV. Select that folder.
External class folder.jpg
4 Also on the libraries tab, click Add External JARs and then add all the files from the following directories:
  • mipav/lib/*
  • mipav/lib/jaxp/*
  • mipav/help/mipav_help.jar
  • mipav/InsightToolkit/lib/InsightToolkit/InsightToolkit.jar

If you would like to use the JRE that is bundled with an installed version of MIPAV, select the JRE System Library in this panel and click Edit. If you previously added the MIPAV JRE to this list using the Installing Java instructions, you can now select that MIPAV bundled JRE for compiling.

AllLibraries.jpg
External JARS.jpg

Click Finish when complete. A new project called mipav-plugin should appear. You're now ready to run MIPAV.

Running MIPAV with a sample plugin within Eclipse

Running MIPAV.
Step Text Picture
1 To make sure you've set everything up correctly, we'll try to run MIPAV inside of Eclipse. Navigate to Run, then Run Configurations... on the control panel. On the dialog box that opens, highlight Java Application, and then click the New Launch Configuration on the left. Fill out the Name and Project fields with the phrase "mipav-plugin" To fill in the Main Class, click the Search... button. Search for the name "MipavMain" If found, great! Otherwise go to troubleshooting.
MipavMain.jpg
2 Click on the arguments tab. In the VM arguments box, put the following phrase "-Xms800M -Xmx800M" This specifies how many megabytes Java has available to run MIPAV. If your computer has more or less, feel free to adjust the numbers accordingly.
VmArg.jpg
3 When finished, click Run. If MIPAV starts, you're ready to start developing plugins. If not, go to troubleshooting.
Splash.png

Importing the plugin

Import.jpg


For now download these three files to a convenient location:

Import these files into Eclipse using the dialog from File, then Import.





Installing the plugin

Installing the plugin.
Step Text Picture
1 Start MIPAV using the method shown in Running MIPAV within Eclipse. If that's already set up, start MIPAV and navigate to Plugins->Install Plugin. The dialog on the right will be displayed. Once you press the Browse button, find the folder where the mipav-plugin project resides. This should be inside the default workspace folder you noted earlier. Once found, go to click on the mipav-plugin/classes folder. You should see the following classes:
  • PlugInDialogNewGeneric2.class
  • PlugInAlgorithmNewGeneric2.class
  • PlugInNewGeneric2.class

Move only PlugInNewGeneric2.class to the right column as shown, and then press Install.

InstallInterface.png
2 A confirmation message will be displayed as shown.
Confirm.png
3 Now open an image using MIPAV. You can now click on Plugs->Algorithms->PlugInNewGeneric2.
PluginOpen.png
4 This plugin opens a blank dialog box with working OK and Cancel buttons.
UpdatedPlugin.png

Modifying the plugin

You'll see the the OK and Cancel buttons print those words to the Console window in Eclipse. These words can be modified on lines X and Y of PlugInDialogNewGeneric2. Note that because we loaded the plugin from the classes folder, the plugin is automatically updated when you make changes to the code. When you want to test a new version of your plugin, simply restart MIPAV and then run your plugin.

Writing a plugin

Writing a plugin, including accessing the MIPAV API, the structure of plugins, and accessing MIPAV help is covered extensively in the following PDF document or this powerpoint presentation.

Attaching the MIPAV Source

If you have a rare copy of the MIPAV source code, this can be integrated into your plugin development. You can also integrate the on-line Java documentation. Right click on the mipav folder in the referenced libraries as shown, and then click on Properties. Under Java Source Attachment, you can select the external file or folder that contains the rare MIPAV source, downloaded Javadoc, or on-line Javadoc.

Troubleshooting

What could have possibly gone wrong? Please e-mail SenseneyJ@mail.nih.gov so your problem can be fixed and added to this page. You could also leave a comment on the talk page.

Helpful Links

  • The new version of the generic plugin is scriptable! Go here to see an example of successful script recording and here to see its execution.