use of org.eclipse.zest.layouts.LayoutEntity in project archi by archimatetool.
the class Graph method applyLayoutInternal.
private void applyLayoutInternal() {
hasPendingLayoutRequest = false;
if ((this.getNodes().size() == 0)) {
return;
}
int layoutStyle = 0;
if ((nodeStyle & ZestStyles.NODES_NO_LAYOUT_RESIZE) > 0) {
layoutStyle = LayoutStyles.NO_LAYOUT_NODE_RESIZING;
}
if (layoutAlgorithm == null) {
layoutAlgorithm = new TreeLayoutAlgorithm(layoutStyle);
}
layoutAlgorithm.setStyle(layoutAlgorithm.getStyle() | layoutStyle);
// calculate the size for the layout algorithm
Dimension d = this.getViewport().getSize();
d.width = d.width - 10;
d.height = d.height - 10;
if (this.preferredSize.width >= 0) {
d.width = preferredSize.width;
}
if (this.preferredSize.height >= 0) {
d.height = preferredSize.height;
}
if (d.isEmpty()) {
return;
}
LayoutRelationship[] connectionsToLayout = getConnectionsToLayout(nodes);
LayoutEntity[] nodesToLayout = getNodesToLayout(getNodes());
try {
if ((nodeStyle & ZestStyles.NODES_NO_LAYOUT_ANIMATION) == 0 && animationEnabled) {
Animation.markBegin();
}
layoutAlgorithm.applyLayout(nodesToLayout, connectionsToLayout, 0, 0, d.width, d.height, false, false);
if ((nodeStyle & ZestStyles.NODES_NO_LAYOUT_ANIMATION) == 0 && animationEnabled) {
Animation.run(animationTime);
}
getLightweightSystem().getUpdateManager().performUpdate();
} catch (InvalidLayoutConfiguration e) {
e.printStackTrace();
}
}
use of org.eclipse.zest.layouts.LayoutEntity in project archi by archimatetool.
the class Graph method getNodesToLayout.
LayoutEntity[] getNodesToLayout(List nodes) {
// @tag zest.bug.156528-Filters.follows : make sure not to layout
// filtered nodes, if the style says so.
LayoutEntity[] entities;
if (ZestStyles.checkStyle(style, ZestStyles.IGNORE_INVISIBLE_LAYOUT)) {
LinkedList nodeList = new LinkedList();
for (Iterator i = nodes.iterator(); i.hasNext(); ) {
GraphNode next = (GraphNode) i.next();
if (next.isVisible()) {
nodeList.add(next.getLayoutEntity());
}
}
entities = (LayoutEntity[]) nodeList.toArray(new LayoutEntity[] {});
} else {
LinkedList nodeList = new LinkedList();
for (Iterator i = nodes.iterator(); i.hasNext(); ) {
GraphNode next = (GraphNode) i.next();
nodeList.add(next.getLayoutEntity());
}
entities = (LayoutEntity[]) nodeList.toArray(new LayoutEntity[] {});
}
return entities;
}
use of org.eclipse.zest.layouts.LayoutEntity in project archi by archimatetool.
the class GraphContainer method applyLayout.
@Override
public void applyLayout() {
if ((this.getNodes().size() == 0)) {
return;
}
int layoutStyle = 0;
if (checkStyle(ZestStyles.NODES_NO_LAYOUT_RESIZE)) {
layoutStyle = LayoutStyles.NO_LAYOUT_NODE_RESIZING;
}
if (layoutAlgorithm == null) {
layoutAlgorithm = new TreeLayoutAlgorithm(layoutStyle);
}
layoutAlgorithm.setStyle(layoutAlgorithm.getStyle() | layoutStyle);
// calculate the size for the layout algorithm
// Dimension d = this.scalledLayer.getSize();
Dimension d = new Dimension();
d.width = (int) scaledWidth;
d.height = (int) scaledHeight;
d.width = d.width - 10;
d.height = d.height - 10;
if (d.isEmpty()) {
return;
}
LayoutRelationship[] connectionsToLayout = getGraph().getConnectionsToLayout(getNodes());
LayoutEntity[] nodesToLayout = getGraph().getNodesToLayout(getNodes());
try {
Animation.markBegin();
layoutAlgorithm.applyLayout(nodesToLayout, connectionsToLayout, 25, 25, d.width - 50, d.height - 50, false, false);
Animation.run(ANIMATION_TIME);
getFigure().getUpdateManager().performUpdate();
} catch (InvalidLayoutConfiguration e) {
e.printStackTrace();
}
}
use of org.eclipse.zest.layouts.LayoutEntity 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();
}
}
}
use of org.eclipse.zest.layouts.LayoutEntity in project archi by archimatetool.
the class AbstractLayoutAlgorithm method verifyInput.
/**
* Verifies the endpoints of the relationships are entities in the entitiesToLayout list.
* Allows other classes in this package to use this method to verify the input
*/
public static boolean verifyInput(LayoutEntity[] entitiesToLayout, LayoutRelationship[] relationshipsToConsider) {
boolean stillValid = true;
for (int i = 0; i < relationshipsToConsider.length; i++) {
LayoutRelationship relationship = relationshipsToConsider[i];
LayoutEntity source = relationship.getSourceInLayout();
LayoutEntity destination = relationship.getDestinationInLayout();
boolean containsSrc = false;
boolean containsDest = false;
int j = 0;
while (j < entitiesToLayout.length && !(containsSrc && containsDest)) {
if (entitiesToLayout[j].equals(source)) {
containsSrc = true;
}
if (entitiesToLayout[j].equals(destination)) {
containsDest = true;
}
j++;
}
stillValid = containsSrc && containsDest;
}
return stillValid;
}
Aggregations