Search in sources :

Example 1 with Clones

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

the class NodeLinkModel method clones.

public Collection<NodeLinkModel> clones() {
    final Clones sourceNodeClones = getSource().subtreeClones();
    if (sourceNodeClones.size() == 1)
        return Arrays.<NodeLinkModel>asList(this);
    ArrayList<NodeLinkModel> clones = new ArrayList<NodeLinkModel>(sourceNodeClones.size());
    for (NodeModel sourceClone : sourceNodeClones) {
        final NodeLinkModel cloneForSource = cloneForSource(sourceClone);
        if (cloneForSource != null)
            clones.add(cloneForSource);
    }
    return clones;
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) ArrayList(java.util.ArrayList) Clones(org.freeplane.features.map.Clones)

Example 2 with Clones

use of org.freeplane.features.map.Clones 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)

Aggregations

ArrayList (java.util.ArrayList)2 Clones (org.freeplane.features.map.Clones)2 NodeModel (org.freeplane.features.map.NodeModel)2 Point (java.awt.Point)1 NodeRelativePath (org.freeplane.features.map.NodeRelativePath)1