Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Rotatable Connection Label
Rotatable Connection Label [message #226944] Mon, 27 November 2006 09:21
Eclipse UserFriend
Originally posted by:


I need to implement a connection text label that is painted
parallel to the connection it is assigned to. So if i have a
connection with a 45° angle i also need to paint the text label
with a 45° angle.

So far i have been experimenting with the PolylineConnection and
the MidPointLocator which helps me with the placement of the text
label that i add as a child to the connection.

To rotate the text label i implemented a class RotatableLabel
(does not extend Label) which in its paintFigure method calls rotate()
on the graphics object, before drawing the labels text.

Here two code snipplets to clarify:


/* in constructor of */

PolylineConnection p = new PolylineConnection();

// define connection
p.setStart(new Point(50, 50));
p.setEnd(new Point(150, 50));

// make label rotated by 45°
RotatableLabel label = new RotatableLabel("12345 987", 45);

// determine connections mid point
MidpointLocator locator = new MidpointLocator(p, 0);

// add label to connection
p.add(label, locator);



/* in paintFigure of */

// define rotation for drawing operations

// paint rotated text (offsetX, offsetY depends on rotation angle,
algorithm unclear)
graphics.drawText(text, new Point(offsetX, offsetY));

I am not at all satisfied with this approach, as for one, the
positioning of the text label depending on the current angle is very
tricky and the text i'm drawing on the rotated graphics object looks
terrible (enabling antialias through the method setTextAntialias changes

Has anyone of you encountered similar problems? Would you take a
different approach?

Any feedback is welcome.

Remo Ferrari 8-)
Previous Topic:Thank you GEF
Next Topic:Class Diagram example: multiple selection
Goto Forum:

Current Time: Wed Dec 08 20:32:56 GMT 2021

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

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

Back to the top