Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » [SOLVED] How to programmatically set the location of a label?((Strategy for no overlapping figures))
[SOLVED] How to programmatically set the location of a label? [message #666802] Fri, 22 April 2011 16:25 Go to next message
Xavier Seignard is currently offline Xavier SeignardFriend
Messages: 52
Registered: June 2010
Member
Hello,
I've programmatically added two labels on my edge, but now I would like to implement something in order to set the location of my labels in a clever way.

I want them close to the first and last point of the edge, but I want them not overlapping the nodes at the end of it.
I also want them to be relocated when I move the nodes at the end of the edge.

So nothing fancy, only a standard strategy for placing a labels.
But I can't figure out how to do it.

For now I can place them close to the edge ends like this (where edgeFigure is the PolylineConnectionEx figure of the edge) :
targetRoleLabel = new WrappingLabel();
targetRoleLabel.setText(relDef.getTargetRole() + " [" + relDef.getTargetCard() + "]");
Point labelPoint = new Point(edgeFigure.getEnd().x - X_OFFSET, edgeFigure.getEnd().y - Y_OFFSET);
targetRoleLabel.setLocation(labelPoint);
edgeFigure.add(targetRoleLabel);


So I should find a smarter way to define the Point argument for the setLocation(Point p) method.

So if you have any hint it would be very welcome Smile

Have a nice day,

Regards,

Xavier

[Updated on: Wed, 27 April 2011 09:38]

Report message to a moderator

Re: How to programmatically set the location of a label? [message #667188 is a reply to message #666802] Wed, 27 April 2011 09:36 Go to previous message
Xavier Seignard is currently offline Xavier SeignardFriend
Messages: 52
Registered: June 2010
Member
Hello,
I found the solution thanks to that GEF tutorial : http://www.eclipse.org/articles/Article-GEF-Draw2d/GEF-Draw2 d.html

I use the ConnectionEndPointLocator to locate the label at the end and at the start of my connection.

Here is an example for placing a label at the start (source) of my connection.
PolylineConnectionEx edgeFigure = (PolylineConnectionEx) getFigure();
WrappingLabel sourceRoleLabel = new WrappingLabel();
sourceRoleLabel.setText("My Label");
ConnectionEndpointLocator sourceRoleLocator = new ConnectionEndpointLocator(getFigure(), false);
sourceRoleLocator.setVDistance(15);
edgeFigure.add(sourceRoleLabel, sourceRoleLocator);

You can do the same for placing a label at the end (target) of your connection passing "true" as second argument in the ConnectionEndpointLocator constructor.

For my purpose I put that code in the refreshSourceDecoration() I override in my CustomConnectionEditPart.

Hope this will help people facing the same question.

Regards,

Xavier
Previous Topic:Refresh RootEditPart
Next Topic:AbstractViewProvider.getCreationMethod getting the wrong method when creating a Diagram
Goto Forum:
  


Current Time: Sat Nov 09 07:31:04 GMT 2024

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

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

Back to the top