Java Code Examples for org.eclipse.draw2d.Connection#translateToRelative()

The following examples show how to use org.eclipse.draw2d.Connection#translateToRelative() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FixedBendpointEditPolicy.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("restriction")
protected Command getBendpointsChangedCommand(ConnectionEditPart part) {
	Connection connection = part.getConnectionFigure();
	Point ptRef1 = connection.getSourceAnchor().getReferencePoint();
	connection.translateToRelative(ptRef1);

	Point ptRef2 = connection.getTargetAnchor().getReferencePoint();
	connection.translateToRelative(ptRef2);

	TransactionalEditingDomain editingDomain = getHost().getEditingDomain();

	SetConnectionBendpointsAndLabelCommmand sbbCommand = new SetConnectionBendpointsAndLabelCommmand(editingDomain);
	sbbCommand.setEdgeAdapter(new EObjectAdapter((EObject) part.getModel()));
	sbbCommand.setNewPointList(connection.getPoints(), ptRef1, ptRef2);
	sbbCommand.setLabelsToUpdate(part, getInitialPoints(connection));

	return new ICommandProxy(sbbCommand);
}
 
Example 2
Source File: RailroadConnectionRouter.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void route(Connection connection) {
	PointList points = connection.getPoints();
	points.removeAllPoints();
	Point startPoint = getStartPoint(connection);
	connection.translateToRelative(startPoint);
	points.addPoint(startPoint);
	Point endPoint = getEndPoint(connection);
	connection.translateToRelative(endPoint);
	Object constraint = getConstraint(connection);
	if (constraint instanceof BendConstraint) {
		int dx = Integer.signum(endPoint.x - startPoint.x) * ILayoutConstants.CONNECTION_RADIUS;
		int dy = Integer.signum(endPoint.y - startPoint.y) * ILayoutConstants.CONNECTION_RADIUS;
		// can be simplified but becomes unreadable
		if (((BendConstraint) constraint).isConvex()) {
			if (((BendConstraint) constraint).isStart()) {
				points.addPoint(startPoint.x - dx, startPoint.y + dy);
				points.addPoint(startPoint.x - dx, endPoint.y - dy);
				points.addPoint(startPoint.x , endPoint.y);
			} else {
				points.addPoint(endPoint.x, startPoint.y);
				points.addPoint(endPoint.x + dx, startPoint.y + dy);
				points.addPoint(endPoint.x + dx, endPoint.y - dy);
			}
		} else {
			if (((BendConstraint) constraint).isStart()) {
				points.addPoint(startPoint.x + dx, startPoint.y + dy);
				points.addPoint(startPoint.x + dx, endPoint.y - dy);
				points.addPoint(startPoint.x + 2 * dx, endPoint.y);
			} else {
				points.addPoint(endPoint.x - 2 * dx, startPoint.y);
				points.addPoint(endPoint.x - dx, startPoint.y + dy);
				points.addPoint(endPoint.x - dx, endPoint.y - dy);
			}
		}
	}
	points.addPoint(endPoint);
	connection.setPoints(points);
}
 
Example 3
Source File: RelativeBendpointUtil.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public void forceLocation(Connection conn, RelativeBendpoint relbp, double locX, double locY) {
	float w = 0;
	Dimension d2 = new Dimension();
	PrecisionDimension d1 = new PrecisionDimension();

	// compute d1 based on source anchor
	PrecisionPoint a1 = new PrecisionPoint(conn.getSourceAnchor().getReferencePoint());
	Point a1Copy = a1.getCopy();
	conn.translateToRelative(a1Copy);

	// x = a1.preciseX() + d1.preciseWidth()
	// <=> x - a1.preciseX() = d1.preciseWidth()
	d1.setPreciseWidth(locX - a1Copy.preciseX());
	d1.setPreciseHeight(locY - a1Copy.preciseY());

	relbp.setRelativeDimensions(d1, d2);
	relbp.setWeight(w);

	// ensure location is correct
	Point location = relbp.getLocation();
	if (Math.abs(location.preciseX() - locX) > 0.1) {
		throw new IllegalStateException(
				"cannot force location-x: expected <" + locX + "> but got <" + location.preciseX() + ">");
	}
	if (Math.abs(location.preciseY() - locY) > 0.1) {
		throw new IllegalStateException(
				"cannot force location-y: expected <" + locY + "> but got <" + location.preciseY() + ">");
	}
}
 
Example 4
Source File: CustomRectilinearRouter.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Rectilinear polyline is invalid if:
 * 1. First bend point is within the source
 * 2. Last bend point is within the target
 * 3. First bend point and source anchor are on different sides of the source shape
 * 4. Last bend point and target anchor are on different sides of the target shape
 * 
 * @param conn connection
 * @param line rectilinear polyline
 * @return <code>true</code> if the line is valid
 */
private boolean isValidRectilinearLine(Connection conn, PointList line) {
    if (!(conn.getSourceAnchor().getOwner() instanceof Connection)) {
        Rectangle source = new PrecisionRectangle(
                getAnchorableFigureBounds(conn.getSourceAnchor().getOwner()));
        conn.getSourceAnchor().getOwner().translateToAbsolute(source);
        conn.translateToRelative(source);
        if (source.contains(line.getPoint(1))) {
            return false;
        }
        int firstSegmentOrientation = line.getFirstPoint().x == line.getPoint(1).x ? PositionConstants.VERTICAL
                : PositionConstants.HORIZONTAL;
        if (getOutisePointOffRectanglePosition(line.getPoint(1), source) != getAnchorLocationBasedOnSegmentOrientation(
                line.getFirstPoint(), source, firstSegmentOrientation)) {
            return false;
        }
    }
    if (!(conn.getTargetAnchor().getOwner() instanceof Connection)) {
        Rectangle target = new PrecisionRectangle(
                getAnchorableFigureBounds(conn.getTargetAnchor().getOwner()));
        conn.getTargetAnchor().getOwner().translateToAbsolute(target);
        conn.translateToRelative(target);
        if (target.contains(line.getPoint(line.size() - 2))) {
            return false;
        }
        int lastSegmentOrientation = line.getLastPoint().x == line.getPoint(line.size() - 2).x
                ? PositionConstants.VERTICAL : PositionConstants.HORIZONTAL;
        if (getOutisePointOffRectanglePosition(line.getPoint(line.size() - 2),
                target) != getAnchorLocationBasedOnSegmentOrientation(line.getLastPoint(), target,
                        lastSegmentOrientation)) {
            return false;
        }
    }
    return true;
}
 
Example 5
Source File: RubberBandRoutingSupport.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
private Rectangle getBounds(Connection conn, IFigure sourceOwner) {
	Rectangle sourceBox = sourceOwner.getBounds().getCopy();
	sourceOwner.translateToAbsolute(sourceBox);
	conn.translateToRelative(sourceBox);
	return sourceBox;
}
 
Example 6
Source File: CustomRectilinearRouter.java    From bonita-studio with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Source bounding rectangle relative to connection figure coordinates
 * 
 * @param conn connection
 * @return <code>PrecisionRectangle</code> source bounds relative to connection's coordinate
 *         system
 */
private PrecisionRectangle sourceBoundsRelativeToConnection(Connection conn) {
    PrecisionRectangle source = new PrecisionRectangle(conn.getSourceAnchor().getOwner().getBounds());
    conn.getSourceAnchor().getOwner().translateToAbsolute(source);
    conn.translateToRelative(source);
    return source;
}
 
Example 7
Source File: CustomRectilinearRouter.java    From bonita-studio with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Target bounding rectangle relative to connection figure coordinates
 * 
 * @param conn connection
 * @return <code>PrecisionRectangle</code> target bounds relative to connection's coordinate
 *         system
 */
private PrecisionRectangle targetBoundsRelativeToConnection(Connection conn) {
    PrecisionRectangle target = new PrecisionRectangle(conn.getTargetAnchor().getOwner().getBounds());
    conn.getTargetAnchor().getOwner().translateToAbsolute(target);
    conn.translateToRelative(target);
    return target;
}