use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.
the class DynamicScreen method calculateBounds.
private DisplayIndependentRectangle calculateBounds() {
InternalNode n1 = (InternalNode) XCoords.first();
InternalNode n2 = (InternalNode) XCoords.last();
InternalNode n3 = (InternalNode) YCoords.first();
InternalNode n4 = (InternalNode) YCoords.last();
double x = n1.getInternalX();
double width = n2.getInternalX();
double y = n3.getInternalY();
double height = n4.getInternalY();
return new DisplayIndependentRectangle(x, y, width - x, height - y);
}
use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.
the class AbstractLayoutAlgorithm method convertPositionsToCoords.
/**
* Convert the positions from a percentage of bounds area to fixed
* coordinates. NOTE: ALL OF THE POSITIONS OF NODES UNTIL NOW WERE FOR THE
* CENTER OF THE NODE - Convert it to the left top corner.
*
* @param entitiesToLayout
* @param relationships
* @param realBounds
*/
private void convertPositionsToCoords(InternalNode[] entitiesToLayout, InternalRelationship[] relationships, DisplayIndependentRectangle screenBounds) {
// Adjust node positions and sizes
for (int i = 0; i < entitiesToLayout.length; i++) {
InternalNode node = entitiesToLayout[i];
double width = node.getInternalWidth() * screenBounds.width;
double height = node.getInternalHeight() * screenBounds.height;
DisplayIndependentPoint location = node.getInternalLocation().convertFromPercent(screenBounds);
node.setInternalLocation(location.x - width / 2, location.y - height / 2);
if (resizeEntitiesAfterLayout) {
adjustNodeSizeAndPos(node, height, width);
} else {
node.setInternalSize(width, height);
}
}
// Adjust bendpoint positions and shift based on source node size
for (int i = 0; i < relationships.length; i++) {
InternalRelationship rel = relationships[i];
for (int j = 0; j < rel.getBendPoints().size(); j++) {
BendPoint bp = (BendPoint) rel.getBendPoints().get(j);
DisplayIndependentPoint fromPercent = bp.convertFromPercent(screenBounds);
bp.setX(fromPercent.x);
bp.setY(fromPercent.y);
}
}
}
use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.
the class AbstractLayoutAlgorithm method convertPositionsToPercentage.
/**
* Convert all node positions into a percentage of the screen. If includeNodeSize
* is true then this also updates the node's internal size.
* @param entitiesToLayout
*/
private void convertPositionsToPercentage(InternalNode[] entitiesToLayout, InternalRelationship[] relationships, DisplayIndependentRectangle layoutBounds, boolean includeNodeSize) {
// Adjust node positions and sizes
for (int i = 0; i < entitiesToLayout.length; i++) {
InternalNode node = entitiesToLayout[i];
DisplayIndependentPoint location = node.getInternalLocation().convertToPercent(layoutBounds);
node.setInternalLocation(location.x, location.y);
if (includeNodeSize) {
// adjust node sizes
double width = node.getInternalWidth() / layoutBounds.width;
double height = node.getInternalHeight() / layoutBounds.height;
node.setInternalSize(width, height);
}
}
// Adjust bendpoint positions
for (int i = 0; i < relationships.length; i++) {
InternalRelationship rel = relationships[i];
for (int j = 0; j < rel.getBendPoints().size(); j++) {
BendPoint bp = (BendPoint) rel.getBendPoints().get(j);
DisplayIndependentPoint toPercent = bp.convertToPercent(layoutBounds);
bp.setX(toPercent.x);
bp.setY(toPercent.y);
}
}
}
use of org.eclipse.zest.layouts.dataStructures.InternalNode 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.dataStructures.InternalNode in project archi by archimatetool.
the class AbstractLayoutAlgorithm method getMinimumDistance.
/**
* minDistance is the closest that any two points are together.
* These two points become the center points for the two closest nodes,
* which we wish to make them as big as possible without overlapping.
* This will be the maximum of minDistanceX and minDistanceY minus a bit, lets say 20%
*
* We make the recommended node size a square for convenience.
*
* _______
* | |
* | |
* | + |
* | |\ |
* |___|_\_|_____
* | | \ |
* | | \ |
* +-|---+ |
* | |
* |_______|
*/
private DisplayIndependentDimension getMinimumDistance(InternalNode[] entitiesToLayout) {
DisplayIndependentDimension horAndVertdistance = new DisplayIndependentDimension(Double.MAX_VALUE, Double.MAX_VALUE);
// the minimum distance between all the nodes
double minDistance = Double.MAX_VALUE;
// TODO: Very Slow!
for (int i = 0; i < entitiesToLayout.length; i++) {
InternalNode layoutEntity1 = entitiesToLayout[i];
double x1 = layoutEntity1.getInternalX();
double y1 = layoutEntity1.getInternalY();
for (int j = i + 1; j < entitiesToLayout.length; j++) {
InternalNode layoutEntity2 = entitiesToLayout[j];
double x2 = layoutEntity2.getInternalX();
double y2 = layoutEntity2.getInternalY();
double distanceX = Math.abs(x1 - x2);
double distanceY = Math.abs(y1 - y2);
double distance = Math.sqrt(Math.pow(distanceX, 2) + Math.pow(distanceY, 2));
if (distance < minDistance) {
minDistance = distance;
horAndVertdistance.width = distanceX;
horAndVertdistance.height = distanceY;
}
}
}
return horAndVertdistance;
}
Aggregations