Search in sources :

Example 26 with InternalNode

use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.

the class TreeLayoutAlgorithm method buildTreeRecursively.

/**
 * Builds a tree of the passed in entity.
 * The entity will pass a weight value to all of its children recursively.
 */
private void buildTreeRecursively(InternalNode layoutEntity, int i, double weight, InternalNode[] entities, final InternalRelationship[] relationships) {
    // No need to do further computation!
    if (layoutEntity == null) {
        return;
    }
    // forest, and its weight value needs to be modified.
    if (markedArr[i]) {
        modifyWeightRecursively(layoutEntity, i, weight, new HashSet(), entities, relationships);
        // No need to do further computation.
        return;
    }
    // Mark this entity, set its weight value and create a new tree node.
    markedArr[i] = true;
    weights[i] = weight;
    // collect the children of this entity and put them in order
    Collection rels = findRelationships(layoutEntity, AS_SOURCE, relationships);
    List children = new ArrayList();
    for (Iterator iter = rels.iterator(); iter.hasNext(); ) {
        InternalRelationship layoutRel = (InternalRelationship) iter.next();
        InternalNode childEntity = layoutRel.getDestination();
        children.add(childEntity);
    }
    if (comparator != null) {
        Collections.sort(children, comparator);
    } else {
        // sort the children by level, then by number of descendents, then by number of children
        // TODO: SLOW
        Collections.sort(children, new Comparator() {

            @Override
            public int compare(Object o1, Object o2) {
                InternalNode node1 = (InternalNode) o1;
                InternalNode node2 = (InternalNode) o2;
                int[] numDescendentsAndLevel1 = new int[2];
                int[] numDescendentsAndLevel2 = new int[2];
                int level1 = numDescendentsAndLevel1[NUM_LEVELS_INDEX];
                int level2 = numDescendentsAndLevel2[NUM_LEVELS_INDEX];
                if (level1 == level2) {
                    getNumDescendentsAndLevel(node1, relationships, numDescendentsAndLevel1);
                    getNumDescendentsAndLevel(node2, relationships, numDescendentsAndLevel2);
                    int numDescendents1 = numDescendentsAndLevel1[NUM_DESCENDENTS_INDEX];
                    int numDescendents2 = numDescendentsAndLevel2[NUM_DESCENDENTS_INDEX];
                    if (numDescendents1 == numDescendents2) {
                        int numChildren1 = getNumChildren(node1, relationships);
                        int numChildren2 = getNumChildren(node1, relationships);
                        return numChildren2 - numChildren1;
                    } else {
                        return numDescendents2 - numDescendents1;
                    }
                } else {
                    return level2 - level1;
                }
            // return getNumChildren(node2, relationships) - getNumChildren(node1, relationships);
            }
        });
    }
    // map children to this parent, and vice versa
    for (Iterator iter = children.iterator(); iter.hasNext(); ) {
        InternalNode childEntity = (InternalNode) iter.next();
        int childEntityIndex = indexOfInternalNode(entities, childEntity);
        if (!childrenLists[i].contains(childEntity)) {
            childrenLists[i].add(childEntity);
        }
        if (!parentLists[childEntityIndex].contains(layoutEntity)) {
            parentLists[childEntityIndex].add(layoutEntity);
        }
    }
    for (Iterator iter = children.iterator(); iter.hasNext(); ) {
        InternalNode childEntity = (InternalNode) iter.next();
        int childEntityIndex = indexOfInternalNode(entities, childEntity);
        buildTreeRecursively(childEntity, childEntityIndex, weight + 1, entities, relationships);
    }
}
Also used : InternalRelationship(org.eclipse.zest.layouts.dataStructures.InternalRelationship) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode) HashSet(java.util.HashSet) Comparator(java.util.Comparator)

Example 27 with InternalNode

use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.

the class TreeLayoutAlgorithm method getLevelRecursive.

private int getLevelRecursive(InternalNode layoutEntity, int i, Set seen, InternalNode[] entities) {
    if (seen.contains(layoutEntity)) {
        return 0;
    }
    seen.add(layoutEntity);
    List parents = parentLists[i];
    int maxParentLevel = 0;
    for (Iterator iter = parents.iterator(); iter.hasNext(); ) {
        InternalNode parentEntity = (InternalNode) iter.next();
        int parentEntityIndex = indexOfInternalNode(entities, parentEntity);
        int parentLevel = getLevelRecursive(parentEntity, parentEntityIndex, seen, entities) + 1;
        maxParentLevel = Math.max(maxParentLevel, parentLevel);
    }
    return maxParentLevel;
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode)

Example 28 with InternalNode

use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.

the class HorizontalShift method applyLayoutInternal.

@Override
protected void applyLayoutInternal(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider, double boundsX, double boundsY, double boundsWidth, double boundsHeight) {
    ArrayList row = new ArrayList();
    for (int i = 0; i < entitiesToLayout.length; i++) {
        addToRowList(entitiesToLayout[i], row);
    }
    int heightSoFar = 0;
    Collections.sort(row, new Comparator() {

        @Override
        public int compare(Object arg0, Object arg1) {
            // TODO Auto-generated method stub
            List a0 = (List) arg0;
            List a1 = (List) arg1;
            LayoutEntity node0 = ((InternalNode) a0.get(0)).getLayoutEntity();
            LayoutEntity node1 = ((InternalNode) a1.get(0)).getLayoutEntity();
            return (int) (node0.getYInLayout() - (node1.getYInLayout()));
        }
    });
    Iterator iterator = row.iterator();
    while (iterator.hasNext()) {
        List currentRow = (List) iterator.next();
        Collections.sort(currentRow, new Comparator() {

            @Override
            public int compare(Object arg0, Object arg1) {
                return (int) (((InternalNode) arg1).getLayoutEntity().getYInLayout() - ((InternalNode) arg0).getLayoutEntity().getYInLayout());
            }
        });
        Iterator iterator2 = currentRow.iterator();
        int i = 0;
        int width = (int) ((boundsWidth / 2) - currentRow.size() * 75);
        heightSoFar += ((InternalNode) currentRow.get(0)).getLayoutEntity().getHeightInLayout() + VSPACING * 8;
        while (iterator2.hasNext()) {
            InternalNode currentNode = (InternalNode) iterator2.next();
            double location = width + 10 * ++i;
            currentNode.setLocation(location, heightSoFar);
            width += currentNode.getLayoutEntity().getWidthInLayout();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) LayoutEntity(org.eclipse.zest.layouts.LayoutEntity) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode) Comparator(java.util.Comparator)

Example 29 with InternalNode

use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.

the class HorizontalShift method addToRowList.

private void addToRowList(InternalNode node, ArrayList list) {
    double layoutY = node.getLayoutEntity().getYInLayout();
    for (int i = 0; i < list.size(); i++) {
        List currentRow = (List) list.get(i);
        InternalNode currentRowNode = (InternalNode) currentRow.get(0);
        double currentRowY = currentRowNode.getLayoutEntity().getYInLayout();
        // double currentRowHeight = currentRowNode.getLayoutEntity().getHeightInLayout();
        if (layoutY >= (currentRowY - DELTA) && layoutY <= currentRowY + DELTA) {
            currentRow.add(node);
            // list.add(i, currentRow);
            return;
        }
    }
    List newRow = new ArrayList();
    newRow.add(node);
    list.add(newRow);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode)

Example 30 with InternalNode

use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.

the class AbstractLayoutAlgorithm method getLayoutBounds.

/**
 * Find the bounds in which the nodes are located.  Using the bounds against the real bounds
 * of the screen, the nodes can proportionally be placed within the real bounds.
 * The bounds can be determined either including the size of the nodes or not.  If the size
 * is not included, the bounds will only be guaranteed to include the center of each node.
 */
protected DisplayIndependentRectangle getLayoutBounds(InternalNode[] entitiesToLayout, boolean includeNodeSize) {
    double rightSide = Double.MIN_VALUE;
    double bottomSide = Double.MIN_VALUE;
    double leftSide = Double.MAX_VALUE;
    double topSide = Double.MAX_VALUE;
    for (int i = 0; i < entitiesToLayout.length; i++) {
        InternalNode entity = entitiesToLayout[i];
        if (entity.hasPreferredLocation()) {
            continue;
        }
        if (includeNodeSize) {
            leftSide = Math.min(entity.getInternalX() - entity.getInternalWidth() / 2, leftSide);
            topSide = Math.min(entity.getInternalY() - entity.getInternalHeight() / 2, topSide);
            rightSide = Math.max(entity.getInternalX() + entity.getInternalWidth() / 2, rightSide);
            bottomSide = Math.max(entity.getInternalY() + entity.getInternalHeight() / 2, bottomSide);
        } else {
            leftSide = Math.min(entity.getInternalX(), leftSide);
            topSide = Math.min(entity.getInternalY(), topSide);
            rightSide = Math.max(entity.getInternalX(), rightSide);
            bottomSide = Math.max(entity.getInternalY(), bottomSide);
        }
    }
    return new DisplayIndependentRectangle(leftSide, topSide, rightSide - leftSide, bottomSide - topSide);
}
Also used : DisplayIndependentRectangle(org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode) BasicEntityConstraint(org.eclipse.zest.layouts.constraints.BasicEntityConstraint) BendPoint(org.eclipse.zest.layouts.dataStructures.BendPoint) DisplayIndependentPoint(org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint)

Aggregations

InternalNode (org.eclipse.zest.layouts.dataStructures.InternalNode)33 Iterator (java.util.Iterator)12 ArrayList (java.util.ArrayList)11 DisplayIndependentPoint (org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint)11 List (java.util.List)10 BasicEntityConstraint (org.eclipse.zest.layouts.constraints.BasicEntityConstraint)9 BendPoint (org.eclipse.zest.layouts.dataStructures.BendPoint)9 InternalRelationship (org.eclipse.zest.layouts.dataStructures.InternalRelationship)9 DisplayIndependentRectangle (org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle)5 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 LayoutEntity (org.eclipse.zest.layouts.LayoutEntity)3 Comparator (java.util.Comparator)2 HashMap (java.util.HashMap)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 DirectedGraph (org.eclipse.draw2d.graph.DirectedGraph)1 DirectedGraphLayout (org.eclipse.draw2d.graph.DirectedGraphLayout)1 Edge (org.eclipse.draw2d.graph.Edge)1 Node (org.eclipse.draw2d.graph.Node)1 LayoutRelationship (org.eclipse.zest.layouts.LayoutRelationship)1