Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Custom connection anchors depending on mouse down
Custom connection anchors depending on mouse down [message #186569] Tue, 13 May 2008 05:29 Go to next message
Eclipse UserFriend
I'm using a custom figure in my diagram with the shape of a diamond and I
want to allow connections only from the vertexs of the figure. I need also
know where the mouse down in order to choose the closest vertex.

As far as I know, I need to override two pair of methods in the custom
figure edit part:

-getSourceConnectionAnchor(ConnectionEditPart connEditPart)
-getSourceConnectionAnchor(Request request)

I Know that the second method is used in the first part of the command
creation an for displaying feedback and I only use it to retrieve the
reference point:

public ConnectionAnchor getSourceConnectionAnchor(Request request) {
pt = ((DropRequest) request).getLocation().getCopy();
if (request instanceof ReconnectRequest) {
return getNodeFigure().getSourceConnectionAnchorAt(pt);
}
else if (request instanceof DropRequest){
return getNodeFigure().getSourceConnectionAnchorAt(pt);
}
return getNodeFigure().getSourceConnectionAnchorAt(null);
}


I can use this reference point to calculate the anchor in
getSourceConnectionAnchor(ConnectionEditPart connEditPart) but when I
close and open again the diagram and the anchor is anew calculated
(calling getSourceConnectionAnchor(ConnectionEditPart connEditPart) but
not getSourceConnectionAnchor(Request request)) I don't have that
reference point and then I can't calculate the anchor point properly.

¿I'm missing something? ¿There is a way to store used anchors an retrieve
it when opening the diagram without recalculate it?


Thanks in advance!
Re: Custom connection anchors depending on mouse down [message #187502 is a reply to message #186569] Fri, 16 May 2008 10:15 Go to previous messageGo to next message
Eclipse UserFriend
I've solved it!!!

I show the steps I've followed:

1: Overriding of getSourceConnectionAnchor in the EditPart to return the
custom anchor.

public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart
connEditPart) {

return new MyAnchor(getFigure());
}

2. Create a ConnectionAnchor class (MyAnchor) tha inherits from
AbstractConnectionAnchor. In this class, you must write a getLocation
method that returns the point where the anchor will be created.

That's all.

You can see, like I do, ChopboxAnchor class to figure out how to write
your custom ConnectionClass.

Cheers!
Re: Custom connection anchors depending on mouse down [message #188006 is a reply to message #187502] Tue, 20 May 2008 11:09 Go to previous message
Eclipse UserFriend
Originally posted by: gmerin.integranova.com

Hi Salva!
I'm also interested on how to achive this. Would it be possible to see
the complete code of your Anchor?

Thanks in advance,
Gabriel.

Salva Martínez escribió:
> I've solved it!!!
>
> I show the steps I've followed:
>
> 1: Overriding of getSourceConnectionAnchor in the EditPart to return the
> custom anchor.
>
> public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart
> connEditPart) {
>
> return new MyAnchor(getFigure());
> }
>
> 2. Create a ConnectionAnchor class (MyAnchor) tha inherits from
> AbstractConnectionAnchor. In this class, you must write a getLocation
> method that returns the point where the anchor will be created.
> That's all.
>
> You can see, like I do, ChopboxAnchor class to figure out how to write
> your custom ConnectionClass.
>
> Cheers!
>
>
>
Previous Topic:An Elist in a feature
Next Topic:label move when connection changes
Goto Forum:
  


Current Time: Sun Jul 27 12:29:52 EDT 2025

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

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

Back to the top