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