Search in sources :

Example 6 with LayoutEntity

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();
    }
}
Also used : TreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm) Dimension(org.eclipse.draw2d.geometry.Dimension) LayoutEntity(org.eclipse.zest.layouts.LayoutEntity) Point(org.eclipse.draw2d.geometry.Point) LayoutConstraint(org.eclipse.zest.layouts.constraints.LayoutConstraint) LayoutRelationship(org.eclipse.zest.layouts.LayoutRelationship) InvalidLayoutConfiguration(org.eclipse.zest.layouts.InvalidLayoutConfiguration)

Example 7 with LayoutEntity

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;
}
Also used : Iterator(java.util.Iterator) LayoutEntity(org.eclipse.zest.layouts.LayoutEntity) LinkedList(java.util.LinkedList)

Example 8 with LayoutEntity

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();
    }
}
Also used : TreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm) Dimension(org.eclipse.draw2d.geometry.Dimension) LayoutEntity(org.eclipse.zest.layouts.LayoutEntity) Point(org.eclipse.draw2d.geometry.Point) LayoutRelationship(org.eclipse.zest.layouts.LayoutRelationship) InvalidLayoutConfiguration(org.eclipse.zest.layouts.InvalidLayoutConfiguration)

Example 9 with LayoutEntity

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();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) LayoutEntity(org.eclipse.zest.layouts.LayoutEntity) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode) Comparator(java.util.Comparator)

Example 10 with LayoutEntity

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;
}
Also used : 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) LayoutRelationship(org.eclipse.zest.layouts.LayoutRelationship)

Aggregations

LayoutEntity (org.eclipse.zest.layouts.LayoutEntity)11 LayoutRelationship (org.eclipse.zest.layouts.LayoutRelationship)6 InvalidLayoutConfiguration (org.eclipse.zest.layouts.InvalidLayoutConfiguration)4 Iterator (java.util.Iterator)3 BasicEntityConstraint (org.eclipse.zest.layouts.constraints.BasicEntityConstraint)3 BendPoint (org.eclipse.zest.layouts.dataStructures.BendPoint)3 DisplayIndependentPoint (org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint)3 InternalNode (org.eclipse.zest.layouts.dataStructures.InternalNode)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Dimension (org.eclipse.draw2d.geometry.Dimension)2 Point (org.eclipse.draw2d.geometry.Point)2 LayoutBendPoint (org.eclipse.zest.layouts.LayoutBendPoint)2 TreeLayoutAlgorithm (org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm)2 ProgressEvent (org.eclipse.zest.layouts.progress.ProgressEvent)2 ProgressListener (org.eclipse.zest.layouts.progress.ProgressListener)2 Cursor (java.awt.Cursor)1 Point (java.awt.Point)1 Comparator (java.util.Comparator)1 LinkedList (java.util.LinkedList)1