Search in sources :

Example 1 with LayoutConstraint

use of org.eclipse.gmf.runtime.notation.LayoutConstraint in project statecharts by Yakindu.

the class SetLabelsOffsetOperation method updateGMFLabelsOffset.

/**
 * Update the offset ({@link Bounds}) of the labels {@link Node}. This method
 * must be called after setting the newPointList and the labelToUpdate. If the
 * methods {@link #setLabelsToUpdate(ConnectionEditPart)} or
 * {@link #setLabelsToUpdate(ConnectionEditPart, PointList)} are not called,
 * this method has no effect.
 */
public void updateGMFLabelsOffset() {
    if (labelsWithNewOffset != null) {
        // Update Bounds of the three labels Node (Center, Begin and End)
        Set<Entry<Node, Point>> entries = labelsWithNewOffset.entrySet();
        for (Entry<Node, Point> entry : entries) {
            LayoutConstraint layoutConstraint = entry.getKey().getLayoutConstraint();
            if (layoutConstraint instanceof Location) {
                Location bounds = (Location) layoutConstraint;
                bounds.setX(entry.getValue().x);
                bounds.setY(entry.getValue().y);
            }
        }
    }
}
Also used : Entry(java.util.Map.Entry) Node(org.eclipse.gmf.runtime.notation.Node) LayoutConstraint(org.eclipse.gmf.runtime.notation.LayoutConstraint) Point(org.eclipse.draw2d.geometry.Point) Location(org.eclipse.gmf.runtime.notation.Location)

Example 2 with LayoutConstraint

use of org.eclipse.gmf.runtime.notation.LayoutConstraint in project statecharts by Yakindu.

the class SetLabelsOffsetOperation method computeGMFLabelOffset.

/**
 * Update {@link Bounds} of a label {@link Node}.
 *
 * @param labelEdgeEditPart
 *            the editPart of the edge label to be updated
 * @param connectionEditPart
 *            The connection having these labels
 */
private void computeGMFLabelOffset(LabelEditPart labelEditPartToUpdate, ConnectionEditPart connectionEditPart) {
    Point newLabelOffset = null;
    Node labelNodeToUpdate = (Node) labelEditPartToUpdate.getModel();
    if (connectionEditPart.getModel() instanceof Edge) {
        PointList oldBendpoints = oldBendPointsList;
        if (oldBendpoints == null) {
            oldBendpoints = connectionEditPart.getConnectionFigure().getPoints();
        }
        boolean isEdgeWithObliqueRoutingStyle = isEdgeWithObliqueRoutingStyle(connectionEditPart);
        LayoutConstraint layoutConstraint = labelNodeToUpdate.getLayoutConstraint();
        if (layoutConstraint instanceof Location) {
            Location point = (Location) layoutConstraint;
            newLabelOffset = new EdgeLabelQuery(oldBendpoints, newPointList, isEdgeWithObliqueRoutingStyle, new Point(point.getX(), point.getY()), labelEditPartToUpdate.getFigure().getSize(), labelEditPartToUpdate.getKeyPoint(), false).calculateGMFLabelOffset();
        }
    }
    if (newLabelOffset != null) {
        labelsWithNewOffset.put(labelNodeToUpdate, newLabelOffset);
    }
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) EdgeLabelQuery(org.yakindu.base.xtext.utils.gmf.routing.EdgeLabelQuery) Node(org.eclipse.gmf.runtime.notation.Node) LayoutConstraint(org.eclipse.gmf.runtime.notation.LayoutConstraint) Point(org.eclipse.draw2d.geometry.Point) Edge(org.eclipse.gmf.runtime.notation.Edge) Location(org.eclipse.gmf.runtime.notation.Location)

Aggregations

Point (org.eclipse.draw2d.geometry.Point)2 LayoutConstraint (org.eclipse.gmf.runtime.notation.LayoutConstraint)2 Location (org.eclipse.gmf.runtime.notation.Location)2 Node (org.eclipse.gmf.runtime.notation.Node)2 Entry (java.util.Map.Entry)1 PointList (org.eclipse.draw2d.geometry.PointList)1 Edge (org.eclipse.gmf.runtime.notation.Edge)1 EdgeLabelQuery (org.yakindu.base.xtext.utils.gmf.routing.EdgeLabelQuery)1