Adding a Contextual Menu Item to a Layer Walkthrough

A contextual menu is a menu displayed when right-clicking an object. Layers have various contextual menu items. In this example, we will add a menu item in the contextual menu of a seismic layer. The action associated with this menu item will be a warning dialog box showing the current coordinates within that layer.

Reviewing Dependencies

The creation of a menu item requires two INT modules that are part of the INTViewer platform:

  • IntviewerCore
  • Viewer2D

See the list of INTViewer modules to load the INTViewer platform and for a description of each module.

Creating your module template using NetBeans wizard

  • Click File -> New Project
  • In the New Project wizard select NetBeans Modules from the Categories list and Module from the Projects list and click Next >
  • For Project Name, specify mydemolayercontextualmenuitemmodule
  • Select option Standalone Module and make sure to specify the INTViewer platform in the NetBeans Platform field.
  • Click Next > and specify com.mycompany.myviewer.mydemolayercontextualmenuitem for the Code Name Base and MyDemoLayerContextualMenuItemModule for the Module Display Name.
  • Check Generate XML Layer (if this option is not present, check the Registering the layer.xml file article)
  • Click on Finish

  • In the Projects tree view, you should see your project which includes a number of files that have been created for you

Configuring your Module

  • In the Projects tree, right click on the module MyDemoLayerContextualMenuItemModule and select Properties from the list.
  • Under Categories, select Libraries.
  • Select Java plaform JDK1.7 . If you don't see this option, you will need to install jdk1.7 and load it into NetBeans using option Tools->Java Platforms
  • Click on the Add button next to Module Dependencies
  • In the list, select IntviewerCore, Viewer2D and click OK.
  • Click OK in Project Properties Dialog

Creating an Action class

    • In the Projects tree, right click on the module MyDemoLayerContextualMenuItemModule and select New -> Java Class... from the list.
    • Enter DemoLayerContextualMenuItemAction as Class Name and select com.mycompany.myviewer.mydemolayercontextualmenuitem as Package.

    • Make this class extend AbstractLayerAction
    • Automatically add an import for AbstractLayerAction

    • Automatically create the skeleton of required methods for this class

    • Customize the performAction method

This requires the import of com.interactive.intviewerapi.util.DialogManager. More details about dialog boxes are available.

  • Right-click Insert Code -> Constructor to override the constructor
  • Enter a display name for the menu item (Show XY Position in this example)

You can download the DemoLayerContextualMenuItemAction.java file from the attachments at the bottom this page.

Customizing the layer.xml file

Modify the layer.xml file as follow:

In this layer.xml file:

    • <folder name="LayerActions"> indicates the start of the list of layer actions available in the module (do not change this line)
    • <folder name="ViewerSeismicLayer"> indicates the type of layer the contextual menu applies to
  • <file name="com-mycompany-myviewer-mydemolayercontextualmenuitem-DemoLayerContextualMenyItemAction.instance"> indicates the fully qualified name of the associated action class
  • <attr name="position" intvalue="0"/> indicates the position of the menu item in the contextual menu

You can download the layer.xml file from the attachments at the bottom this page. See layer actions in the references for a list of available layer types

Running your Contextual Menu

    • Click the green arrow in the toolbar.
    • Load a seismic X-Section using File -> Open Data in New X-Section Window -> Seismic...
    • Open a seismic data file in the file dialog box
    • Right click the layer
  • Select Show XY Position...
  • The position is displayed

More information about contextual menus and layers is available in the references.