Search in sources :

Example 6 with NodeRelativePath

use of org.freeplane.features.map.NodeRelativePath in project freeplane by freeplane.

the class NodeLinkModel method cloneForSource.

public NodeLinkModel cloneForSource(NodeModel sourceClone) {
    final NodeModel source = getSource();
    if (sourceClone == source)
        return this;
    String targetID = getTargetID();
    final NodeModel target = getTarget();
    if (target != null && target.getParentNode() != null && source.getParentNode() != null) {
        final NodeRelativePath nodeRelativePath = new NodeRelativePath(source, target);
        final NodeModel commonAncestor = nodeRelativePath.commonAncestor();
        final NodeModel ancestorClone = nodeRelativePath.ancestorForBegin(sourceClone);
        if (commonAncestor.isCloneOf(ancestorClone)) {
            final NodeRelativePath pathAncestorToSource = new NodeRelativePath(commonAncestor, source);
            final NodeRelativePath clonePath = new NodeRelativePath(ancestorClone, sourceClone);
            if (pathAncestorToSource.equalPathsTo(clonePath)) {
                final NodeModel targetClone = nodeRelativePath.pathEnd(ancestorClone);
                targetID = targetClone.createID();
            }
        }
    }
    return cloneForSource(sourceClone, targetID);
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) NodeRelativePath(org.freeplane.features.map.NodeRelativePath)

Aggregations

NodeModel (org.freeplane.features.map.NodeModel)6 NodeRelativePath (org.freeplane.features.map.NodeRelativePath)6 Point (java.awt.Point)3 HashSet (java.util.HashSet)2 ArrayList (java.util.ArrayList)1 Clones (org.freeplane.features.map.Clones)1 IMapSelection (org.freeplane.features.map.IMapSelection)1 ModeController (org.freeplane.features.mode.ModeController)1