Working With Windows

The window types

All the windows created inside the desktop area of INTViewer must be of type IViewerWindow. The most useful types of windows are actually ILayeredWindow and IWindow3D which extend IViewerWindow.

All the important 2D window types supported by the viewer, including windows that display seismic data, maps or cross-plots are of type ILayeredWindow. IWindow3D is the only 3D window type

This tutorial covers the basics for all the layered and 3D window types. Specifics about the different types of layers can be found using the links below.

  • XSection windows
  • Map windows
  • 3D windows
  • Cross-plot windows

When you create a window, make sure you add Viewer2D or Viewer3D to your module dependencies. Viewer2D is for windows such as XSections, Maps. Viewer3D is for the 3D window.

Creating a new window

For a x-section window (make sure the Viewer2D and Seismic2D modules are imported):

    import com.interactive.intviewerapi.windows.IXSectionWindow;
    ...
    IXSectionWindow xsectionWindow = IXSectionWindow.factory.createWindow();

For a map window (make sure the Viewer2D and Seismic2D modules are imported):

    import com.interactive.intviewerapi.windows.IXpWindow;
    ...
    IMapWindow mapWindow = IMapWindow.factory.createWindow();

For a cross-plot window (make sure the Viewer2D and CrossPlot modules are imported):

    import com.interactive.intviewerapi.windows.IXpWindow;
    ...
    IXpWindow xpWindow = IXpWindow.factory.createWindow();

The specific window classes IXSectionWindow, IMapWindow and IXpWindow all extend the interface ILayeredWindow so the API described below applies to all those classes.

For a 3D window (make sure the Viewer3D module is imported):

    import com.interactive.intviewerapi.windows.IWindow3D;
    ...
    IWindow3D threeDWindow = IWindow3D.factory.createWindow();

Setting properties of a window

The properties of a window can be set using the NamedProps class as follows:

    import com.interactive.intviewerapi.layers.NamedProps;
    import com.interactive.intviewerapi.windows.ILayeredWindow;
        ...
    NamedProps windowProperties = new NamedProps();
    windowProperties.putProperty(ILayeredWindow.TITLE, "X-Section View");
    windowProperties.putProperty(ILayeredWindow.TITLE_LOC, ILayeredWindow.TOP);
    windowProperties.putProperty(ILayeredWindow.VAXIS_LOC, ILayeredWindow.LEFT_RIGHT);
    windowProperties.putProperty(ILayeredWindow.HAXIS_LOC, ILayeredWindow.TOP_BOTTOM);
    xsectionWindow.setProperties(windowProperties);

In the context of the legacy FRAMES window system (see Overview of API changes in INTViewer 5.2), window size and positioning properties can be set directly using the ILayeredWindow API.

    xsectionWindow.setSize(550, 550); 
    xsectionWindow.setLocation(0, 0);

or, if you wanted to set the window to the full desktop size:

    import com.interactive.intviewerapi.windows.IWindowManager;
     ...
    IWindowManager iwm = IWindowManager.Factory.getInstance();
    Dimension dim = iwm.getDesktopSize();
    xsectionWindow.setSize(dim.width, dim.height);

Getting information about existing 2D

The window manager also gives us access to the windows managed in the desktop area of INTViewer. For example, we can then retrieve the selected window or the list of existing windows as follows:

    import com.interactive.intviewerapi.windows.IViewerWindow;
     ...
    // Getting the selected window (could return null)
    IViewerWindow slw = iwm.getSelectedViewerWindow();
For the list of all 2D layered windows:
    ILayeredWindow[] layeredWindows = iwm.getAllViewerWindows(ILayeredWindow.class);

Getting notified when a 2D or 3D window has been selected

Netbeans supports a Lookup mechanism that can be used to provide notification for any sort of selection. INTViewer uses this mechanism for window and layer selection. The utility class GlobalSelection provides an easy way to register and get notification for selection. It can be used as follows for 2D windows:

1. Create a GlobalSelection object for ILayeredWindow

    import com.interactive.intviewerapi.GlobalSelection;
    ...

private GlobalSelection<ILayeredWindow> windowSelection = new GlobalSelection<>(ILayeredWindow.class);

2. implement in your class the interface LookupListener which has one method resultChanged:

    import org.openide.util.LookupEvent;
    import org.openide.util.LookupListener;
    ...
    public void resultChanged(LookupEvent arg0) {
        Collection<? extends ILayeredWindow> windows = windowSelection.allInstances();
        if (!windows.isEmpty()) {
            ...
        }
    }

3. Register the class that implements LookupListener

    windowSelection.addLookupListener(this);

This mechanism is identical for 3D windows:

1. Create a GlobalSelection object for IWindow3D

    import com.interactive.intviewerapi.GlobalSelection;
    ...
    private GlobalSelection<IWindow3D> windowSelection = new GlobalSelection<>(IWindow3D.class);

2. implement in your class the interface LookupListener which has one method resultChanged:

    import org.openide.util.LookupEvent;
    import org.openide.util.LookupListener;
    ...
    public void resultChanged(LookupEvent arg0) {
        Collection<? extends IWindow3D> windows = windowSelection.allInstances();
        if (!windows.isEmpty()) {
            ...
        }
    }

3. Register the class that implements LookupListener

windowSelection.addLookupListener(this);

Getting notified when a 2D layer or 3D object has been added, removed or selected

To receive notification that a 3D object has been added, removed or selected, you need to listen to ViewerWindowEvent.

public class MyClass implements IEventSubcriber<ViewerWindowEvent> {
   public MyClass() {
      ...
      EventBroadcaster.getInstance().subscribe(ViewerWindowEvent.class, this);
   }
   ...
   public void onEvent(ViewerWindowEvent e) {
       ... // handle event here
   }
}


For example, if you have a layer that needs a reference layer, and you want your layer to be removed automatically when its reference layer is removed, follow this template:

   public MyClass() {
      ...
      EventBroadcaster.getInstance().subscribe(ViewerWindowEvent.class, this);
   }
    @Override
    public void onEvent(ViewerWindowEvent evt) {
        if ((this.getData() != null) && (this.refLayer != null)) {
            if (evt.getEventType().equals(ViewerWindowEvent.VISUALS_REMOVED_EVENT_TYPE)) {
                boolean isReferenceLayerRemoved = false;
                IVisual[] removedLayers = evt.getVisuals();
                for (IVisual currentLayer : removedLayers) {
                    if (currentLayer.equals(this.refLayer)) {
                        isReferenceLayerRemoved = true;
                    }
                }
                if (isReferenceLayerRemoved) {
                    EventBroadcaster.getInstance().unsubscribe(ViewerWindowEvent.class, this);
                    this.getViewerWindow().deleteVisuals(new IVisual[]{this});
                    this.refLayer = null;
                }
            }
        }
    }

If you extend AbstractXSectionReferenceLayer, this is done automatically as part of its implemementation.

Taking window snapshots

You can easily take a snapshot programmatically of a window.

All windows implement the IImageProvider interface and have a getBufferedImage method:

http://www.int.com/intviewer/docs/api/latest/com/interactive/intviewerapi/windows/IImageProvider.html

Some windows might have additional APIs. For example, IXSectionWindow has the following method where you can customize the size of the image:

BufferedImage getFullBufferedImage(long width, long height)

To convert a buffered image to a file, use the javax.imageio.ImageIO.write method.