use of org.eclipse.draw2d.geometry.PointList in project knime-core by knime.
the class ConnectionBendpointEditPolicy method setReferencePoints.
private void setReferencePoints(final BendpointRequest request) {
PointList points = getConnection().getPoints();
int bpIndex = -1;
List bendPoints = (List) getConnection().getRoutingConstraint();
Point bp = ((Bendpoint) bendPoints.get(request.getIndex())).getLocation();
int smallestDistance = -1;
for (int i = 0; i < points.size(); i++) {
if (smallestDistance == -1 || points.getPoint(i).getDistance2(bp) < smallestDistance) {
bpIndex = i;
smallestDistance = points.getPoint(i).getDistance2(bp);
if (smallestDistance == 0) {
break;
}
}
}
if (bpIndex > 0) {
points.getPoint(REF1, bpIndex - 1);
}
getConnection().translateToAbsolute(REF1);
if (bpIndex < points.size() - 1) {
points.getPoint(REF2, bpIndex + 1);
}
getConnection().translateToAbsolute(REF2);
}
use of org.eclipse.draw2d.geometry.PointList in project knime-core by knime.
the class NodeOutPortFigure method createShapePoints.
/**
* Create a point list for the triangular figure (a polygon).
*
* @param r The bounds
* @return the pointlist (size=3) {@inheritDoc}
*/
@Override
protected PointList createShapePoints(final Rectangle r) {
if (getType().equals(BufferedDataTable.TYPE)) {
PointList points = new PointList(3);
points.addPoint(new Point(r.x, r.y));
points.addPoint(new Point(r.x + r.width - 1, r.y + ((r.height) / 2) - 1));
points.addPoint(new Point(r.x, r.y + r.height - 1));
return points;
}
PointList points = new PointList(4);
points.addPoint(new Point(r.x, r.y));
points.addPoint(new Point(r.x + r.width - 1, r.y));
points.addPoint(new Point(r.x + r.width - 1, r.y + r.height - 1));
points.addPoint(new Point(r.x, r.y + r.height - 1));
return points;
}
use of org.eclipse.draw2d.geometry.PointList in project knime-core by knime.
the class WorkflowInPortFigure method createShapePoints.
/**
* {@inheritDoc}
*/
@Override
protected PointList createShapePoints(final Rectangle r) {
Rectangle rect = getBounds().getCopy();
if (getType().equals(BufferedDataTable.TYPE)) {
// triangle
PointList list = new PointList(3);
list.addPoint(rect.x, rect.y);
list.addPoint(rect.x + rect.width, rect.y + (rect.height / 2));
list.addPoint(rect.x, rect.y + rect.height);
return list;
} else {
// square
PointList list = new PointList(4);
list.addPoint(new Point(rect.x, rect.y));
list.addPoint(new Point(rect.x + rect.width, rect.y));
list.addPoint(new Point(rect.x + rect.width, rect.y + rect.height));
list.addPoint(new Point(rect.x, rect.y + rect.height));
return list;
}
}
use of org.eclipse.draw2d.geometry.PointList in project knime-core by knime.
the class SnapToPortGeometry method populateRowsAndCols.
/**
* Updates the cached row and column Entries using the provided parts.
* Columns are only the center of a node figure while rows are all ports of
* a node.
*
* @param parts a List of EditParts
*/
protected void populateRowsAndCols(final List parts, final List dragedParts) {
// add the port edit parts to a list
List<AbstractPortEditPart> portList = getPorts(parts);
// create all row relevant points fromt the port list
List<Entry> rowVector = new ArrayList<Entry>();
for (int i = 0; i < portList.size(); i++) {
GraphicalEditPart child = portList.get(i);
Rectangle bounds = getFigureBounds(child);
// get information is this is an inport
boolean inport = false;
if (portList.get(i) instanceof NodeInPortEditPart || portList.get(i) instanceof WorkflowInPortEditPart) {
inport = true;
}
// get information is this is a model port
rowVector.add(new Entry(0, bounds.y + (bounds.height - 1) / 2, inport, portList.get(i).getType()));
}
// add the port edit parts to a list
List<AbstractPortEditPart> dargedPortList = getPorts(dragedParts);
for (int i = 0; i < dargedPortList.size(); i++) {
// for each port get a possible connection (if connected)
AbstractPortEditPart portPart = dargedPortList.get(i);
List sourceConnections = portPart.getSourceConnections();
for (int j = 0; j < sourceConnections.size(); j++) {
ConnectionContainerEditPart conPart = (ConnectionContainerEditPart) sourceConnections.get(j);
Point p = ((Connection) conPart.getFigure()).getPoints().getPoint(2);
rowVector.add(new Entry(0, p.y, true, portPart.getType()));
}
List targetConnections = portPart.getTargetConnections();
for (int j = 0; j < targetConnections.size(); j++) {
ConnectionContainerEditPart conPart = (ConnectionContainerEditPart) targetConnections.get(j);
PointList pList = ((Connection) conPart.getFigure()).getPoints();
Point p = pList.getPoint(pList.size() - 3);
rowVector.add(new Entry(0, p.y, false, portPart.getType()));
}
}
List<Entry> colVector = new ArrayList<Entry>();
for (int i = 0; i < parts.size(); i++) {
GraphicalEditPart child = (GraphicalEditPart) parts.get(i);
Rectangle bounds = getFigureBounds(child);
colVector.add(new Entry(0, bounds.x + (bounds.width - 1) / 2));
}
m_rows = rowVector.toArray(new Entry[rowVector.size()]);
m_cols = colVector.toArray(new Entry[colVector.size()]);
}
use of org.eclipse.draw2d.geometry.PointList in project yamcs-studio by yamcs.
the class PointListProperty method readValueFromXML.
@Override
public PointList readValueFromXML(Element propElement) {
PointList result = new PointList();
for (Object oe : propElement.getChildren(XML_ELEMENT_POINT)) {
Element se = (Element) oe;
result.addPoint(Integer.parseInt(se.getAttributeValue(XML_ATTRIBUTE_X)), Integer.parseInt(se.getAttributeValue(XML_ATTRIBUTE_Y)));
}
return result;
}
Aggregations