org.eclipse.draw2d.Connection Java Examples

The following examples show how to use org.eclipse.draw2d.Connection. 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: TreeLayoutUtil.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
private static int getDeepestTreeLevel(ConnectionLayer connectionLayer,
		IFigure figure) {
	final List<Connection> connectionList = getOutgoingConnections(
			connectionLayer, figure);
	if (connectionList.size() > 0) {
		final int[] ret = new int[connectionList.size()];
		for (int i = 0; i < connectionList.size(); i++) {
			ret[i] = 1 + getDeepestTreeLevel(connectionLayer,
					connectionList.get(i).getTargetAnchor().getOwner());
		}
		int maxLevel = ret[0];
		if (ret.length > 1) {
			for (int i = 1; i < ret.length; i++) {
				if (ret[i] > maxLevel) {
					maxLevel = ret[i];
				}
			}
		}
		return maxLevel;
	}
	return 0;
}
 
Example #2
Source File: InitialPointsConnectionBendpointEditPolicy.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected Command getBendpointsChangedCommand(Connection connection, Edge edge) {
	Point ptRef1 = connection.getSourceAnchor().getReferencePoint();
	getConnection().translateToRelative(ptRef1);

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

	TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();

	SetConnectionBendpointsAndLabelCommmand sbbCommand = new SetConnectionBendpointsAndLabelCommmand(editingDomain);
	sbbCommand.setEdgeAdapter(new EObjectAdapter(edge));
	sbbCommand.setNewPointList(connection.getPoints(), ptRef1, ptRef2);

	return new ICommandProxy(sbbCommand);
}
 
Example #3
Source File: FixedBendpointEditPolicy.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
private void showLineFeedback(ConnectionEditPart connectionEditPart) {
	// XXX: copied from InitialPointsOfRequestDataManager
	List<?> children = connectionEditPart.getChildren();
	Connection connection = connectionEditPart.getConnectionFigure();
	for (Object child : children) {
		if (child instanceof ExternalXtextLabelEditPart) {
			IFigure figure = ((ExternalXtextLabelEditPart) child).getFigure();
			Object currentConstraint = connection.getLayoutManager().getConstraint(figure);
			if (currentConstraint instanceof EdgeLabelLocator) {
				EdgeLabelLocator edgeLabelLocator = (EdgeLabelLocator) currentConstraint;
				edgeLabelLocator.setFeedbackData(getInitialPoints(connection),
						new Vector(edgeLabelLocator.getOffset().x, edgeLabelLocator.getOffset().y),
						SetLabelsOffsetOperation.isEdgeWithObliqueRoutingStyle(connectionEditPart));
			}
		}
	}
}
 
Example #4
Source File: TreeLayoutUtil.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns incoming connection figures of the figure parameter.
 * 
 * @param connectionLayer
 * @param figure
 * @return
 */
public static List<Connection> getIncomingConnections(
		ConnectionLayer connectionLayer, IFigure figure) {

	final List<Connection> incomingConnectionList = new ArrayList<Connection>();

	for (final Object object : connectionLayer.getChildren()) {
		if (object instanceof Connection) {
			final Connection connection = (Connection) object;
			if (connection.getTargetAnchor().getOwner() == figure) {
				incomingConnectionList.add(connection);
			}
		}
	}
	return incomingConnectionList;
}
 
Example #5
Source File: TreeLayoutUtil.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns outgoing connection figures of the figure parameter.
 * 
 * @param connectionLayer
 * @param figure
 * @return
 */
public static List<Connection> getOutgoingConnections(
		ConnectionLayer connectionLayer, IFigure figure) {

	final List<Connection> outgoingConnectionList = new ArrayList<Connection>();

	for (final Object object : connectionLayer.getChildren()) {
		if (object instanceof Connection) {
			final Connection connection = (Connection) object;
			if (connection.getSourceAnchor().getOwner() == figure) {
				outgoingConnectionList.add(connection);
			}
		}
	}
	return outgoingConnectionList;
}
 
Example #6
Source File: RelativeBendpointUtil.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
public List<Point> convertConstraintToListOfPoint(Connection conn) {
	List<Point> list = new ArrayList<>();
	Object routingConstraint = conn.getRoutingConstraint();
	if (routingConstraint instanceof List) {
		List<?> bendpointList = (List<?>) routingConstraint;
		for (Object bpobj : bendpointList) {
			if (bpobj instanceof RelativeBendpoint) {
				list.add(((RelativeBendpoint) bpobj).getLocation());
			} else {
				System.err.println("[ERR] unknown bend point " + bpobj);
			}
		}
	} else if (routingConstraint != null) {
		System.out.println("[ERR] unknown routing constraint " + routingConstraint);
	}
	return list;
}
 
Example #7
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 #8
Source File: FixedBendpointEditPolicy.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
protected void eraseChangeBoundsFeedback(ChangeBoundsRequest request) {
	connectionStart = true;
	router.commitBoxDrag();
	for (ConnectionEditPart connectionEditPart : getAllConnectionParts(request)) {
		List<?> children = connectionEditPart.getChildren();
		Connection connection = connectionEditPart.getConnectionFigure();
		for (Object child : children) {
			if (child instanceof ExternalXtextLabelEditPart) {
				IFigure figure = ((ExternalXtextLabelEditPart) child).getFigure();
				Object currentConstraint = connection.getLayoutManager().getConstraint(figure);
				if (currentConstraint instanceof EdgeLabelLocator) {
					EdgeLabelLocator edgeLabelLocator = (EdgeLabelLocator) currentConstraint;
					edgeLabelLocator.eraseFeedbackData();
				}
			}
		}
	}

}
 
Example #9
Source File: RubberBandRoutingSupport.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
private void initDrag(Rectangle originalAbs, List<Connection> connections, boolean isSource, boolean isTarget) {
		for (Connection connection : connections) {
			// disable repaint so that first drag does not let connection jump
//			((TransitionFigure) connection).disableRepaint();

			// save connection points
			ConnData cd = new ConnData(connection, isSource, isTarget);
			conn.put(connection, cd);

			// compute max move deltas
			MaxMoveDelta[] mmds = cd.getMaxMoveDeltas(originalAbs);

			// merge with current mmds
			for (int i = 0; i < this.mmds.length; i++) {
				this.mmds[i].merge(mmds[i]);
			}
		}
	}
 
Example #10
Source File: RubberBandRoutingSupport.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected List<RelativeBendpoint> createConstraint(Connection conn, List<PrecisionPoint> list) {
	List<RelativeBendpoint> constraint = new ArrayList<>();
	for (Point p : list) {
		RelativeBendpoint relbp = new RelativeBendpoint();
		relbp.setConnection(conn);
		relbpUtil.forceLocation(conn, relbp, p.preciseX(), p.preciseY());
		constraint.add(relbp);
	}
	return constraint;
}
 
Example #11
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 #12
Source File: ConnectionRouterImp.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void route(Connection conn) {
	NULL.route(conn);
	PointList points = conn.getPoints();
	Point start = points.getFirstPoint();
	Point end = points.getLastPoint();
	points.removeAllPoints();
	points.addPoint(start);
	if (start.y > end.y)
		routeBottomToTop(start, end, points);
	else
		routeTopToBottom(start, end, points);
	points.addPoint(end);
}
 
Example #13
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 #14
Source File: TreeConnectionRouter.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void route(Connection conn) {
	super.route(conn);
	if (conn.getSourceAnchor().getOwner() == null || conn.getTargetAnchor().getOwner() == null)
		return;
	PointList points = new PointList();
	points.addPoint(conn.getPoints().getFirstPoint());
	ProcessFigure source = getProcessFigure(conn.getSourceAnchor());
	ProcessFigure target = getProcessFigure(conn.getTargetAnchor());
	Point sourceLoc = source.getLocation();
	Point targetLoc = target.getLocation();
	Point firstPoint = conn.getPoints().getFirstPoint();
	Point lastPoint = conn.getPoints().getLastPoint();
	if (targetLoc.x < sourceLoc.x + source.getSize().width
			|| targetLoc.x > sourceLoc.x + source.getSize().width + LayoutManager.H_SPACE + target.getSize().width
			|| target == source) {
		points.addPoint(firstPoint.getTranslated(LayoutManager.H_SPACE / 2, 0));
		int y1 = sourceLoc.y < targetLoc.y ? targetLoc.y : sourceLoc.y;
		y1 -= LayoutManager.V_SPACE / 2;
		points.addPoint(firstPoint.getTranslated(LayoutManager.H_SPACE / 2, 0).x, y1);
		points.addPoint(lastPoint.getTranslated(-LayoutManager.H_SPACE / 2, 0).x, y1);
		points.addPoint(lastPoint.getTranslated(-LayoutManager.H_SPACE / 2, 0));
	} else {
		points.addPoint(firstPoint.getTranslated(LayoutManager.H_SPACE / 2, 0));
		points.addPoint(firstPoint.getTranslated(LayoutManager.H_SPACE / 2, 0).x, lastPoint.y);
	}
	points.addPoint(lastPoint);
	conn.setPoints(points);
}
 
Example #15
Source File: ProcessLinkCreatePolicy.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
protected Connection createDummyConnection(Request req) {
	PolylineConnection con = (PolylineConnection) super.createDummyConnection(req);
	con.setForegroundColor(Link.COLOR);
	if (!(req instanceof CreateConnectionRequest)) {
		con.setTargetDecoration(new PolygonDecoration());
		return con;
	}
	CreateLinkCommand cmd = (CreateLinkCommand) ((CreateConnectionRequest) req).getStartCommand();
	if (cmd.output != null)
		con.setTargetDecoration(new PolygonDecoration());
	else if (cmd.input != null)
		con.setSourceDecoration(new PolygonDecoration());
	return con;
}
 
Example #16
Source File: Animation.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
static boolean playbackState(Connection conn) {
	if (!PLAYBACK) {
		return false;
	}

	PointList list1 = (PointList) initialStates.get(conn);
	PointList list2 = (PointList) finalStates.get(conn);
	if (list1 == null) {
		conn.setVisible(false);
		return true;
	}
	if (list1.size() == list2.size()) {
		Point pt1 = new Point(), pt2 = new Point();
		PointList points = conn.getPoints();
		points.removeAllPoints();
		for (int i = 0; i < list1.size(); i++) {
			list1.getPoint(pt2, i);
			list2.getPoint(pt1, i);
			pt1.x = (int) Math.round(pt1.x * progress + (1 - progress)
					* pt2.x);
			pt1.y = (int) Math.round(pt1.y * progress + (1 - progress)
					* pt2.y);
			points.addPoint(pt1);
		}
		conn.setPoints(points);
	}
	return true;
}
 
Example #17
Source File: Animation.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
static void recordFinalState(IFigure child) {
	if (child instanceof Connection) {
		recordFinalState((Connection) child);
		return;
	}
	Rectangle rect2 = child.getBounds().getCopy();
	Rectangle rect1 = (Rectangle) initialStates.get(child);
	if (rect1.isEmpty()) {
		rect1.x = rect2.x;
		rect1.y = rect2.y;
		rect1.width = rect2.width;
	}
	finalStates.put(child, rect2);
}
 
Example #18
Source File: Animation.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
public static void recordInitialState(Connection connection) {
	if (!RECORDING) {
		return;
	}
	PointList points = connection.getPoints().getCopy();
	if (points.size() == 2
			&& points.getPoint(0).equals(Point.SINGLETON.setLocation(0, 0))
			&& points.getPoint(1).equals(
					Point.SINGLETON.setLocation(100, 100))) {
		initialStates.put(connection, null);
	} else {
		initialStates.put(connection, points);
	}
}
 
Example #19
Source File: TreeConnectionRouter.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void route(Connection conn) {
	// pre route
	NULL.route(conn);

	// get points
	PointList points = conn.getPoints();
	Point first = points.getFirstPoint();
	Point last = points.getLastPoint();

	// distance from to point to connection anchor
	final int trans = GraphLayoutManager.verticalSpacing / 4;

	// create new list
	PointList newPoints = new PointList();
	// add first point
	newPoints.addPoint(first);

	// add 2 new points
	newPoints.addPoint(first.x, first.y - trans);
	newPoints.addPoint(last.x, last.y + trans);

	// add last point
	newPoints.addPoint(last);
	// set new list
	conn.setPoints(newPoints);
}
 
Example #20
Source File: GenericLevelPresets.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private void createConnection ( final Figure connLayer, final Label label, final Figure figure )
{
    final Connection c = new PolylineConnection ();
    c.setSourceAnchor ( new ChopboxAnchor ( label ) );
    c.setTargetAnchor ( new ChopboxAnchor ( figure ) );
    c.setConnectionRouter ( new BendpointConnectionRouter () );
    connLayer.add ( c );
}
 
Example #21
Source File: TreeLayout.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected List<List<TreeNode>> getTreeLevels(List<TreeNode> treeNodeList,
		int level) {
	final List<List<TreeNode>> levelElements = new ArrayList<List<TreeNode>>();
	final List<TreeNode> nextRankElements = new ArrayList<TreeNode>();
	levelElements.add(new ArrayList<TreeNode>());
	levelElements.get(0).addAll(treeNodeList);

	for (final TreeNode treeNode : treeNodeList) {
		// Set level of the treeNode
		treeNode.level = level;

		if (treeNode.children.isEmpty()) {

			// calculate child GraphNodes in next Rank
			final List<Connection> connectionList = TreeLayoutUtil
					.getTreeFigureIncomingConnections(connectionLayer,
							treeNode.getFigure());
			
			for (int i = 0; i < connectionList.size(); i++) {
				final Connection connection = connectionList.get(i);
				if (connection.getSourceAnchor().getOwner() != null) {
					final IFigure childFig = connection.getSourceAnchor()
							.getOwner();
					final TreeNode childTreeNode = new TreeNode(treeNode,
							childFig);
					treeNode.children.add(childTreeNode);
				}
			}
		}

		treeNode.children = sortTreeNodeList(treeNode.children);
		nextRankElements.addAll(treeNode.children);
	}
	// add ranks for childTreeNodeList
	if (!nextRankElements.isEmpty()) {
		levelElements.addAll(getTreeLevels(nextRankElements, ++level));
	}
	return levelElements;
}
 
Example #22
Source File: FixedBendpointEditPolicy.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
private List<Connection> getTargetConnections(ChangeBoundsRequest request) {
	List<Connection> result = new ArrayList<>();
	@SuppressWarnings("unchecked")
	List<IGraphicalEditPart> targetConnections = filter(getHost().getTargetConnections(), request);
	for (IGraphicalEditPart iGraphicalEditPart : targetConnections) {
		Connection connection = (Connection) iGraphicalEditPart.getFigure();
		result.add(connection);
	}
	return result;
}
 
Example #23
Source File: FixedBendpointEditPolicy.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
private List<Connection> getSourceConnections(ChangeBoundsRequest request) {
	List<Connection> result = new ArrayList<>();
	@SuppressWarnings("unchecked")
	List<IGraphicalEditPart> sourceConnections = filter(getHost().getSourceConnections(), request);
	for (IGraphicalEditPart iGraphicalEditPart : sourceConnections) {
		Connection connection = (Connection) iGraphicalEditPart.getFigure();
		result.add(connection);
	}
	return result;
}
 
Example #24
Source File: FixedBendpointEditPolicy.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
private PointList getInitialPoints(Connection connection) {
	ConnData cd = router.getCD(connection);
	if (cd != null) {
		return relbpUtil.convertToPointList(cd.initialVisualPoints);
	}
	return connection.getPoints();
}
 
Example #25
Source File: TransitionPriorityDecorationProvider.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public void createDecorators(IGraphicalEditPart editPart) {
	PriorityFigure figure = new PriorityFigure(MapModeUtil.getMapMode(), getPriority(editPart));
	figure.setSize(12, 13);
	setDecoration(getDecoratorTarget().addDecoration(figure,
			new ConnectionLocator((Connection) editPart.getFigure(), ConnectionLocator.TARGET) {
				protected Point getLocation(PointList points) {
					Point p = PointListUtilities.pointOn(PointListUtilities.copyPoints(points),
							DISTANCE_TO_SOURCE, KeyPoint.ORIGIN, new Point());
					return p;
				}
			}, false));

	figure.setToolTip(new Label("Transition Priority " + getPriority(editPart)));
}
 
Example #26
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 #27
Source File: InitialPointsOfRequestDataManager.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Reset the initial points stored in this manager and also erase the feedback
 * data from all the {@link EdgeLabelLocator} of the labels of the current
 * connection.
 *
 * @param connection The connection from which to erase feedback data
 */
public void eraseInitialPoints(Connection connection) {
	initialPoints = null;
	for (Object object : connection.getChildren()) {
		if (object instanceof WrappingLabel) {
			Object currentConstraint = connection.getLayoutManager().getConstraint((WrappingLabel) object);
			if (currentConstraint instanceof EdgeLabelLocator) {
				((EdgeLabelLocator) currentConstraint).eraseFeedbackData();
			}
		}
	}
}
 
Example #28
Source File: RailroadConnectionRouter.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void remove(Connection connection) {
	constraints.remove(connection);
}
 
Example #29
Source File: Animation.java    From olca-app with Mozilla Public License 2.0 4 votes vote down vote up
static void recordFinalState(Connection conn) {
	PointList points1 = (PointList) initialStates.get(conn);
	PointList points2 = conn.getPoints().getCopy();

	if (points1 != null && points1.size() != points2.size()) {
		Point p = new Point(), q = new Point();

		int size1 = points1.size() - 1;
		int size2 = points2.size() - 1;

		int i1 = size1;
		int i2 = size2;

		double current1 = 1.0;
		double current2 = 1.0;

		double prev1 = 1.0;
		double prev2 = 1.0;

		while (i1 > 0 || i2 > 0) {
			if (Math.abs(current1 - current2) < 0.1 && i1 > 0 && i2 > 0) {
				// Both points are the same, use them and go on;
				prev1 = current1;
				prev2 = current2;
				i1--;
				i2--;
				current1 = (double) i1 / size1;
				current2 = (double) i2 / size2;
			} else if (current1 < current2) {
				// 2 needs to catch up
				// current1 < current2 < prev1
				points1.getPoint(p, i1);
				points1.getPoint(q, i1 + 1);

				p.x = (int) ((q.x * (current2 - current1) + p.x
						* (prev1 - current2)) / (prev1 - current1));
				p.y = (int) ((q.y * (current2 - current1) + p.y
						* (prev1 - current2)) / (prev1 - current1));

				points1.insertPoint(p, i1 + 1);

				prev1 = prev2 = current2;
				i2--;
				current2 = (double) i2 / size2;

			} else {
				// 1 needs to catch up
				// current2< current1 < prev2

				points2.getPoint(p, i2);
				points2.getPoint(q, i2 + 1);

				p.x = (int) ((q.x * (current1 - current2) + p.x
						* (prev2 - current1)) / (prev2 - current2));
				p.y = (int) ((q.y * (current1 - current2) + p.y
						* (prev2 - current1)) / (prev2 - current2));

				points2.insertPoint(p, i2 + 1);

				prev2 = prev1 = current1;
				i1--;
				current1 = (double) i1 / size1;
			}
		}
	}
	finalStates.put(conn, points2);
}
 
Example #30
Source File: RailroadConnectionRouter.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void setConstraint(Connection connection, Object constraint) {
	if (constraint instanceof BendConstraint) {
		constraints.put(connection, (BendConstraint) constraint);
	}
}