Search in sources :

Example 1 with InvalidLayoutConfiguration

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

the class SimpleSWTExample method performLayout.

private void performLayout(boolean placeRandomly) {
    if (!continuous) {
    }
    if (currentLayoutAlgorithm.isRunning()) {
        throw new RuntimeException("Layout is already running");
    }
    if (placeRandomly) {
        placeRandomly();
    }
    ProgressListener progressListener = new ProgressListener() {

        int lastStep = 0;

        class progressSync implements Runnable {

            public static final int PROGRESS_UPDATED = 1;

            public static final int PROGRESS_STARTED = 2;

            public static final int PROGRESS_ENDED = 3;

            public static final int UPDATE_GUI = 4;

            private int progressState = -1;

            private ProgressEvent e;

            public progressSync(int progressState, final ProgressEvent e) {
                this.progressState = progressState;
                this.e = e;
            }

            @Override
            public void run() {
                switch(progressState) {
                    case PROGRESS_STARTED:
                        if (!continuous) {
                            pmd = new ProgressMonitorDialog(getShell());
                            progressMonitor = pmd.getProgressMonitor();
                            pmd.open();
                            progressMonitor.beginTask("Layout Running...", e.getTotalNumberOfSteps());
                        }
                        break;
                    case PROGRESS_UPDATED:
                        if (!continuous) {
                            progressMonitor.worked(e.getStepsCompleted() - lastStep);
                            lastStep = e.getStepsCompleted();
                        }
                        break;
                    case PROGRESS_ENDED:
                        if (!continuous) {
                            progressMonitor.done();
                            pmd.close();
                        }
                        updateGUI();
                        mainShell.redraw();
                        break;
                    case UPDATE_GUI:
                        updateGUI();
                        GUI_UPDATING = false;
                        break;
                }
                mainComposite.redraw();
            }
        }

        @Override
        public void progressUpdated(final ProgressEvent e) {
            if (asynchronously) {
                if (!mainComposite.isDisposed()) {
                    Display.getDefault().asyncExec(new progressSync(progressSync.PROGRESS_UPDATED, e));
                    if (!GUI_UPDATING) {
                        GUI_UPDATING = true;
                        Display.getDefault().asyncExec(new progressSync(progressSync.UPDATE_GUI, e));
                    }
                }
            } else {
                if (!mainComposite.isDisposed()) {
                    new progressSync(progressSync.PROGRESS_UPDATED, e).run();
                }
            }
        }

        @Override
        public void progressStarted(ProgressEvent e) {
            if (asynchronously) {
                if (!mainComposite.isDisposed()) {
                    Display.getDefault().asyncExec(new progressSync(progressSync.PROGRESS_STARTED, e));
                }
            } else {
                if (!mainComposite.isDisposed()) {
                    new progressSync(progressSync.PROGRESS_STARTED, e).run();
                }
            }
        }

        @Override
        public void progressEnded(ProgressEvent e) {
            if (asynchronously) {
                if (!mainComposite.isDisposed()) {
                    Display.getDefault().asyncExec(new progressSync(progressSync.PROGRESS_ENDED, e));
                }
            } else {
                if (!mainComposite.isDisposed()) {
                    new progressSync(progressSync.PROGRESS_ENDED, e).run();
                }
            }
            currentLayoutAlgorithm.removeProgressListener(this);
            Display.getDefault().asyncExec(new progressSync(progressSync.PROGRESS_UPDATED, e));
        }
    };
    currentLayoutAlgorithm.addProgressListener(progressListener);
    try {
        LayoutEntity[] layoutEntities = new LayoutEntity[entities.size()];
        entities.toArray(layoutEntities);
        LayoutRelationship[] layoutRelationships = new LayoutRelationship[relationships.size()];
        relationships.toArray(layoutRelationships);
        currentLayoutAlgorithm.applyLayout(layoutEntities, layoutRelationships, 0, 0, mainComposite.getClientArea().width - 30, mainComposite.getClientArea().height - 17, asynchronously, continuous);
        if (!animate) {
            updateGUI();
        }
    } catch (InvalidLayoutConfiguration e) {
        e.printStackTrace();
    }
}
Also used : ProgressListener(org.eclipse.zest.layouts.progress.ProgressListener) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) LayoutEntity(org.eclipse.zest.layouts.LayoutEntity) ProgressEvent(org.eclipse.zest.layouts.progress.ProgressEvent) Point(org.eclipse.swt.graphics.Point) LayoutBendPoint(org.eclipse.zest.layouts.LayoutBendPoint) LayoutRelationship(org.eclipse.zest.layouts.LayoutRelationship) InvalidLayoutConfiguration(org.eclipse.zest.layouts.InvalidLayoutConfiguration)

Example 2 with InvalidLayoutConfiguration

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

the class SimpleSwingExample method performLayout.

protected void performLayout() {
    stop();
    final Cursor cursor = mainFrame.getCursor();
    updateGUICount = 0;
    placeRandomly();
    final boolean continuous = btnContinuous.isSelected();
    final boolean asynchronous = btnAsynchronous.isSelected();
    ProgressListener progressListener = new ProgressListener() {

        @Override
        public void progressUpdated(final ProgressEvent e) {
            // if (asynchronous) {
            updateGUI();
            // }
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            lblProgress.setText("Progress: " + e.getStepsCompleted() + " of " + e.getTotalNumberOfSteps() + " completed ...");
            lblProgress.paintImmediately(0, 0, lblProgress.getWidth(), lblProgress.getHeight());
        }

        @Override
        public void progressStarted(ProgressEvent e) {
            if (!asynchronous) {
                mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            }
            // $NON-NLS-1$
            lblProgress.setText("Layout started ...");
            lblProgress.paintImmediately(0, 0, lblProgress.getWidth(), lblProgress.getHeight());
        }

        @Override
        public void progressEnded(ProgressEvent e) {
            // $NON-NLS-1$
            lblProgress.setText("Layout completed ...");
            lblProgress.paintImmediately(0, 0, lblProgress.getWidth(), lblProgress.getHeight());
            currentLayoutAlgorithm.removeProgressListener(this);
            if (!asynchronous) {
                mainFrame.setCursor(cursor);
            }
        }
    };
    currentLayoutAlgorithm.addProgressListener(progressListener);
    try {
        final LayoutEntity[] layoutEntities = new LayoutEntity[entities.size()];
        entities.toArray(layoutEntities);
        final LayoutRelationship[] layoutRelationships = new LayoutRelationship[relationships.size()];
        relationships.toArray(layoutRelationships);
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                try {
                    currentLayoutAlgorithm.applyLayout(layoutEntities, layoutRelationships, 0, 0, mainPanel.getWidth(), mainPanel.getHeight(), asynchronous, continuous);
                } catch (InvalidLayoutConfiguration e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });
        // if (!animate) {
        updateGUI();
        // }
        // reset
        currentNodeShape = DEFAULT_NODE_SHAPE;
    } catch (StackOverflowError e) {
        e.printStackTrace();
    } finally {
    }
}
Also used : ProgressListener(org.eclipse.zest.layouts.progress.ProgressListener) LayoutEntity(org.eclipse.zest.layouts.LayoutEntity) Cursor(java.awt.Cursor) ProgressEvent(org.eclipse.zest.layouts.progress.ProgressEvent) LayoutRelationship(org.eclipse.zest.layouts.LayoutRelationship) InvalidLayoutConfiguration(org.eclipse.zest.layouts.InvalidLayoutConfiguration)

Example 3 with InvalidLayoutConfiguration

use of org.eclipse.zest.layouts.InvalidLayoutConfiguration 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 4 with InvalidLayoutConfiguration

use of org.eclipse.zest.layouts.InvalidLayoutConfiguration 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)

Aggregations

InvalidLayoutConfiguration (org.eclipse.zest.layouts.InvalidLayoutConfiguration)4 LayoutEntity (org.eclipse.zest.layouts.LayoutEntity)4 LayoutRelationship (org.eclipse.zest.layouts.LayoutRelationship)4 Dimension (org.eclipse.draw2d.geometry.Dimension)2 Point (org.eclipse.draw2d.geometry.Point)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 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 Point (org.eclipse.swt.graphics.Point)1 LayoutBendPoint (org.eclipse.zest.layouts.LayoutBendPoint)1 LayoutConstraint (org.eclipse.zest.layouts.constraints.LayoutConstraint)1