Community
Participate
Working Groups
Created attachment 139889 [details] First patch to improve As blogged here: http://manuelselva.wordpress.com/2009/05/06/draw2d-enhancements-part-1-labels-on-polylines/ it would be nice to have draw2d supporting "labeled" polylines. I don't have enough time to make a clean patch and as suggested by Mariot I am putting here a FIRST patch for such feature. WARNING, this patch is for now an ugly patch :o( I am sorry ... This patch brings 2 new classes, PolyLineLabelDecoration and PolylineLabelLocator. It also modify the PolyLineConnection's figure in order to add a new method allowing clients to add the polyline label decoration. The PolylineLabelDecoration figure currently extends Label. Not sure this is the best solution. What do you think ? If this solution is retained we should take into account label's image, position etc .. and override all label's "coordinates computation" method. Thus we could have a polyline label decoration answering to Mark requirements: "Is this decoration able to line break the text in case that the line is not as long as the text? Can I positions the label right, center, left, above and beneath the line? Is the label rotatable? Because on an vertical line an arrow can point to the top, then i would read the text from the bottom. In the other case, if the arrow points to the bottom, I would read from above."
Thanks for submitting this "first" patch, made my world easier :P However, there is some issues that need to be discussed: 1- When the connection has an angle over 90 and lower then -90, it is incorrectly rotated. I found out that it is only missing a translation on the x axis. Here is a simple fix (in the paint method): graphics.translate(getBounds().x, getBounds().y); if (angle < 0){ graphics.translate(0, getBounds().height); } + if (angle < -90 || angle > 90){ + graphics.translate(getBounds().width, 0); + } graphics.rotate((float) angle); if (isOpaque()) 2- Hit testing is incorrect, since getBounds() is overridden. The containsPoint() methods should probably be overridden to provide proper hit testing, but I have not tried it. 3- Once again, since getBounds() is overridden, I am experiencing problems with direct edition: the cell editor is huge since it uses the client area (which is based on the bounds) to position and size itself. 4- It doesn't update the ellipsis when the connection is moved. If the text fits when the decoration is created, then there'll never be an ellipsis if the connection is moved; the text will only get cropped when it gets out of bounds. And vice-versa. I'll continue to try and fix these issue and post some patches here if I get something usable.
Hi, I would love to see such a feature in Helios GEF roadmap. Is it possible ? Mariot
yes, this is something we could add to Helios. Would it be possible to include a draw2d example for the new code. See the draw2d examples plug-in for examples of other snippets.
I found something else which is more problematic: it is impossible to use this decoration with a zoomed-in or zoomed-out viewer. Reason: ScaledGraphics doesn't implement rotate(), which throws a RuntimeException in Graphics. I added a simple class check which avoid rotating the text if ScaledGraphics is use, so in a zoomed viewer the label appears horizontal, the same as if a simple label was used. Any plan on making ScaledGraphics enable rotation?
(In reply to comment #4) > I found something else which is more problematic: it is impossible to use this > decoration with a zoomed-in or zoomed-out viewer. Reason: ScaledGraphics > doesn't implement rotate(), which throws a RuntimeException in Graphics. I > added a simple class check which avoid rotating the text if ScaledGraphics is > use, so in a zoomed viewer the label appears horizontal, the same as if a > simple label was used. > > Any plan on making ScaledGraphics enable rotation? created bug 290891 for that
Created attachment 159447 [details] Enhancement to initial patch I've fixed all the issues I was experiencing with the initial patch. This version seems to be rather stable as I'm using it inside one of our gef editor. The only issue right now is with direct editing: I still haven't figured how to properly show the cell editor based on this decoration. I don't have time to look into this since it has been decided that connections with this decoration won't be editable. Enjoy!
Hi everyone, I've made another version of this patch, fixing some miscalculations and implementing several features: * Correct hit testing * Positioning of text at the source, destination or in the center. * It's now possible to label arced connections (looks ok only with centered positioning) * Accurate icon and text placements * Ability to turn off text cutting (e.g. for self-directed connection loops, where source and target points are the same, the text would be just above the loop) It doesn't currently support textAlign and iconAlign properties though it should be pretty easy to add. And I also didn't address issue with in-place editing. The patch is done against latest zest.core code base from git and there are a couple of changes to existing GraphConnection and PolylineArcConnection classes that use this updated label.
Created attachment 227462 [details] Further modification with zest changes
(In reply to comment #8) > Created attachment 227462 [details] > Further modification with zest changes Hi Anton, If possible can you please share a sample code snippet where a label is added to a polyline. It will be of great help to me. Thank, uzma
There are changes for a GraphConnection class in the same patch including such example. In short: connectionFigure.add(new PolylineLabelDecoration(), new PolylineLabelLocator(connectionFigure));