use of org.eclipse.zest.layouts.LayoutRelationship 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.LayoutRelationship 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.LayoutRelationship in project archi by archimatetool.
the class CycleChecker method hasDirectedCircles.
/**
* Tests if there is a directed cirlce in the graph formed by the given entities and relationships.
* @param entities The entities in the graph to check
* @param relationships The relationships in the graph to check
* @param cycle Populated with the cycle encountered, if there is one.
* @throws RuntimeException Thrown if entities doesn't contain all of the endpoints for each relationship in relationships
* @return <code>true</code> if there is a directed circle.
* Otherwise, <code>false</code>.
*/
public static boolean hasDirectedCircles(LayoutEntity[] entities, LayoutRelationship[] relationships, List cycle) {
if (!AbstractLayoutAlgorithm.verifyInput(entities, relationships)) {
// $NON-NLS-1$
throw new RuntimeException("The endpoints of the relationships aren't contained in the entities list.");
}
// Enumeration enum;
// Iterator iterator;
Hashtable endPoints = new Hashtable();
// Initialize the relation(transitive) vector.
for (int i = 0; i < relationships.length; i++) {
LayoutRelationship rel = relationships[i];
// Add the relationship to the source endpoint
Object subject = rel.getSourceInLayout();
List rels = (List) endPoints.get(subject);
if (rels == null) {
rels = new ArrayList();
endPoints.put(subject, rels);
}
if (!rels.contains(rel))
rels.add(rel);
}
boolean hasCyle = hasCycle(new ArrayList(Arrays.asList(entities)), endPoints, cycle);
return hasCyle;
}
use of org.eclipse.zest.layouts.LayoutRelationship in project archi by archimatetool.
the class AbstractLayoutAlgorithm method updateRelationships.
/**
* Updates the given array of relationships checking if any need to be removed or added.
* Also updates the original array of relationships.
* @param relationships the current relationships
* @return the update relationships array
*/
protected InternalRelationship[] updateRelationships(InternalRelationship[] relationships) {
if ((relationshipsToRemove.size() > 0) || (relationshipsToAdd.size() > 0)) {
List internalRelsList = new ArrayList(Arrays.asList(relationships));
// remove relationships
if (relationshipsToRemove.size() > 0) {
for (Iterator iter = relationshipsToRemove.iterator(); iter.hasNext(); ) {
LayoutRelationship relation = (LayoutRelationship) iter.next();
if (relation.getLayoutInformation() != null) {
internalRelsList.remove(relation.getLayoutInformation());
}
}
}
// Also remove from _internalRelationships
ArrayList updatedRelationships = new ArrayList(internalRelationships.length - relationshipsToRemove.size() + relationshipsToAdd.size());
for (int i = 0; i < internalRelationships.length; i++) {
InternalRelationship relation = internalRelationships[i];
if (relationshipsToRemove.contains(relation.getLayoutRelationship())) {
relationshipsToRemove.remove(relation.getLayoutRelationship());
} else {
updatedRelationships.add(relation);
}
}
relationshipsToRemove.clear();
// add relationships
if (relationshipsToAdd.size() > 0) {
LayoutRelationship[] relsArray = new LayoutRelationship[relationshipsToAdd.size()];
relsArray = (LayoutRelationship[]) relationshipsToAdd.toArray(relsArray);
InternalRelationship[] newRelationships = createInternalRelationships(relsArray);
for (int i = 0; i < newRelationships.length; i++) {
internalRelsList.add(newRelationships[i]);
updatedRelationships.add(newRelationships[i]);
}
}
relationshipsToAdd.clear();
relationships = new InternalRelationship[internalRelsList.size()];
relationships = (InternalRelationship[]) internalRelsList.toArray(relationships);
internalRelationships = new InternalRelationship[updatedRelationships.size()];
internalRelationships = (InternalRelationship[]) updatedRelationships.toArray(internalRelationships);
}
return relationships;
}
use of org.eclipse.zest.layouts.LayoutRelationship in project archi by archimatetool.
the class AbstractLayoutAlgorithm method createInternalRelationships.
/**
* Creates a list of InternalRelationship objects from the given list of LayoutRelationship objects.
* @param rels
* @return List of internal relationships
*/
private InternalRelationship[] createInternalRelationships(LayoutRelationship[] rels) {
ArrayList listOfInternalRelationships = new ArrayList(rels.length);
for (int i = 0; i < rels.length; i++) {
LayoutRelationship relation = rels[i];
InternalNode src = (InternalNode) relation.getSourceInLayout().getLayoutInformation();
InternalNode dest = (InternalNode) relation.getDestinationInLayout().getLayoutInformation();
if ((src != null) && (dest != null)) {
InternalRelationship internalRelationship = new InternalRelationship(relation, src, dest);
listOfInternalRelationships.add(internalRelationship);
} else {
// $NON-NLS-1$ //$NON-NLS-2$
throw new RuntimeException("Error creating internal relationship, one of the nodes is null: src=" + src + ", dest=" + dest);
}
}
InternalRelationship[] internalRelationships = new InternalRelationship[listOfInternalRelationships.size()];
listOfInternalRelationships.toArray(internalRelationships);
return internalRelationships;
}
Aggregations