0

EditorPalette では、テンプレートは mxGraphComponent にドラッグ アンド ドロップできる JLabels を使用して表されますね。

ただし、これらのテンプレートを JTree 経由で階層構造を使用して EditorPalette に追加したいのですが、通常のテンプレートのようにノードを GraphComponents にドラッグ アンド ドロップすることはできません。

コンポーネントの左側に JTree を追加し、mxGraphComponent にドラッグ アンド ドロップするための追加テンプレートの機能を提供してくれませんか?

4

1 に答える 1

1

わかった。私の間違いは、ジオメトリ情報を提供する 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);
}
于 2013-08-30T18:34:49.390 に答える