The INTViewer API allows programmers to implement drag and drop capabilities. You can drag a 2D or 3D layer from one viewer window to another one. You can also drag an object in the File Explorer top component to a viewer window.
The main interface used in Drag and Drop operations is the com.interactive.intviewerapi.IDataImporter interface. The implementation of a Drag and Drop is in two steps:
The following importer class imports any visual using ITriangleMeshData and coming from a map window:
THREEDMAPTRIANGLEMESHIMPORTER.JAVA
package com.interactive.intviewer.tmesh.importers;
import com.interactive.intviewer.layer2d.AbstractVisualNamer;
import com.interactive.intviewer.tmesh.util.TriangleMeshObject3DImportUtil;
import com.interactive.intviewer.util.VisualImportUtil;
import com.interactive.intviewer.view2d.AbstractSelfHandleException;
import com.interactive.intviewerapi.IDataImporter;
import com.interactive.intviewerapi.IVisual;
import com.interactive.intviewerapi.data.IData;
import com.interactive.intviewerapi.data.tmesh.ITriangleMeshData;
import com.interactive.intviewerapi.objects3d.IObject3D;
import com.interactive.intviewerapi.objects3d.IObject3DFactory;
import com.interactive.intviewerapi.objects3d.ITriangleMeshObject3D;
import com.interactive.intviewerapi.windows.ICRSProvider;
import com.interactive.intviewerapi.windows.IWindow3D;
import java.util.logging.Logger;
public class ThreeDMapTriangleMeshImporter implements IDataImporter<IVisual, IWindow3D> {
private static final Logger logger = Logger.getLogger(ThreeDMapTriangleMeshImporter.class.getName());
@Override
public Class<IVisual> getSupportedClass() {
return IVisual.class;
}
@Override
public boolean importData(IWindow3D window, IVisual provider) {
IObject3DFactory<ITriangleMeshObject3D, IData, IWindow3D> lf = ITriangleMeshObject3D.factory;
try {
IObject3D object3D = lf.createObject3D(window, provider.getData(), provider.getProperties(), false);
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
return true;
}
@Override
public boolean canImport(IVisual provider) {
return !(provider instanceof IObject3D) && (provider.getData() != null) && (provider.getData() instanceof ITriangleMeshData) && (provider.getViewerWindow() instanceof ICRSProvider);
}
}
Register this importer in the layer.xml file for each window type that should use it. In this example below, we register this importer for 3D windows (<folder name="Viewer3D">):
LAYER.XML
<folder name="DnDImporters">
<folder name="Viewer3D">
<file name="com-interactive-intviewer-tmesh-importers-ThreeDMapTriangleMeshImporter.instance"/>
</folder>
A window can have several importers registered. Upon the detection of a drag and drop operation, all importers for that window will be tried using the getSupportedClass and canImport methods. The first importer matching the class and returning true to a canImport call will be used. If two importers match, only the first one will be used.
The following importer class imports any data object using ITriangleMeshData and coming from the "Data" and "File Explorer" top components:
MVTRIANGLEMESHDATANODEIMPORTER.JAVA
package com.interactive.intviewer.tmesh.importers;
import com.interactive.intviewer.seismic.SeismicLayerRequiredException;
import com.interactive.intviewerapi.data.DataNode;
import com.interactive.intviewer.seismic.util.SeismicLayer2DImportUtil;
import com.interactive.intviewer.tmesh.layer2d.MapTriangleMeshLayer;
import com.interactive.intviewer.util.DataNodeUtil;
import com.interactive.intviewer.util.VisualImportUtil;
import com.interactive.intviewer.view2d.AbstractSelfHandleException;
import com.interactive.intviewer.view2d.MVDesktopDataImporterAdapter;
import com.interactive.intviewerapi.IDataImporter;
import com.interactive.intviewerapi.data.tmesh.ITriangleMeshData;
import com.interactive.intviewerapi.layers.NamedProps;
import com.interactive.intviewerapi.windows.IMapWindow;
import java.util.logging.Logger;
public class MVTriangleMeshDataNodeImporter implements IDataImporter<DataNode, IMapWindow> {
private static final Logger logger = Logger.getLogger(MVTriangleMeshDataNodeImporter.class.getName());
@Override
public Class<DataNode> getSupportedClass() {
return DataNode.class;
}
@Override
public boolean canImport(DataNode dob) {
ITriangleMeshData hd = dob.getLookup().lookup(ITriangleMeshData.class);
if (hd != null) {
return true;
}
return false;
}
@Override
public boolean importData(IMapWindow parentWindow, DataNode dob) {
ITriangleMeshData foundData = dob.getLookup().lookup(ITriangleMeshData.class);
try {
IMapTriangleMeshLayer.factory.createLayer(parentWindow, foundData, new NamedProps(), true);
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
return true;
}
}
The registration is identical to the registration for visuals. In this case, the destination window is a Map window:
LAYER.XML
<folder name="ViewerPlotMV">
<file name="com-interactive-intviewer-tmesh-importers-MVTriangleMeshDataNodeImporter.instance"/>
</folder>
There are many cases where a layer cannot be dropped to a window. For example, a triangle mesh layer cannot be created in a XSection window unless there is already a seismic layer in that window.
You can handle by displaying a dialog if the drag and drop failed.