Search in sources :

Example 1 with InternalNode

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

the class AggregateLayoutAlgorithm method postLayoutAlgorithm.

/**
 * Called at the end of the layout algorithm -- change the size and colour
 * of each node according to times called/total time
 */
@Override
protected void postLayoutAlgorithm(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider) {
    final int minimumSize = 40;
    double xcursor = 0.0;
    double ycursor = 0.0;
    for (InternalNode sn : entitiesToLayout) {
        Long time = list.remove(0);
        double percent = (double) time / (double) totalTime;
        double snWidth = (sn.getInternalWidth() * percent) + minimumSize;
        double snHeight = (sn.getInternalHeight() * percent) + minimumSize;
        sn.setSize(snWidth, snHeight);
        if (xcursor + snWidth > graphWidth) {
            // reaching the end of row, move to lower column
            ycursor += snHeight;
            xcursor = 0;
            sn.setLocation(xcursor, ycursor);
        } else {
            sn.setLocation(xcursor, ycursor);
            xcursor += snWidth;
        }
    }
}
Also used : InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode)

Example 2 with InternalNode

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

the class SpringLayoutAlgorithm method computeOneIteration.

@Override
protected void computeOneIteration(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider, double x, double y, double width, double height) {
    if (bounds == null)
        bounds = new DisplayIndependentRectangle(x, y, width, height);
    checkPreferredLocation(entitiesToLayout, bounds);
    computeForces(entitiesToLayout);
    largestMovement = Double.MAX_VALUE;
    computePositions(entitiesToLayout);
    for (int i = 0; i < entitiesToLayout.length; i++) {
        InternalNode layoutEntity = entitiesToLayout[i];
        layoutEntity.setInternalLocation(tempLocationsX[i], tempLocationsY[i]);
    }
    defaultFitWithinBounds(entitiesToLayout, bounds);
    iteration++;
}
Also used : DisplayIndependentRectangle(org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode)

Example 3 with InternalNode

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

the class TreeLayoutAlgorithm method buildForestRecursively.

/**
 * Builds the forest recursively. All entities
 * will be placed somewhere in the forest.
 */
private void buildForestRecursively(List roots, List unplacedEntities, InternalNode[] entities, InternalRelationship[] relationships) {
    if (unplacedEntities.size() == 0) {
        // no more entities to place
        return;
    }
    // get the first entity in the list of unplaced entities, find its root, and build this root's tree
    InternalNode layoutEntity = (InternalNode) unplacedEntities.get(0);
    InternalNode rootEntity = findRootObjectRecursive(layoutEntity, new HashSet(), relationships);
    int rootEntityIndex = indexOfInternalNode(entities, rootEntity);
    buildTreeRecursively(rootEntity, rootEntityIndex, 0, entities, relationships);
    roots.add(rootEntity);
    // now see which nodes are left to be placed in a tree somewhere
    List unmarkedCopy = new ArrayList(unplacedEntities);
    for (Iterator iter = unmarkedCopy.iterator(); iter.hasNext(); ) {
        InternalNode tmpEntity = (InternalNode) iter.next();
        int tmpEntityIndex = indexOfInternalNode(entities, tmpEntity);
        boolean isMarked = markedArr[tmpEntityIndex];
        if (isMarked) {
            unplacedEntities.remove(tmpEntity);
        }
    }
    buildForestRecursively(roots, unplacedEntities, entities, relationships);
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode) HashSet(java.util.HashSet)

Example 4 with InternalNode

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

the class TreeLayoutAlgorithm method getNumberOfLeavesRecursive.

private int getNumberOfLeavesRecursive(InternalNode layoutEntity, int i, Set seen, InternalNode[] entities) {
    int numLeaves = 0;
    List children = childrenLists[i];
    if (children.size() == 0) {
        numLeaves = 1;
    } else {
        // TODO: SLOW!
        for (Iterator iter = children.iterator(); iter.hasNext(); ) {
            InternalNode childEntity = (InternalNode) iter.next();
            if (!seen.contains(childEntity)) {
                seen.add(childEntity);
                int childEntityIndex = indexOfInternalNode(entities, childEntity);
                numLeaves += getNumberOfLeavesRecursive(childEntity, childEntityIndex, seen, entities);
            } else {
                numLeaves = 1;
            }
        }
    }
    return numLeaves;
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode)

Example 5 with InternalNode

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

the class GridLayoutAlgorithm method applyLayoutInternal.

/**
 * Use this algorithm to layout the given entities, using the given relationships and bounds.
 * The entities will be placed in the same order as they are passed in, unless a comparator
 * is supplied.
 *
 * @param entitiesToLayout Apply the algorithm to these entities
 * @param relationshipsToConsider Only consider these relationships when applying the algorithm.
 * @param boundsX The left side of the bounds in which the layout can place the entities.
 * @param boundsY The top side of the bounds in which the layout can place the entities.
 * @param boundsWidth The width of the bounds in which the layout can place the entities.
 * @param boundsHeight The height of the bounds in which the layout can place the entities.
 * @throws RuntimeException Thrown if entitiesToLayout doesn't contain all of the endpoints for each relationship in relationshipsToConsider
 */
@Override
protected synchronized void applyLayoutInternal(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider, double boundsX, double boundsY, double boundsWidth, double boundsHeight) {
    int index = 0;
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            if ((i * cols + j) < numChildren) {
                // find new position for child
                double xmove = boundsX + j * colWidth + offsetX;
                double ymove = boundsY + i * rowHeight + offsetY;
                InternalNode sn = entitiesToLayout[index++];
                sn.setInternalLocation(xmove, ymove);
                sn.setInternalSize(Math.max(w, MIN_ENTITY_SIZE), Math.max(h, MIN_ENTITY_SIZE));
            }
        }
        fireProgressEvent(2 + i, totalProgress);
    }
    updateLayoutLocations(entitiesToLayout);
    fireProgressEvent(totalProgress, totalProgress);
}
Also used : InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode)

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