• mxGraph实现按住ctrl键盘拖动图形实现复制图形功能


    实现这个功能很easy,仅仅须要重写moveCells方法就能够了。以下是源文件里的代码:

    mxGraph.prototype.moveCells = function(cells, dx, dy, clone, target, evt) {
        if (cells != null && (dx != 0 || dy != 0 || clone || target != null)) {
            this.model.beginUpdate();
            try {
                if (clone) {
                    cells = this.cloneCells(cells, this.isCloneInvalidEdges());
                    if (target == null) {
                        target = this.getDefaultParent();
                    }
                }
                this.cellsMoved(cells, dx, dy, !clone && this.isDisconnectOnMove() && this.isAllowDanglingEdges(), target == null);
                if (target != null) {
                    var index = this.model.getChildCount(target);
                    this.cellsAdded(cells, target, index, null, null, true);
                }
                this.fireEvent(new mxEventObject(mxEvent.MOVE_CELLS, 'cells', cells, 'dx', dx, 'dy', dy, 'clone', clone, 'target', target, 'event', evt));
            } finally {
                this.model.endUpdate();
            }
        }
        return cells;
    };
    接下来要对这种方法进行改造。加一句就能够了
    mxGraph.prototype.moveCells = function(cells, dx, dy, clone, target, evt) {
         clone=evt.ctrlKey;//对。就是这啦!

      if (cells != null && (dx != 0 || dy != 0 || clone || target != null)) { this.model.beginUpdate(); try { if (clone) { cells = this.cloneCells(cells, this.isCloneInvalidEdges()); if (target == null) { target = this.getDefaultParent(); } } this.cellsMoved(cells, dx, dy, !clone && this.isDisconnectOnMove() && this.isAllowDanglingEdges(), target == null); if (target != null) { var index = this.model.getChildCount(target); this.cellsAdded(cells, target, index, null, null, true); } this.fireEvent(new mxEventObject(mxEvent.MOVE_CELLS, 'cells', cells, 'dx', dx, 'dy', dy, 'clone', clone, 'target', target, 'event', evt)); } finally { this.model.endUpdate(); } } return cells; };


    是的。实现这个功能的确非常easy。可是往往实际项目中会有不同的需求。比方一个数据库关系图,复制一个字段到还有一张表中的时候;选择了多个图形而且包含关系线的是时候是否须要复制关系;假设图形存在子图形。是否须要一同复制;当前选择的图形是不是同意移动/复制。移动进入目标图形,目标图形是否同意该操作等等,这些就须要在这种方法区域中进行复杂的推断。

  • 相关阅读:
    hadoop中常见的问题
    RedHat中敲sh-copy-id命令报错:-bash: ssh-copy-id: command not found
    【POJ2411】Mondriaan's Dream(轮廓线DP)
    【CF248E】Piglet's Birthday(动态规划)
    【BZOJ2655】Calc(拉格朗日插值,动态规划)
    【Luogu4781】【模板】拉格朗日插值
    【CF995F】Cowmpany Cowmpensation(动态规划,拉格朗日插值)
    拉格朗日插值公式
    求集合中选一个数与当前值进行位运算的max
    【HDU4471】Homework(矩阵快速幂)
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/5275394.html
Copyright © 2020-2023  润新知