Search in sources :

Example 46 with NodeModel

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

the class MMapController method getPathToNearestTargetClone.

private NodeRelativePath getPathToNearestTargetClone(final NodeModel source, final NodeModel target) {
    if (source == target)
        return new NodeRelativePath(source, target);
    final Clones targetClones = target.subtreeClones();
    final int pathNumber = targetClones.size();
    if (pathNumber == 1)
        return new NodeRelativePath(source, target);
    Collection<NodeRelativePath> paths = new ArrayList<>(pathNumber);
    for (NodeModel targetClone : targetClones) paths.add(new NodeRelativePath(source, targetClone));
    final NodeRelativePath shortestPath = Collections.min(paths, new Comparator<NodeRelativePath>() {

        @Override
        public int compare(NodeRelativePath o1, NodeRelativePath o2) {
            return o1.getPathLength() - o2.getPathLength();
        }
    });
    return shortestPath;
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) NodeRelativePath(org.freeplane.features.map.NodeRelativePath) ArrayList(java.util.ArrayList) Clones(org.freeplane.features.map.Clones) Point(java.awt.Point)

Example 47 with NodeModel

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

the class MMapController method moveNodes.

public void moveNodes(final List<NodeModel> movedNodes, final NodeModel newParent, final int newIndex, final boolean isLeft, final boolean changeSide) {
    final List<NodeModel> movedNodesWithSummaryGroupIndicators = new SummaryGroupEdgeListAdder(movedNodes).addSummaryEdgeNodes();
    int index = newIndex;
    for (NodeModel node : movedNodesWithSummaryGroupIndicators) moveNodeAndItsClones(node, newParent, index++, isLeft, changeSide && node.isLeft() != isLeft);
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) Point(java.awt.Point)

Example 48 with NodeModel

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

the class MMapController method deleteSingleNodeWithClones.

private void deleteSingleNodeWithClones(NodeModel node) {
    final NodeModel parentNode = node.getParentNode();
    final int index = parentNode.getIndex(node);
    for (NodeModel parentClone : parentNode.subtreeClones()) deleteSingleNode(parentClone, index);
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) Point(java.awt.Point)

Example 49 with NodeModel

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

the class MMapController method addNewSummaryNodeStartEditing.

public void addNewSummaryNodeStartEditing(final NodeModel parentNode, final int start, final int end, final int summaryLevel, final boolean isLeft) {
    ModeController modeController = getMModeController();
    stopEditing();
    final NodeModel newSummaryNode = addNewNode(parentNode, end + 1, isLeft);
    final SummaryNode summary = modeController.getExtension(SummaryNode.class);
    summary.undoableActivateHook(newSummaryNode, SUMMARY);
    AlwaysUnfoldedNode unfolded = modeController.getExtension(AlwaysUnfoldedNode.class);
    unfolded.undoableActivateHook(newSummaryNode, unfolded);
    final FirstGroupNode firstGroupNodeHook = modeController.getExtension(FirstGroupNode.class);
    final NodeModel firstNodeInGroup = parentNode.getChildAt(start);
    if (SummaryNode.isSummaryNode(firstNodeInGroup))
        firstGroupNodeHook.undoableActivateHook(firstNodeInGroup, FIRST_GROUP);
    else {
        final NodeModel previousNode = firstNodeInGroup.previousNode(start, isLeft);
        if (previousNode == null || SummaryNode.isSummaryNode(previousNode) || !SummaryNode.isFirstGroupNode(previousNode)) {
            NodeModel newFirstGroup = addNewNode(parentNode, start, isLeft);
            firstGroupNodeHook.undoableActivateHook(newFirstGroup, FIRST_GROUP);
        }
        firstGroupNodeHook.undoableDeactivateHook(firstNodeInGroup);
    }
    int level = summaryLevel;
    for (int i = start + 1; i <= end; i++) {
        NodeModel node = parentNode.getChildAt(i);
        if (isLeft != node.isLeft())
            continue;
        if (SummaryNode.isSummaryNode(node))
            level++;
        else
            level = 0;
        if (level == summaryLevel && SummaryNode.isFirstGroupNode(node)) {
            if (level > 0)
                firstGroupNodeHook.undoableDeactivateHook(node);
            else
                deleteSingleNodeWithClones(node);
        }
    }
    final NodeModel firstSummaryChildNode = addNewNode(newSummaryNode, 0, isLeft);
    startEditingAfterSelect(firstSummaryChildNode);
    select(firstSummaryChildNode);
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) SummaryNode(org.freeplane.features.map.SummaryNode) AlwaysUnfoldedNode(org.freeplane.features.map.AlwaysUnfoldedNode) ModeController(org.freeplane.features.mode.ModeController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) FirstGroupNode(org.freeplane.features.map.FirstGroupNode) Point(java.awt.Point)

Example 50 with NodeModel

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

the class MMapController method moveNodeAndItsClones.

public void moveNodeAndItsClones(NodeModel child, final NodeModel newParent, int newIndex, final boolean isLeft, final boolean changeSide) {
    if (child.subtreeContainsCloneOf(newParent)) {
        UITools.errorMessage("not allowed");
        return;
    }
    final NodeModel oldParent = child.getParentNode();
    if (newParent != oldParent && newParent.subtreeClones().contains(oldParent)) {
        moveNodeAndItsClones(child, oldParent, newIndex, newParent.isLeft(), false);
        return;
    }
    final NodeModel childNode = child;
    final int oldIndex = oldParent.getIndex(childNode);
    final int childCount = newParent.getChildCount();
    newIndex = newIndex >= childCount ? oldParent == newParent ? childCount - 1 : childCount : newIndex;
    if (oldParent != newParent || oldIndex != newIndex || changeSide != false) {
        final NodeRelativePath nodeRelativePath = getPathToNearestTargetClone(oldParent, newParent);
        final Set<NodeModel> oldParentClones = new HashSet<NodeModel>(oldParent.subtreeClones().toCollection());
        final Set<NodeModel> newParentClones = new HashSet<NodeModel>(newParent.subtreeClones().toCollection());
        final NodeModel commonAncestor = nodeRelativePath.commonAncestor();
        for (NodeModel commonAncestorClone : commonAncestor.subtreeClones()) {
            NodeModel oldParentClone = nodeRelativePath.pathBegin(commonAncestorClone);
            NodeModel newParentClone = nodeRelativePath.pathEnd(commonAncestorClone);
            final boolean isLeftForClone = newParentClone == newParent ? isLeft : newParentClone.isLeft();
            moveSingleNode(oldParentClone.getChildAt(oldIndex), newParentClone, newIndex, isLeftForClone, changeSide);
            oldParentClones.remove(oldParentClone);
            newParentClones.remove(newParentClone);
        }
        for (NodeModel newParentClone : newParentClones) insertSingleNewNode(child.cloneTree(), newParentClone, newIndex, newParentClone.isLeft());
        for (NodeModel oldParentClone : oldParentClones) deleteSingleNode(oldParentClone, oldIndex);
    }
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) NodeRelativePath(org.freeplane.features.map.NodeRelativePath) Point(java.awt.Point) HashSet(java.util.HashSet)

Aggregations

NodeModel (org.freeplane.features.map.NodeModel)450 ModeController (org.freeplane.features.mode.ModeController)100 MapModel (org.freeplane.features.map.MapModel)53 Controller (org.freeplane.features.mode.Controller)46 MapStyleModel (org.freeplane.features.styles.MapStyleModel)46 MMapController (org.freeplane.features.map.mindmapmode.MMapController)39 MapController (org.freeplane.features.map.MapController)38 Point (java.awt.Point)37 IStyle (org.freeplane.features.styles.IStyle)36 IActor (org.freeplane.core.undo.IActor)34 IMapSelection (org.freeplane.features.map.IMapSelection)33 ArrayList (java.util.ArrayList)22 NodeView (org.freeplane.view.swing.map.NodeView)20 URI (java.net.URI)19 Color (java.awt.Color)18 Component (java.awt.Component)17 ResourceController (org.freeplane.core.resources.ResourceController)17 MModeController (org.freeplane.features.mode.mindmapmode.MModeController)16 NodeStyleController (org.freeplane.features.nodestyle.NodeStyleController)15 MTextController (org.freeplane.features.text.mindmapmode.MTextController)15