Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Connection: how to update control points
Connection: how to update control points [message #1794083] Thu, 23 August 2018 09:56
Shenwei Zheng is currently offline Shenwei ZhengFriend
Messages: 15
Registered: December 2016
Junior Member
Hi all,

I defined a connection with orthogonal router. The start dynamic anchor has a bottom middle computation strategy and the end dynamic anchor has a top middle computation strategy. I added one control point, with which I want to specify the position of the horizontal line of the connection. The left image is what I desired but sometime is came out with the right one.

related code:
DynamicAnchor startAnchor = new DynamicAnchor(startRectangle);
DynamicAnchor startAnchor = new DynamicAnchor(endRectangle);
startAnchor.setComputationStrategy(new BottomMiddleStrategy(0, 0));
endRectangle.setComputationStrategy(new TopMiddleStrategy(0, 0));

Connection connection = new Connection();
connection.setRouter(new OrthogonalRouter());

connection.addControlPoint(0, new Point(endRectangle.getTranslateX() + endRectangle.getWidth() / 2, endRectangle.getTranslateY() -50);
public class BottomMiddleStrategy implements IComputationStrategy

  private double offsetWidth;
  private double offsetHeihgt;

  public BottomMiddleStrategy(double offSetWidth, double offSetHeight)
    this.offsetWidth = offSetWidth;
    this.offsetHeihgt = offSetHeight;

  public Point computePositionInScene(Node anchorage, Node anchored, Set<Parameter< ? >> parameters)
    double width = anchorage.getLayoutBounds().getWidth() / 2 + anchorage.getLayoutBounds().getMinX() + offsetWidth;
    double height = anchorage.getLayoutBounds().getHeight() + anchorage.getLayoutBounds().getMinY() + offsetHeihgt;
    return NodeUtils.localToScene(anchorage, new Point(width, height));

  public Set<Class< ? extends Parameter< ? >>> getRequiredParameters()
    Set<Class< ? extends Parameter< ? >>> parameters = new HashSet<>();
    return parameters;

When the position of start or end is changed, I have to manualy update the control point. I tried three variants:
1. remove my defined control point and add it again. But it looks like there too more control points. As my understanding, when I added a single control point, connection will add other control points to make the connection to be orthogonal. When the 'real' control point is removed, other control points stay in the connection. So this variant will not work. (Not sure if I am correct)
if (connection.getControlPoint(0) != null)
connection.addControlPoint(0, new Point(endRectangle.getTranslateX() + endRectangle.getWidth() / 2, endRectangle.getTranslateY() -50);

2. remove all controls points and add the defined control point again. But sometimes I got the right image.
connection.addControlPoint(0, new Point(endRectangle.getTranslateX() + endRectangle.getWidth() / 2, endRectangle.getTranslateY() -50);

3. based on the second variant, I added a second control point. But I got an exception which I cannot find out where is the problem.
java.lang.IllegalArgumentException: Index out of range (index: 0, size: 0).
	at org.eclipse.gef.fx.nodes.Connection.removeControlPoint(
	at org.eclipse.gef.fx.nodes.Connection.removeAllControlPoints(	

Maybe there is a simple way to have a orthogonal connection as I desired. Does someone have a better solution? Thank you.

Best Regards

[Updated on: Thu, 23 August 2018 09:59]

Report message to a moderator

Previous Topic:Add LayoutAlgorithm in MinMap example
Next Topic:Realizing simple bendable connections
Goto Forum:

Current Time: Sat Sep 22 12:36:28 GMT 2018

Powered by FUDForum. Page generated in 0.01653 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top