Creating your own 2D Layer
This tutorial will teach you how to write your own implementation of a 2D layer.
Create your module template in NetBeans
Create your module template in NetBeans
- 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 MyHorizonLayer
- Select option Standalone Module and make sure to specify the INTViewer platform in the NetBeans Platform field.
- Click Next > and specify com.mycompany.myviewer.myhorizonlayer for the Code Name Base and MyHorizonLayerModule for the Module Display Name.
- Click the Generate XML Layer checkbox (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
Configuring your Module
- In the Projects tree, right click on the module MyHorizonLayerModule and select Properties from the list.
- Under Categories, select Libraries.
- Select Java plaform JDK1.7 or your current version.
- Click on the Add button next to Module Dependencies
- In the list, select AllDeps, IntviewerCore, JCarnacProWrapper, Lookup, Utilities API, Viewer2D and click OK.
- Click OK in Project Properties Dialog
Create your HorizonLayer class
Create your HorizonLayer class
- In the Projects tree, right click on the module MyHorizonLayerModule and select New -> Java Class... from the list.
- Enter HorizonLayer as Class Name and select com.mycompany.myviewer.myhorizonlayer as Package.
- Click Finish.
- In the class editor, indicate that this HorizonLayer class extends AbstractLayer2D.
- Right-click in the class editor and select "Fix Imports". This will automatically import the abstract class AbstractLayer2D.
- On the line with the class definition, click on the little light bulb with the red exclamation mark.
- Click on "Implement all abstract methods" to make skeletons for all the methods.
- Comment out all the "throw new UnsupportedOperationException..." to make them dummy methods.
- For methods that require a return value, simply return "null" for right now.
- Add a constructor to override the AbstractLayer2D constructor.
- Be sure to fix imports to import ILayeredWindow.
Create a New Horizon Layer action
Create a New Horizon Layer action
- Now we will create a user action that triggers the creation of a new horizon.
- In the Projects tree, right click on the module MyHorizonLayerModule and select New -> Action... from the list.
- Make sure the radio button "Always Enabled" is clicked, and click Next >
- In the GUI registration, make sure it is in the File category.
- Then change the Menu selection to "File" and Position to "<separator> - HERE". Click Next >
- In practice, this screen is how you specify where and what will trigger your action.
- For the class name write "NewHorizonLayerAction," and the display name put "New Horizon Layer." Click Finish.
- If you run the program now you will see the action is successfully wired up but does not actually do anything when clicked on.
- Now we will code up an action to create a horizon layer. Since horizon layers only make sense in relation to a seismic layer, we need to know which seismic layer has been selected, if at all. To do this, we will need to use a class called GlobalSelection.
- Edit NewHorizonLayerAction.java to contain the following code. You may have to Fix Imports or add the Seismic2D library through the Module Properties like before.
- Now click on the green arrow to run the program. Click on Open Data in New XSection Window and then Seismic.
- Choose a data file to open and click OK on the properties box.
- Now when you click on "Add Horizon" in the file menu, the new horizon layer will show up in the Layers screen.