Search in sources :

Example 11 with PointList

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);
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) ArrayList(java.util.ArrayList) PointList(org.eclipse.draw2d.geometry.PointList) List(java.util.List) Point(org.eclipse.draw2d.geometry.Point) AbsoluteBendpoint(org.eclipse.draw2d.AbsoluteBendpoint) Bendpoint(org.eclipse.draw2d.Bendpoint) AbsoluteBendpoint(org.eclipse.draw2d.AbsoluteBendpoint) Point(org.eclipse.draw2d.geometry.Point) Bendpoint(org.eclipse.draw2d.Bendpoint)

Example 12 with PointList

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;
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Point(org.eclipse.draw2d.geometry.Point)

Example 13 with PointList

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;
    }
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point)

Example 14 with PointList

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()]);
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) AbstractPortEditPart(org.knime.workbench.editor2.editparts.AbstractPortEditPart) ArrayList(java.util.ArrayList) PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Connection(org.eclipse.draw2d.Connection) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) NodeInPortEditPart(org.knime.workbench.editor2.editparts.NodeInPortEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) ArrayList(java.util.ArrayList) PointList(org.eclipse.draw2d.geometry.PointList) List(java.util.List) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart)

Example 15 with PointList

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;
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Element(org.jdom.Element)

Aggregations

PointList (org.eclipse.draw2d.geometry.PointList)80 Point (org.eclipse.draw2d.geometry.Point)49 Rectangle (org.eclipse.draw2d.geometry.Rectangle)15 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)10 ArrayList (java.util.ArrayList)9 ConnectionModel (org.csstudio.opibuilder.model.ConnectionModel)8 Polyline (org.eclipse.draw2d.Polyline)7 List (java.util.List)6 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)6 AbstractPolyModel (org.csstudio.opibuilder.widgets.model.AbstractPolyModel)5 Dimension (org.eclipse.draw2d.geometry.Dimension)5 Bendpoint (org.eclipse.draw2d.Bendpoint)4 PrecisionRectangle (org.eclipse.draw2d.geometry.PrecisionRectangle)4 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)3 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)3 PolarPoint (org.csstudio.swt.widgets.figureparts.PolarPoint)3 AbsoluteBendpoint (org.eclipse.draw2d.AbsoluteBendpoint)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 ConnectionReconnectCommand (org.csstudio.opibuilder.commands.ConnectionReconnectCommand)2