Developing plug-in programs
MIPAV provides the following classes for developing plug-in programs:
PlugInAlgorithm.class
PlugInFile.class
PlugInView.class
Plug-in programs are developed in the same way as the other Java programs are. The high-level steps of creating plug-ins follow.
1 Determining the type of plug-in program -Before you begin to write the code for the plug-in, determine the plug-in type: algorithm, file, or view. Refer to "Determining the type of plug-in program".
2 Determining which version of Java to use -Detailed instructions appear in "Determining which version of Java to use" and Figure 5.
3 Writing the source code -Some lines of code must appear in the source code so that the plug-in program interfaces correctly with MIPAV. Refer to "Writing the source code".
4 Building and compiling plug-in programs -You should keep back-up copies of the source and compiled files in case you need to update or change plug-in programs. See "Building and compiling plug-in programs".
5 Creating a self-contained plug-in frame< -A self-contained plug-in is a Java application that does not rely on the default MIPAV user-interface, but, instead, hides MIPAV and display its own image(s) with action/algorithm handling specific to its frame. See "Creating a self-contained plug-in frame".
6 Installing plug-in programs -This section explains how to install plug-in programs. Refer to "Installing plug-in programs".
7 Sample plug-in programs -This section provides a couple of examples of MIPAV plug-ins. Refer to "Examples of MIPAV plug-ins".
Note: This section does not explain how to write a Java program; however, it explains what must be incorporated in the plug-in program so that it correctly interfaces with the MIPAV application.
Contents
Determining the type of plug-in program
The first step of creating a plug-in program is to determine the type you want to create, which depends on its purpose. As mentioned earlier, MIPAV plug-in programs can be of the algorithm, file, or view type. However, most users want MIPAV to perform very specific additional functions on images. Since these functions may not be currently available in MIPAV, users choose to add the functions by developing the algorithm type of plug-in program.
Determining which version of Java to use
The first line in the About System dialog box indicates the version of Java that was used to develop MIPAV. To obtain the correct version of Java, go to the following web site: <http://www.java.sun.com>
Writing the source code
Note: In this section, \$MIPAV is used to represent the MIPAV user directory, which is the directory where MIPAV is installed. The user directory is indicated in the About System dialog box. In the MIPAV main window, select Help > JVM Information to view the About System dialog box.
When you develop a plug-in for MIPAV, several lines must be present in the code so that it executes properly. Some mandatory code should be included in all plug-in files. Other code might change depending on the plug-in type.
Including mandatory code
The next three figures (Figure 6- Figure8) show the mandatory source code needed for creating a file type of plug-in, a view type of plug-in, and an algorithm type of plug-in. The plug-ins directory of MIPAV includes these three files (e.g. C:\[$MIPAV]\mipav\plugins):
Referencing files
To reference a class, you must specify it using the Import keyword. For example, line 2 in PlugInFile.java imports the view functions (Figure 9).
import gov.nih.mipav.view.*;
|
Lines 3, 4, and 6 in the PlugInView.java and PlugInAlgorithm.java files import the model structures, view functions, and the basic Java package that has GUI functions (Figure 10).
import gov.nih.mipav.model.structures.*; // MIPAV package where main // MIPAV structures are located (e.g., model image) import gov.nih.mipav.view.*; Â import java.awt.*
|
If you reference a class, you must include it in the plug-in package so that it can be called from the main file. After you write and compile, you must now install files in the user or home directory:
An example of this appears in the first line of Figure 11.
package plugins; // added to plugins pkg. so PlugInSampleStub may // call it.
|
Lines of code that are dependent on plug-in type
Declaration
Type of plug-in
|
Declaration
|
---|---|
File
|
public interface PlugInFile extends PlugIn (
|
View
|
public interface PlugInView extends PlugIn (
|
Algorithm
|
public interface PlugInAlgorithm extends PlugIn (
|
Parameters for the run method
Type of plug-in
|
Parameters for the run method
|
---|---|
File
|
public void run(ViewUserInterface UI);
|
View
|
public void run(ViewUserInterface UI, Frame parentFrame, ModelImage image);
|
Algorithm
|
public void run(ViewUserInterface UI, Frame parentFrame, ModelImage image);
|
1 package gov.nih.mipav.plugins; 2 3 import gov.nih.mipav.model structures.*; 4 import gov.nih.mipav.view.*; 5 6 import java.awt *; 7 8 public interface PlugInAlgorithm extends PlugIn { 9 10 /** 11 * run 12 * @param UI MIPAV main user interface. 13 * @param parentFrame Frame that displays the MIPAV image. 14 * Can be used as a parent frame when building dialogs. 15 * @param image Model of the MIPAV image. 16 * @see ModelImage 17 * @see ViewJFrameImage 18 */ 19 public void run(ViewUserInterface UI, Frame parentFrame, ModelImage image;) 20 21 }
|
Next: Building and compiling plug-in programs