Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Links starts always at the same point
Links starts always at the same point [message #485279] Fri, 11 September 2009 07:42 Go to next message
Marc Mising name is currently offline Marc Mising nameFriend
Messages: 193
Registered: July 2009
Location: Valencia, Spain
Senior Member
Hi!

I want to link two nodes and I want this link start and finishes at the
same point, specifically in the {bottom,top,left,right}-center of the
figure.

********* *********
* *-------* *
********* *********


I think I should use Anchors, isn't it?

Thanks anybody
Marc
Re: Links starts always at the same point [message #485316 is a reply to message #485279] Fri, 11 September 2009 11:05 Go to previous messageGo to next message
Peter Lang is currently offline Peter LangFriend
Messages: 153
Registered: July 2009
Senior Member
Hi Marc,

Yes, you should use Anchors :)

The following solution will try to use the best out of left/right/bottom/top depending on the positions of the two nodes. If you only want to use a constant point, just return translated bounds.getRight() for instance.

In the EditPart of your node:
@Override
public ConnectionAnchor getTargetConnectionAnchor(
        ConnectionEditPart connEditPart) {
    return getConnectionAnchor();
}

@Override
public ConnectionAnchor getSourceConnectionAnchor(
        ConnectionEditPart connEditPart) {
    return getConnectionAnchor();
}

private ConnectionAnchor connectionAnchor;

protected ConnectionAnchor getConnectionAnchor() {
    if (connectionAnchor== null) {
        connectionAnchor= new FixedConnectionAnchor(getNodeFigure());
    }
    return connectionAnchor;
}

class FixedConnectionAnchor extends SlidableAnchor {

    public FixedConnectionAnchor(IFigure owner) {
        super(owner);
    }

    @Override
    protected Point getLocation(Point ownReference, Point foreignReference) {
        Rectangle bounds = getOwner().getBounds();
        Dimension diff = foreignReference.getDifference(bounds.getCenter());
        Point p;
        if(Math.abs(diff.width) > Math.abs(diff.height)) {
            p = diff.width > 0 ? bounds.getRight() : bounds.getLeft();
        }
        else {
            p = diff.height > 0 ? bounds.getBottom() : bounds.getTop();
        }
        PrecisionPoint pp = new PrecisionPoint(p);
        getOwner().translateToAbsolute(pp);
        return pp;
    }
}
Re: Links starts always at the same point [message #485342 is a reply to message #485316] Fri, 11 September 2009 12:57 Go to previous message
Marc Mising name is currently offline Marc Mising nameFriend
Messages: 193
Registered: July 2009
Location: Valencia, Spain
Senior Member
Thanks Peter! ;)
Previous Topic:Palette hide
Next Topic:subeditor change & save wipeout content of parenteditor
Goto Forum:
  


Current Time: Fri Apr 19 04:51:21 GMT 2024

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

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

Back to the top