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