use of org.eclipse.zest.layouts.dataStructures.InternalRelationship in project archi by archimatetool.
the class DirectedGraphLayoutAlgorithm method applyLayoutInternal.
@Override
protected void applyLayoutInternal(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider, double boundsX, double boundsY, double boundsWidth, double boundsHeight) {
HashMap mapping = new HashMap(entitiesToLayout.length);
DirectedGraph graph = new DirectedGraph();
for (int i = 0; i < entitiesToLayout.length; i++) {
InternalNode internalNode = entitiesToLayout[i];
Node node = new Node(internalNode);
node.setSize(new Dimension(10, 10));
mapping.put(internalNode, node);
graph.nodes.add(node);
}
for (int i = 0; i < relationshipsToConsider.length; i++) {
InternalRelationship relationship = relationshipsToConsider[i];
Node source = (Node) mapping.get(relationship.getSource());
Node dest = (Node) mapping.get(relationship.getDestination());
Edge edge = new Edge(relationship, source, dest);
graph.edges.add(edge);
}
DirectedGraphLayout directedGraphLayout = new ExtendedDirectedGraphLayout();
directedGraphLayout.visit(graph);
for (Iterator iterator = graph.nodes.iterator(); iterator.hasNext(); ) {
Node node = (Node) iterator.next();
InternalNode internalNode = (InternalNode) node.data;
// For horizontal layout transpose the x and y coordinates
if ((layout_styles & SWT.HORIZONTAL) == SWT.HORIZONTAL) {
internalNode.setInternalLocation(node.y, node.x);
} else {
internalNode.setInternalLocation(node.x, node.y);
}
}
updateLayoutLocations(entitiesToLayout);
}
use of org.eclipse.zest.layouts.dataStructures.InternalRelationship in project archi by archimatetool.
the class SpringLayoutAlgorithm method preLayoutAlgorithm.
@Override
protected void preLayoutAlgorithm(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider, double x, double y, double width, double height) {
// TODO: Filter out any non-wanted entities and relationships
// super.applyLayout(entitiesToLayout, relationshipsToConsider, x, y,
// width, height);
// InternalNode[] a_entitiesToLayout = (InternalNode[]) entitiesToLayout.toArray(new InternalNode[entitiesToLayout.size()]);
bounds = new DisplayIndependentRectangle(x, y, width, height);
tempLocationsX = new double[entitiesToLayout.length];
tempLocationsY = new double[entitiesToLayout.length];
forcesX = new double[entitiesToLayout.length];
forcesY = new double[entitiesToLayout.length];
anchors = new boolean[entitiesToLayout.length];
for (int i = 0; i < entitiesToLayout.length; i++) {
anchors[i] = DEFAULT_ANCHOR;
}
for (int i = 0; i < relationshipsToConsider.length; i++) {
InternalRelationship layoutRelationship = relationshipsToConsider[i];
addRelation(layoutRelationship);
}
// do the calculations
preCompute(entitiesToLayout);
startTime = date.getTime();
}
use of org.eclipse.zest.layouts.dataStructures.InternalRelationship in project archi by archimatetool.
the class AbstractLayoutAlgorithm method convertPositionsToCoords.
/**
* Convert the positions from a percentage of bounds area to fixed
* coordinates. NOTE: ALL OF THE POSITIONS OF NODES UNTIL NOW WERE FOR THE
* CENTER OF THE NODE - Convert it to the left top corner.
*
* @param entitiesToLayout
* @param relationships
* @param realBounds
*/
private void convertPositionsToCoords(InternalNode[] entitiesToLayout, InternalRelationship[] relationships, DisplayIndependentRectangle screenBounds) {
// Adjust node positions and sizes
for (int i = 0; i < entitiesToLayout.length; i++) {
InternalNode node = entitiesToLayout[i];
double width = node.getInternalWidth() * screenBounds.width;
double height = node.getInternalHeight() * screenBounds.height;
DisplayIndependentPoint location = node.getInternalLocation().convertFromPercent(screenBounds);
node.setInternalLocation(location.x - width / 2, location.y - height / 2);
if (resizeEntitiesAfterLayout) {
adjustNodeSizeAndPos(node, height, width);
} else {
node.setInternalSize(width, height);
}
}
// Adjust bendpoint positions and shift based on source node size
for (int i = 0; i < relationships.length; i++) {
InternalRelationship rel = relationships[i];
for (int j = 0; j < rel.getBendPoints().size(); j++) {
BendPoint bp = (BendPoint) rel.getBendPoints().get(j);
DisplayIndependentPoint fromPercent = bp.convertFromPercent(screenBounds);
bp.setX(fromPercent.x);
bp.setY(fromPercent.y);
}
}
}
use of org.eclipse.zest.layouts.dataStructures.InternalRelationship in project archi by archimatetool.
the class AbstractLayoutAlgorithm method convertPositionsToPercentage.
/**
* Convert all node positions into a percentage of the screen. If includeNodeSize
* is true then this also updates the node's internal size.
* @param entitiesToLayout
*/
private void convertPositionsToPercentage(InternalNode[] entitiesToLayout, InternalRelationship[] relationships, DisplayIndependentRectangle layoutBounds, boolean includeNodeSize) {
// Adjust node positions and sizes
for (int i = 0; i < entitiesToLayout.length; i++) {
InternalNode node = entitiesToLayout[i];
DisplayIndependentPoint location = node.getInternalLocation().convertToPercent(layoutBounds);
node.setInternalLocation(location.x, location.y);
if (includeNodeSize) {
// adjust node sizes
double width = node.getInternalWidth() / layoutBounds.width;
double height = node.getInternalHeight() / layoutBounds.height;
node.setInternalSize(width, height);
}
}
// Adjust bendpoint positions
for (int i = 0; i < relationships.length; i++) {
InternalRelationship rel = relationships[i];
for (int j = 0; j < rel.getBendPoints().size(); j++) {
BendPoint bp = (BendPoint) rel.getBendPoints().get(j);
DisplayIndependentPoint toPercent = bp.convertToPercent(layoutBounds);
bp.setX(toPercent.x);
bp.setY(toPercent.y);
}
}
}
use of org.eclipse.zest.layouts.dataStructures.InternalRelationship in project archi by archimatetool.
the class AbstractLayoutAlgorithm method updateRelationships.
/**
* Updates the given array of relationships checking if any need to be removed or added.
* Also updates the original array of relationships.
* @param relationships the current relationships
* @return the update relationships array
*/
protected InternalRelationship[] updateRelationships(InternalRelationship[] relationships) {
if ((relationshipsToRemove.size() > 0) || (relationshipsToAdd.size() > 0)) {
List internalRelsList = new ArrayList(Arrays.asList(relationships));
// remove relationships
if (relationshipsToRemove.size() > 0) {
for (Iterator iter = relationshipsToRemove.iterator(); iter.hasNext(); ) {
LayoutRelationship relation = (LayoutRelationship) iter.next();
if (relation.getLayoutInformation() != null) {
internalRelsList.remove(relation.getLayoutInformation());
}
}
}
// Also remove from _internalRelationships
ArrayList updatedRelationships = new ArrayList(internalRelationships.length - relationshipsToRemove.size() + relationshipsToAdd.size());
for (int i = 0; i < internalRelationships.length; i++) {
InternalRelationship relation = internalRelationships[i];
if (relationshipsToRemove.contains(relation.getLayoutRelationship())) {
relationshipsToRemove.remove(relation.getLayoutRelationship());
} else {
updatedRelationships.add(relation);
}
}
relationshipsToRemove.clear();
// add relationships
if (relationshipsToAdd.size() > 0) {
LayoutRelationship[] relsArray = new LayoutRelationship[relationshipsToAdd.size()];
relsArray = (LayoutRelationship[]) relationshipsToAdd.toArray(relsArray);
InternalRelationship[] newRelationships = createInternalRelationships(relsArray);
for (int i = 0; i < newRelationships.length; i++) {
internalRelsList.add(newRelationships[i]);
updatedRelationships.add(newRelationships[i]);
}
}
relationshipsToAdd.clear();
relationships = new InternalRelationship[internalRelsList.size()];
relationships = (InternalRelationship[]) internalRelsList.toArray(relationships);
internalRelationships = new InternalRelationship[updatedRelationships.size()];
internalRelationships = (InternalRelationship[]) updatedRelationships.toArray(internalRelationships);
}
return relationships;
}
Aggregations