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;
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations