Developing plug-in programs

From MIPAV
Jump to: navigation, search

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.

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

To avoid compatibility problems when you create a plug-in program, use the same version of Java that was used to create MIPAV. To determine which version of Java the latest version of MIPAV uses, select Help > JVNM Information in the MIPAV window. The About System dialog box opens. See Figure 5.
Figure 5. About System dialog box
MIPAV API JVM Version.jpg

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):

PlugInFile.java-Mandatory source code for a file type of plug-in. See Figure 6;
PlugInView.java-Mandatory source code for a view type of plug-in. See Figure 7;
PlugInAlgorithm.java-Mandatory source code for an algorithm type of plug-in. See Figure 8.
{| border="1" cellpadding="5" |+
Figure 6. Mandatory code for a file type of plug-in (PlugInFile.java). For readability purposes, keywords in all code reproduced in this chapter appear in bold, and comments appear in green type
|- |
1 package gov.nih.mipav.plugins;
2
3 import gov.nih.mipav.view.*;
4
5 import java.awt.*;
6
7 public interface PlugInFile extends PlugIn {
8
9 /**
10 * run
11 * @param UI MIPAV main user interface.
12 */
13 public void run(ViewUserInterface UI);
14 }
|}
{| border="1" cellpadding="5" |+
Figure 7. Mandatory code for a view type of plug-in (PlugInView.java). For readability purposes, keywords in all code reproduced in this chapter appear in bold, and comments appear in green type
|- |
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 PlugInView 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
15 * dialogs.
16 * @param image model of the MIPAV image.
17 * @see ModelImage
18 * @see ViewJFrameImage
19 *
20 */
21 public void run(ViewUserInterface UI, Frame parentFrame, ModelImage image);
22 }
|} {| border="1" cellpadding="5" |+
Figure 8. Mandatory code for an algorithm type of plug-in (PlugInAlgorithm.java). For readability purposes, keywords in all code reproduced in this chapter appear in bold, and comments appear in green type
|- |
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
9 public interface PlugInAlgorithm extends PlugIn {
10
11 /**
12 * run
13 * @param UI MIPAV main user interface.
14 * @param parentFrame frame that displays the MIPAV image.
15 * Can be used as a parent frame when building
16 * dialogs.
17 * @param image model of the MIPAV image.
18 * @see ModelImage
19 * @see ViewJFrameImage
20 *
21 */
22 public void run(ViewUserInterface UI, Frame parentFrame, ModelImage image);
23
24
25 }
26
|}

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).

Figure 9. Importing the view functions in PlugInFile.java
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).

Figure 10. Importing model structures, view functions, and [java.awt]

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:

Windows
c:\Documents and Settings\<user ID>\mipav\plugins
UNIX
/user/<user ID>/mipav/plugins

An example of this appears in the first line of Figure 11.

Figure 11. Example of placing referenced files in the \$MIPAV\plugins directory

package plugins; // added to plugins pkg. so PlugInSampleStub may
// call it.

Lines of code that are dependent on plug-in type

Two lines of code depend on the type of plug-in program being developed:
Declaration
Parameters for the run method
Declaration
The declaration used in a plug-in depends on the type of plug-in being developed. For instance, in line 9 in PlugInAlgorithm.java (Figure 8), the combination of words "public interface PlugInAlgorithm" indicates that the plug-in in an Algorithm. For File or View types of plug-ins, simply replace PlugInAlgorithm with PlugInFile (line 7 in PlugInFile.java, see [MIPAV_Plugins.html#1465012 Figure 310]) or PlugInView (line 8 in PlugInView.java, see Figure 7), respectively.

Table 4. Declarations dependent on type of plug-in

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
The parameters for the run method also depend on the plug-in type. Compare the run methods used in PlugInFile.java (Figure 6), PlugInView.java (Figure 7), and PlugInAlgorithm.java (Figure 8).

Table 5. Parameters for run methods dependent on type of plug-in

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);

Figure 12. PlugInAlgorithm.java. For readability purposes, keywords in all code reproduced in this chapter appear in bold, and comments appear in green type

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

See also: