use of org.eclipse.zest.layouts.LayoutEntity 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.LayoutEntity 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.LayoutEntity in project archi by archimatetool.
the class SimpleSwingExample method createTreeGraph.
/**
* @param maxLevels Max number of levels wanted in tree
* @param maxChildren Max number of children for each node in the tree
* @param randomNumChildren Whether or not to pick random number of levels (from 1 to maxLevels) and
* random number of children (from 1 to maxChildren)
*/
private void createTreeGraph(int minChildren, int maxChildren, int minLevels, int maxLevels, boolean randomNumChildren, boolean randomLevels, boolean addNonTreeRels) {
LayoutEntity currentParent = createSimpleNode(getNextID());
entities.add(currentParent);
createTreeGraphRecursive(currentParent, minChildren, maxChildren, minLevels, maxLevels, 1, randomNumChildren, randomLevels, addNonTreeRels);
}
use of org.eclipse.zest.layouts.LayoutEntity in project archi by archimatetool.
the class AbstractLayoutAlgorithm method updateEntities.
/**
* Updates the given array of entities checking if any need to be removed or added.
* @param entities the current entities
* @return the updated entities array
*/
protected InternalNode[] updateEntities(InternalNode[] entities) {
if ((entitiesToRemove.size() > 0) || (entitiesToAdd.size() > 0)) {
List internalNodesList = new ArrayList(Arrays.asList(entities));
// remove nodes
for (Iterator iter = entitiesToRemove.iterator(); iter.hasNext(); ) {
LayoutEntity entity = (LayoutEntity) iter.next();
if (entity.getLayoutInformation() != null) {
internalNodesList.remove(entity.getLayoutInformation());
}
}
// Also remove from _internalNodes
ArrayList updatedEntities = new ArrayList(internalNodes.length - entitiesToRemove.size() + entitiesToAdd.size());
for (int i = 0; i < internalNodes.length; i++) {
InternalNode node = internalNodes[i];
if (entitiesToRemove.contains(node.getLayoutEntity())) {
entitiesToRemove.remove(node.getLayoutEntity());
} else {
updatedEntities.add(node);
}
}
entitiesToRemove.clear();
// Add any new nodes
LayoutEntity[] entitiesArray = new LayoutEntity[entitiesToAdd.size()];
entitiesArray = (LayoutEntity[]) entitiesToAdd.toArray(entitiesArray);
InternalNode[] newNodes = createInternalNodes(entitiesArray);
for (int i = 0; i < newNodes.length; i++) {
internalNodesList.add(newNodes[i]);
updatedEntities.add(newNodes[i]);
}
entitiesToAdd.clear();
entities = new InternalNode[internalNodesList.size()];
entities = (InternalNode[]) internalNodesList.toArray(entities);
internalNodes = new InternalNode[updatedEntities.size()];
internalNodes = (InternalNode[]) updatedEntities.toArray(internalNodes);
}
return entities;
}
use of org.eclipse.zest.layouts.LayoutEntity in project archi by archimatetool.
the class AbstractLayoutAlgorithm method createInternalNodes.
// public void run() {
//
// if (started == true) {
// throw new RuntimeException("Layout has already run!");
// }
// started = true;
// //layoutStopped = false;
// isLayoutPaused = false;
// applyLayoutInternal(internalNodes, internalRelationships, internalX, internalY, internalWidth, internalHeight);
// stop();
// layoutStopped = true;
// isLayoutPaused = false;
// }
/**
* Creates a list of InternalNode objects from the list of LayoutEntity objects the user
* wants layed out. Sets the internal nodes' positions and sizes from the
* external entities.
*/
private InternalNode[] createInternalNodes(LayoutEntity[] nodes) {
InternalNode[] internalNodes = new InternalNode[nodes.length];
BasicEntityConstraint basicEntityConstraint = new BasicEntityConstraint();
for (int i = 0; i < nodes.length; i++) {
basicEntityConstraint.clear();
LayoutEntity externalNode = nodes[i];
InternalNode internalNode = new InternalNode(externalNode);
externalNode.populateLayoutConstraint(basicEntityConstraint);
internalNode.setInternalLocation(externalNode.getXInLayout(), externalNode.getYInLayout());
internalNodes[i] = internalNode;
}
// end of for
return internalNodes;
}
Aggregations