Developing plug-in programs
Contents
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.
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.
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-Figure 8) 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 6PlugInView.java -Mandatory source code for a view type of plug-in. See Figure 7;<br /> '''PlugInAlgorithm.java''' -Mandatory source code for an algorithm type of plug-in. See Figure 8.<br /> {| 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''' |- | <div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#000000"> 1 <span style="font-style: normal; text-decoration: none; text-transform: none; vertical-align: baseline">'''<font color="#000000">package</font>'''</span> gov.nih.mipav.plugins;<br /></font></div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#000000"> 2 <br /></font></div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#000000"> 3 <span style="font-style: normal; text-decoration: none; text-transform: none; vertical-align: baseline">'''<font color="#000000">import</font>'''</span> gov.nih.mipav.view.*;<br /></font></div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#000000"> 4 <br /></font></div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#000000"> 5 <span style="font-style: normal; text-decoration: none; text-transform: none; vertical-align: baseline">'''<font color="#000000">import</font>'''</span> java.awt.*;<br /></font></div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#000000"> 6 <br /></font></div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#000000"> 7 <span style="font-style: normal; text-decoration: none; text-transform: none; vertical-align: baseline">'''<font color="#000000">public interface</font>'''</span> PlugInFile <span style="font-style: normal; text-decoration: none; text-transform: none; vertical-align: baseline">'''<font color="#000000">extends</font>'''</span> PlugIn {<br /></font></div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#000000"> 8 <br /></font></div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#000000"> 9 <span style="font-style: normal; font-weight: normal; text-decoration: none; text-transform: none; vertical-align: baseline"><font color="#00ef07">/**</font></span><br /></font></div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#00ef07"> 10 <span style="font-style: normal; font-weight: normal; text-decoration: none; text-transform: none; vertical-align: baseline"><font color="#00ef07"> * run </font></span><br /></font></div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#00ef07"> 11 <span style="font-style: normal; font-weight: normal; text-decoration: none; text-transform: none; vertical-align: baseline"><font color="#00ef07"> * @param UI MIPAV main user interface.</font></span><br /></font></div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#00ef07"> 12 <span style="font-style: normal; font-weight: normal; text-decoration: none; text-transform: none; vertical-align: baseline"><font color="#00ef07"> */</font></span><br /></font></div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#000000"> 13 <span style="font-style: normal; text-decoration: none; text-transform: none; vertical-align: baseline">'''<font color="#000000">public void </font>'''</span>run(ViewUserInterface UI);<br /></font></div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#000000"> 14 }<br /></font></div> |} <br /></font>'''</div><div style="font-style: normal; margin-bottom: 2pt; margin-left: 0pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: 0pt; text-transform: none; vertical-align: baseline">'''<font color="#000000"> {| 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''' |- | <div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#000000"> 1 <span style="font-style: normal; text-decoration: none; text-transform: none; vertical-align: baseline">'''<font color="#000000">package</font>'''</span> gov.nih.mipav.plugins;<br /></font></div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#000000"> 2 <br /></font></div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#000000"> 3 <span style="font-style: normal; text-decoration: none; text-transform: none; vertical-align: baseline">'''<font color="#000000">import</font>'''</span> gov.nih.mipav.model.structures.*;<br /></font></div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#000000"> 4 <span style="font-style: normal; text-decoration: none; text-transform: none; vertical-align: baseline">'''<font color="#000000">import</font>'''</span> gov.nih.mipav.view.*;<br /></font></div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#000000"> 5 <br /></font></div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#000000"> 6 <span style="font-style: normal; text-decoration: none; text-transform: none; vertical-align: baseline">'''<font color="#000000">import</font>'''</span> java.awt.*;<br /></font></div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#000000"> 7 <br /></font></div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#000000"> 8 <span style="font-style: normal; text-decoration: none; text-transform: none; vertical-align: baseline">'''<font color="#000000">public interface</font>'''</span> PlugInView <span style="font-style: normal; text-decoration: none; text-transform: none; vertical-align: baseline">'''<font color="#000000">extends</font>'''</span> PlugIn {<br /></font></div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#000000"> 9 <br /></font></div><div style="font-style: normal; font-weight: normal; margin-bottom: 0pt; margin-left: 30pt; margin-right: 0pt; margin-top: 0pt; text-align: left; text-decoration: none; text-indent: -30pt; text-transform: none; vertical-align: baseline"><font color="#000000"> 10 /<span style="font-style: normal; font-weight: normal; text-decoration: none; text-transform: none; vertical-align: baseline"><font color="#00ef07"><nowiki>**</font></span>
</font></div>
}
Referencing filesTo reference a class, you must specify it using the Import keyword. For example, line 2 in PlugInFile.java imports the view functions (Figure 9).
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.
Lines of code that are dependent on plug-in typeTwo lines of code depend on the type of plug-in program being developed: 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 Figure 6) or PlugInView (line 8 in PlugInView.java, see Figure 7), respectively.
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).
Building and compiling plug-in programs To build a new plug-in program for MIPAV, you must first install a build environment, alter the path environment variable, and compile the plug-in files.
Installing a build environment 1 Download and install Java SE Development Kit (JDK), version 1.6 (JDK 6u2) <http://java.sun.com/javase/downloads/index.jsp>. Configuring the environment To configure your environment, you need to add two new variables-JAVA_HOME and ANT_HOME-and update the path variable in your system.
On Windows workstations 1 Click Start > Control Panel. The Control Panel window opens. 2 Double-click the System icon. The System Properties dialog box opens. 3 Click Advanced. The Advanced page of the System Properties dialog box appears. 4 Click Environment Variables. The Environment Variables dialog box opens. 5 Decide whether to add and edit variables in the User variables box or the System variables box based on which users should have access to the Java SDK and Ant. 6 Add the JAVA_HOME variable to your environment: a Click New. The New User Variable dialog box or the New System Variable dialog box opens. b Type JAVA_HOME in Variable name. c Type the path for the Java SDK on your computer (e.g., C:\Program Files\Java\jdk1.6.0_02) in Variable value. d Click OK. The JAVA_HOME variable appears in either the User variables box or System variables box as appropriate. 7 Add the ANT_HOME variable to your environment by doing the following: a Click New under either the User variables box or the System variables box. The New User Variable dialog box or the New System Variables dialog box opens as appropriate. b Type ANT_HOME in Variable name. c Type the path for the Ant on your computer (e.g., C:\Program Files\Ant\apache-ant-1.7.0) in Variable value. d Click OK. The ANT_HOME variable appears in either the User variables box or System variables box as appropriate. 8 Update either the PATH variable in the User variables box or the Path variable in the System variables box by doing the following: a Select the PATH variable in the User variables box, or select the Path variable in the System variables box. b Click Edit under the User variables box, or click Edit under the System variables box. Either the Edit User Variable dialog box or the Edit System Variable dialog box opens. c Type ;%JAVA_HOME%\bin;%ANT_HOME%\bin to the end of the PATH variable or to the end of the Path variable. d Click OK. The edited variable appears either in the User variables box or the System variables box. See also Figure 14. 9 Open a new terminal for the change to take effect by doing the following: a Click Start > Run. The Run dialog box opens. b Type cmd in Open, and click OK. A terminal window opens. 10 Retrieve the sample Ant build file (build.xml) from the MIPAV web site and place it in the same directory as the plug-in.java files you want to compile. 11 Alter the dir.mipav and dir.jdk properties within the build.xml to point to the directory where MIPAV and the SDK are installed, respectively. Note: Add and edit the variables in the User variables box if you want to limit the build environment to just yourself and no other users. Add and edit the variables in the Systems variables box to make the environment accessible to anyone who uses the workstation. Recommendation: Although it is possible to update the path variable in either the User variables box or System variables box, you should add the statement to the same box in which you added the JAVA_HOME and ANT_HOME variables.
See also: "Installing Ant" on <http://ant.apache.org/manual/index.html>. "JavaTM SE 6 Release Notes-Microsoft Windows Installation (32-bit)" on <http://java.sun.com/javase/6/webnotes/install/jdk/install-windows.html>.
On Linux or UNIX workstationsBash users should do the following: 1 Edit the file $HOME/.bash_profile and add lines similar to following: ANT_HOME=/path/to/apache-ant-1.6.3 JAVA_HOME=/path/to/j2sdk1.4.2_08 PATH=$PATH:$JAVA_HOME/bin:$ANT_HOME/bin export ANT_HOME export JAVA_HOME export PATH where ANT_HOME and JAVA_HOME are the paths where each application was installed. 2 Retrieve the sample Ant build file from the MIPAV web site, and place it in the same directory where the plug-in .java files you want to compile are located. 3 Alter the dir.mipav and dir.jdk properties within build.xml to point to the directory where MIPAV and the SDK are installed, respectively.
Build.xmlFigure 15 below displays the content of the build.xml file. build.xml is also available on the MIPAV web site <http://mipav.cit.nih.gov/documentation/presentations/plugins/build.xml>.
Compiling the plug-in files Note: You should keep back-up copies of the source and compiled files in case you need to update or change the plug-in. 1 Type ant compile on your workstation (e.g., cmd ant compile on Windows or xterm ant compile on UNIX platforms). The BUILD SUCCESSFUL message should appear at the end of the Ant output. 2 Copy the .class files that Ant produced into MIPAV's plug-in directory. On Windows platforms: C:\Documents and Settings\username\mipav\plugins On UNIX platforms: /home/username/mipav/plugins where username is the name of your account on the system. 3 Install the plug-in file. Select PlugIns > Install Plugin in the main MIPAV window. In the Install PlugIn dialog box, use the Browse buton to navigate to the \plugins directory . Select the plug-in and Press OK.
|