Bug 281246 - Draw2d Enhancement - Labeled Polylines
Summary: Draw2d Enhancement - Labeled Polylines
Status: NEW
Alias: None
Product: GEF
Classification: Tools
Component: GEF-Legacy Draw2d (show other bugs)
Version: unspecified   Edit
Hardware: PC All
: P3 enhancement with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: gef-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 290891
Blocks:
  Show dependency tree
 
Reported: 2009-06-23 12:37 EDT by Manuel Selva CLA
Modified: 2013-02-26 04:22 EST (History)
7 users (show)

See Also:


Attachments
First patch to improve (7.32 KB, patch)
2009-06-23 12:37 EDT, Manuel Selva CLA
no flags Details | Diff
Enhancement to initial patch (9.93 KB, patch)
2010-02-18 11:03 EST, Pascal Gélinas CLA
no flags Details | Diff
Further modification with zest changes (19.47 KB, patch)
2013-02-22 08:42 EST, Anton Tanasenko CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Manuel Selva CLA 2009-06-23 12:37:40 EDT
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."
Comment 1 Pascal Gélinas CLA 2009-08-18 17:25:32 EDT
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.
Comment 2 Mariot Chauvin CLA 2009-08-19 09:44:27 EDT
Hi,
 
I would love to see such a feature in Helios GEF roadmap.
Is it possible ?

Mariot
Comment 3 Anthony Hunter CLA 2009-08-19 10:42:26 EDT
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.
Comment 4 Pascal Gélinas CLA 2009-08-19 15:47:26 EDT
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?
Comment 5 Mariot Chauvin CLA 2009-09-30 08:06:46 EDT
(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
Comment 6 Pascal Gélinas CLA 2010-02-18 11:03:34 EST
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!
Comment 7 Anton Tanasenko CLA 2013-02-22 08:41:48 EST
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.
Comment 8 Anton Tanasenko CLA 2013-02-22 08:42:46 EST
Created attachment 227462 [details]
Further modification with zest changes
Comment 9 Uzma Pathan CLA 2013-02-26 04:10:43 EST
(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
Comment 10 Anton Tanasenko CLA 2013-02-26 04:22:19 EST
There are changes for a GraphConnection class in the same patch including such example. In short:

connectionFigure.add(new PolylineLabelDecoration(), new PolylineLabelLocator(connectionFigure));