How to specify the location of a plugin in the MIPAV menu

From MIPAV
Revision as of 20:19, 13 June 2012 by Olga Vovk (Talk | contribs)

(diff) <previousrevision> | Latest revision (diff) | <nextrevision> (diff)
Jump to: navigation, search

By default, the location of a plugin within the MIPAV GUI is specified by the PlugIn interface that the main plugin class inherits. For example if "PlugInImageSubmit" inherits from "PlugInGeneric" it can be reached in the GUI via selecting Plugins->Generic->PlugInImageSubmit within the GUI. This page describes an optional method that allows you to modify that structure.

Creating a Category

Each plugin's location in the GUI is actually determined by the following field defined in every interface that is an instance of PlugIn.java:

public static final String[] CATEGORY = {"Heading 1", "Heading 2",...,"Heading n"};

Modifying this location requires the following. In your plugin class that inherits a sub-interface of PlugIn (such as PlugInAlgorithm, PlugInGeneric, PlugInFile, etc.), add the public static final String array named CATEGORY (case sensitive). Specify the hierarchical structure of your plugin's location using these headings.

Plugins that inherit PlugInAlgorithm

Note that no matter the structure specified, plugins that inherit from PlugInAlgorithm will not be displayed until an image is loaded. If this condition means one of your specified GUI headings is left empty, that heading will not be displayed. Once an image is loaded, these PlugInAlgorithms with their respective headings will be displayed.

Example

As PlugInGeneric

If you haven't already tried to write MIPAV plugins without access to MIPAV source code, start there. Once you're set up in Eclipse (or whatever IDE suits you), try the following code in a new PlugInDNAStruct.java:

import gov.nih.mipav.plugins.PlugInGeneric;

public class PlugInDNAStruct implements PlugInGeneric {

	public static final String[] CATEGORY = {"NHGRI", "Watson", "Gene info"};

	public void run() {
		System.out.println("Guanine<->Cytosine, Adenine<->Thymine");
	}
}

Now install this plugin. If you're using Eclipse, the associated .class file will be wherever your output path is (mipav/classes or mipav/bin most likely). Once installed, you'll notice you can now navigate to Plugins->NHGRI->Watson->Gene info->PlugInDNAStruct, which prints out the above text.

As PlugInAlgorithm

Again learning how to write MIPAV plugins without access to MIPAV source code is a good starting point. Create a PlugInInfluenzaStruct.java with the following code:

import java.awt.Frame;

import gov.nih.mipav.model.structures.ModelImage;
import gov.nih.mipav.plugins.PlugInAlgorithm;

public class PlugInInfluenzaStruct implements PlugInAlgorithm {

	public static final String[] CATEGORY = {"NIAID", "GenBank"};
	
	public void run(Frame parentFrame, ModelImage image) {
		System.out.println("Symptoms of flu include fever (usually high), headache, and extreme tiredness");
	}

}

Try installing this plugin without loading an image. You'll see that the structure of the plugin GUI has not changed. Load an image, and you'll notice that you can now navigate to Plugins->NIAID->GenBank->PlugInInfluenzaStruct. The above text will be printed as standard output (in Eclipse this shows up in the console window).

Closing Notes

If you've installed a plugin whose directory location within the GUI you'd like to change, you don't need to re-install the plugin. Like any change to the plugin, a change to the CATEGORY field will show up once you complile the plugin file.

Finally, this method is completely optional. Plugins may continue to be developed without adding a CATEGORY field.