わかった。私の間違いは、ジオメトリ情報を提供する mxCell を作成する必要があるということでした。
mxCell cell = new mxCell(component);
私が書かなければならない上のコードで
mxCell cell = new mxCell(component, new mxGeometry(), "");
ドラッグ機能を追加する完全な方法は次のようになります。
public void addComponentTabListeners() {
final JTree componentTree = view.componentTree;
DragGestureListener dragGestureListener = new DragGestureListener() {
@Override
public void dragGestureRecognized(DragGestureEvent arg0) {
TreePath path = componentTree.getSelectionPath();
if ((path == null) || (path.getPathCount() <= 1)) {
return;
}
DefaultMutableTreeNode componentsNode = (DefaultMutableTreeNode) path.getLastPathComponent();
I_Component component = null;
try {
component = ComponentHandler_KonsensApplication.getInstance().createInstance(
componentsNode.toString(), "need unique Name here");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
mxCell cell = new mxCell(component, new mxGeometry(), "");
cell.setVertex(true);
mxRectangle bounds = new mxRectangle();
bounds.setHeight(80);
bounds.setWidth(80);
mxGraphTransferable t = new mxGraphTransferable(new Object[] { cell }, bounds);
arg0.startDrag(null, mxSwingConstants.EMPTY_IMAGE, new Point(), t, null);
}
};
DragSource dragSource = new DragSource();
dragSource.createDefaultDragGestureRecognizer(componentTree, DnDConstants.ACTION_COPY,
dragGestureListener);
}