Сбрасывание вершины на вершину, создание ребра между ними

Я пытаюсь понять, как реализовать вышеуказанную функциональность? т. е. если у меня уже есть вершина на моем графике, и я перетаскиваю другую вершину из своей палитры (я получил свое приложение из примера Java BasicGraphEditor), я хотел бы автоматически создать ребро из цели перетаскивания в перетаскиваемую ячейку .

Текущая реализация создает группу, которую я НЕ хочу.

Какие-либо предложения?

Спасибо!


person Rogan Dawes    schedule 19.03.2018    source источник


Ответы (1)


Хорошо, кажется, что это решение вышеуказанного вопроса.

Расширьте mxGraphComponent и реализуйте следующий метод:

        public Object[] importCells(Object[] cells, double dx, double dy, Object target, Point location) {
        if (target == null && cells.length == 1 && location != null) {
            target = getCellAt(location.x, location.y);

            if (target instanceof mxICell && cells[0] instanceof mxICell) {
                mxICell targetCell = (mxICell) target;
                mxICell dropCell = (mxICell) cells[0];

                if (targetCell.isVertex() == dropCell.isVertex()) {
                    // make target null, otherwise we create a group
                    cells = super.importCells(cells, dx, dy, null, location);

                    Object parent = graph.getModel().getParent(target);
                    // we cloned it, so update the reference
                    dropCell = (mxICell) cells[0];
                    graph.insertEdge(parent, null, "", target, dropCell);

                    graph.setSelectionCell(dropCell);

                    return null;
                }
            }
        }

        return super.importCells(cells, dx, dy, target, location);
    }
person Rogan Dawes    schedule 19.03.2018