Creating a self-contained plug-in frame

Jump to: navigation, search

You can create a self-contained plug-in that does not rely on the default MIPAV user interface. When running, this type of plug-in hides MIPAV and displays its own image(s) with the action and algorithm handling specific to its frame.

To create a self-contained plug-in:

1 Extend ViewJFrameImage, as this will allow the plug-in to use a wide-range of ViewJFrameImage and ViewJFrameBase specific functions for storing and displaying ModelImages. These functions include, for example, the image and on-screen buffers, menu and toolbar builders, etc.
2 Override the ViewOpenFrameInterface openFrame(ModelImage) function. This handles the creation of a new PlugIn frame based on whether a result image is created within the dialog of an algorithm. For example, when the user runs an algorithm and selects the destination New Image rather than Replace Image, a new frame will be created with the result of the algorithm. To set all algorithms to work in place and disallow creating of new frames, call ViewUserInterface setForceInPlace(true) function, which tells the dialogs that all algorithms must work in place.
3 Create an init() function, where the PlugIn frame is layout and components will be initialized.
4 In the init() function, several methods should be called:
Call initLUT() for the ModelImage look-up table,
Call initResolutions() for the ModelImage resolutions,
Call initZoom() for the frame's zoom factor,
initComponentImage() creates a displayable ComponentImage,
initExtentsVariables() initializes z-slice and time-slice positions.
5 To add toolbars and menus to your plug-in, within init(), create a ViewControlsImage object, and then
Call buildToolBar() to create pre-defined toolbars for image, VOI, paint, and scripting controls;
Or call buildSimpleToolBar and pass Vector<CustomUIBuilder.UIParams> using addCustomToolBar() for each of the Vectors.

Pre-defined button and menu parameters are located in CustomUIBuilder. Pre-defined as well as the user-defined UIParams can be added and used in both toolbars and menus.

6 Create ViewMenuBar. This allows you to add either pre-defined or UIParam menus. The Vector from above (used on the custom toolbar) can be passed into the ViewMenuBar makeCustomMenu() function. ViewMenuBar also has pre-defined menus for a file, help, image, look-up tables, etc.
7 Finally, the init() function should handle the container for the ViewJComponentEditImage created from initComponentImage(). The component image should be added to a JScrollPane to accommodate the variable size of the display.
8 Override the actionPerformed() method to catch (handle) ActionEvents. If a custom toolbar and (or) menu bar was created using a Vector of UIParams, the UIParam contains the action event for each button and (or) menu item.
9 Override the componentResized() method to properly handle (or ignore) the resizing of the plug-in frame. Using the ViewJFrameImage componentResized function would likely create unwanted behavior as the layout of the plug-in is different from MIPAV's standard ViewJFrameImage.
10 Create a basic PlugInGeneric class that will be called as a command-line argument. This class should have the ability to choose/open a ModelImage using the FileIO.readImage() method. The self-contained plug-in frame should be instantiated within this class by passing in the ModelImage.
11 When running MIPAV, pass in the arguments
-hide -p [YourGenericPlugin]. The -hide flag tells MIPAV not to bring up the User Interface and MessageFrame, while the -p flag tells which plug-in to run. See Figure 17.

Figure 17. The arguments for running the self-contained plug-in frame.

MIPAV SimpleImageFramePlugInRun.jpg


The ViewJFrameMessage Data and Debug tabs (as well as others) can be added to the plug-in frame by retrieving the JTabbedPane through ViewUserInterface.getReference().getMessageFrame().getTabbedPane(). This enables the Data and Debug message output to be displayed outside of the separate message frame that accompanies MIPAV.

See also: Figure 18 and Figure 19.

Figure 18. A part of the code for The full code can be found in "Examples of MIPAV plug-ins", Figure 28.

1 import java.awt.*;
2 import java.awt.event.*;
3 import java.util.Vector;
5 import javax.swing.*;
6 import gov.nih.mipav.model.file.FileInfoBase;
7 import gov.nih.mipav.model.structures.ModelImage;
8 import gov.nih.mipav.model.structures.ModelLUT;
9 import gov.nih.mipav.model.structures.ModelRGB;
10 import gov.nih.mipav.model.structures.VOI;
11 import gov.nih.mipav.view.*;
12 import gov.nih.mipav.view.dialogs.*;
15 /**
16 * Plugin example class for creating a simple, self-contained frame that extends ViewJFrame Image
17 * Contains a subset of the VOI functions, as well as the message frame contained within the frame itself
18 * @author linkb
19 *
20 */
21 public class PlugInDialogImageVOIDisplay extends ViewJFrameImage implements MouseListener, AdjustmentListener {
25 //~ Constructors ---------------------------------------------------------------------------------------------------
27 /**
28 * Default constructor
29 */
30 public PlugInDialogImageVOIDisplay(ModelImage image) {
31 super(image, null, null, false, false);
32 init();
33 }
36 /**
37 * ViewOpenFrameInterface function for opening a model image (result) into a new frame
38 */
39 public PlugInDialogImageVOIDisplay openFrame(ModelImage image) {
40 return new PlugInDialogImageVOIDisplay(image);
41 }

Figure 19. The Simple Image Frame plug-in opens the MIPAV independent image frame for a selected image. (a) The image frame contains the following elements of the interface - the VOI toolbar, image slice slider and menu bar. The Gradient Magnitude algorithm was called from the menu and applied to the image. (b) The result image opened in a new image frame.

MIPAV SimpleImageFramePlugIn.jpg

Next: Examples of MIPAV plug-ins

See also: