Difference between revisions of "How to specify the script name of a plugin"

From MIPAV
Jump to: navigation, search
(first page)
 
Line 91: Line 91:
  
 
==Closing Notes==
 
==Closing Notes==
 +
 
If you're using the instructions used in how to [Writing MIPAV plugins without access to MIPAV source code|write MIPAV plugins without access to MIPAV source code]], you won't need to re-install the plugin after you change a script name; however, it's not a bad idea.  In general, changing the script name will require you to reinstall the plugin.
 
If you're using the instructions used in how to [Writing MIPAV plugins without access to MIPAV source code|write MIPAV plugins without access to MIPAV source code]], you won't need to re-install the plugin after you change a script name; however, it's not a bad idea.  In general, changing the script name will require you to reinstall the plugin.
  
 
Finally, this method is completely optional.  Plugins may continue to be developed without adding a SCRIPT_PREFIX field.
 
Finally, this method is completely optional.  Plugins may continue to be developed without adding a SCRIPT_PREFIX field.

Revision as of 15:17, 29 March 2016

All scriptable plugins are manipulated by MIPAV's script interface through whichever class extends JDialogScriptableBase. When this class is not in the default package, the script interface refers to this plugin by its full name. This page shows you how to shorten that name by describing an optional method to modify the way MIPAV's script recorder refers to your plugin during script recording and running.

Creating a Script Name

Each plugin's sript name is normally the full package of the class that extends JDialogScriptableBase. You can modify this behavior by adding the following SCRIPT_PREFIX field to the class that implements the interface PlugIn or a sub-interface of PlugIn:

public static final String SCRIPT_PREFIX = "my.package.name.PlugInDialog";

Its important to see that this field is added to the class that implements the interface PlugIn or a sub-interface of PlugIn(such as PlugInAlgorithm, PlugInGeneric, PlugInFile, etc.). That may or may not be the same class as the class that extends JDialogScriptableBase. Some examples are provided below.

Example

PlugInDNAStruct

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 java.awt.Frame;

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

import gov.nih.nihgri.PlugInDialogDNAStruct;

public class PlugInDNAStruct implements PlugInAlgorithm {

	public static final String SCRIPT_PREFIX = "gov.nih.nihgri.PlugInDialog";

	public void run(Frame parentFrame, ModelImage image) {
		System.out.println("This plugin is not being run as a script.");
                new PluginDialogDNAStruct(parentFrame, image);
	}
}

PlugInDialogDNAStruct

Now create a file called PlugInDialogDNAStruct.java in the package gov.nih.nihgri. Use the following as your source code:

package gov.nih.nihgri;

import gov.nih.mipav.model.algorithms.AlgorithmInterface;
import gov.nih.mipav.view.dialogs.JDialogScriptableBase;

public class PlugInDialogDNAStruct extends JDialogScriptableBase implements AlgorithmInterface {

    /**
     * Empty constructor needed for dynamic instantiation (used during scripting).
     */
    public PlugInDialogHistogram() { 
        System.out.println("This plugin is being run as a script.");
    }

    /**
     * Creates new dialog to enter parameters for PlugInAlgorithmDNAStruct.
     *
     * @param  theParentFrame  Parent frame
     * @param  im              Source image
     */
    public PlugInDialogHistogram(Frame theParentFrame, ModelImage im) {
        super(theParentFrame, false);
        System.out.println("This plugin is not being run as a script.");
    }

    public void algorithmPerformed(AlgorithmBase algorithm) {

    }

The first constructor will be called when this plugin is run as a script, the second constructor will be run when this plugin is called through the MIPAV user interface.

Installation

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->Algorithm->PlugInDNAStruct, which prints out:

This plugin is not being run as a script.
This plugin is not being run as a script.

Creating a script

Create a script for this plugin using the directions at Creating a script. You'll see that the script window contains the shortened name of the plugin, "DNAStruct" Once you save the script, try running it.

Running a script

Try running the script using the directions included at Running a script. Again, the short name of the plugin shows up in this interface.

Closing Notes

If you're using the instructions used in how to [Writing MIPAV plugins without access to MIPAV source code|write MIPAV plugins without access to MIPAV source code]], you won't need to re-install the plugin after you change a script name; however, it's not a bad idea. In general, changing the script name will require you to reinstall the plugin.

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