Search in sources :

Example 16 with InternalNode

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

the class AbstractLayoutAlgorithm method resizeAndShiftNodes.

/**
 * Find and set the node size - shift the nodes to the right and down to make
 * room for the width and height.
 * @param entitiesToLayout
 * @param relationships
 */
private void resizeAndShiftNodes(InternalNode[] entitiesToLayout) {
    // get maximum node size as percent of screen dimmensions
    double nodeSize = getNodeSize(entitiesToLayout);
    double halfNodeSize = nodeSize / 2;
    // Resize and shift nodes
    for (int i = 0; i < entitiesToLayout.length; i++) {
        InternalNode node = entitiesToLayout[i];
        node.setInternalSize(nodeSize, nodeSize);
        node.setInternalLocation(node.getInternalX() + halfNodeSize, node.getInternalY() + halfNodeSize);
    }
}
Also used : 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)

Example 17 with InternalNode

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

the class AbstractLayoutAlgorithm method createInternalRelationships.

/**
 * Creates a list of InternalRelationship objects from the given list of LayoutRelationship objects.
 * @param rels
 * @return List of internal relationships
 */
private InternalRelationship[] createInternalRelationships(LayoutRelationship[] rels) {
    ArrayList listOfInternalRelationships = new ArrayList(rels.length);
    for (int i = 0; i < rels.length; i++) {
        LayoutRelationship relation = rels[i];
        InternalNode src = (InternalNode) relation.getSourceInLayout().getLayoutInformation();
        InternalNode dest = (InternalNode) relation.getDestinationInLayout().getLayoutInformation();
        if ((src != null) && (dest != null)) {
            InternalRelationship internalRelationship = new InternalRelationship(relation, src, dest);
            listOfInternalRelationships.add(internalRelationship);
        } else {
            // $NON-NLS-1$ //$NON-NLS-2$
            throw new RuntimeException("Error creating internal relationship, one of the nodes is null: src=" + src + ", dest=" + dest);
        }
    }
    InternalRelationship[] internalRelationships = new InternalRelationship[listOfInternalRelationships.size()];
    listOfInternalRelationships.toArray(internalRelationships);
    return internalRelationships;
}
Also used : InternalRelationship(org.eclipse.zest.layouts.dataStructures.InternalRelationship) ArrayList(java.util.ArrayList) 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) LayoutRelationship(org.eclipse.zest.layouts.LayoutRelationship)

Example 18 with InternalNode

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

the class AbstractLayoutAlgorithm method createInternalNodes.

// public void run() {
// 
// if (started == true) {
// throw new RuntimeException("Layout has already run!");
// }
// started = true;
// //layoutStopped = false;
// isLayoutPaused = false;
// applyLayoutInternal(internalNodes, internalRelationships, internalX, internalY, internalWidth, internalHeight);
// stop();
// layoutStopped = true;
// isLayoutPaused = false;
// }
/**
 * Creates a list of InternalNode objects from the list of LayoutEntity objects the user
 * wants layed out. Sets the internal nodes' positions and sizes from the
 * external entities.
 */
private InternalNode[] createInternalNodes(LayoutEntity[] nodes) {
    InternalNode[] internalNodes = new InternalNode[nodes.length];
    BasicEntityConstraint basicEntityConstraint = new BasicEntityConstraint();
    for (int i = 0; i < nodes.length; i++) {
        basicEntityConstraint.clear();
        LayoutEntity externalNode = nodes[i];
        InternalNode internalNode = new InternalNode(externalNode);
        externalNode.populateLayoutConstraint(basicEntityConstraint);
        internalNode.setInternalLocation(externalNode.getXInLayout(), externalNode.getYInLayout());
        internalNodes[i] = internalNode;
    }
    // end of for
    return internalNodes;
}
Also used : BasicEntityConstraint(org.eclipse.zest.layouts.constraints.BasicEntityConstraint) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode) LayoutEntity(org.eclipse.zest.layouts.LayoutEntity) BasicEntityConstraint(org.eclipse.zest.layouts.constraints.BasicEntityConstraint) BendPoint(org.eclipse.zest.layouts.dataStructures.BendPoint) DisplayIndependentPoint(org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint)

Example 19 with InternalNode

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

the class AbstractLayoutAlgorithm method updateBendPoints.

/**
 * Update external bend points from the internal bendpoints list. Save the
 * source and destination points for later use in scaling and translating
 * @param relationshipsToConsider
 */
protected void updateBendPoints(InternalRelationship[] relationshipsToConsider) {
    for (int i = 0; i < relationshipsToConsider.length; i++) {
        InternalRelationship relationship = relationshipsToConsider[i];
        List bendPoints = relationship.getBendPoints();
        if (bendPoints.size() > 0) {
            // We will assume that source/dest coordinates are for center of node
            BendPoint[] externalBendPoints = new BendPoint[bendPoints.size() + 2];
            InternalNode sourceNode = relationship.getSource();
            externalBendPoints[0] = new BendPoint(sourceNode.getInternalX(), sourceNode.getInternalY());
            InternalNode destNode = relationship.getDestination();
            externalBendPoints[externalBendPoints.length - 1] = new BendPoint(destNode.getInternalX(), destNode.getInternalY());
            for (int j = 0; j < bendPoints.size(); j++) {
                BendPoint bp = (BendPoint) bendPoints.get(j);
                externalBendPoints[j + 1] = new BendPoint(bp.x, bp.y, bp.getIsControlPoint());
            }
            relationship.getLayoutRelationship().setBendPoints(externalBendPoints);
        }
    }
}
Also used : InternalRelationship(org.eclipse.zest.layouts.dataStructures.InternalRelationship) ArrayList(java.util.ArrayList) List(java.util.List) 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) BendPoint(org.eclipse.zest.layouts.dataStructures.BendPoint)

Example 20 with InternalNode

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

the class TreeLayoutAlgorithm method findRootObjectRecursive.

/**
 * Finds the root node that can be treated as the root of a tree.
 * The found root node should be one of the unmarked nodes.
 */
private InternalNode findRootObjectRecursive(InternalNode currentEntity, Set seenAlready, InternalRelationship[] relationshipsToConsider) {
    InternalNode rootEntity = null;
    InternalRelationship rel = findRelationship(currentEntity, AS_DESTINATION, relationshipsToConsider);
    if (rel == null) {
        rootEntity = currentEntity;
    } else {
        InternalNode parentEntity = rel.getSource();
        if (!seenAlready.contains(parentEntity)) {
            seenAlready.add(parentEntity);
            rootEntity = findRootObjectRecursive(parentEntity, seenAlready, relationshipsToConsider);
        } else {
            rootEntity = currentEntity;
        }
    }
    return rootEntity;
}
Also used : InternalRelationship(org.eclipse.zest.layouts.dataStructures.InternalRelationship) 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