Adding Icons to a Link

The Link object in ILOG Diagrammer for .NET lets you easily add text items at any position on the link path (using the TextItems property), but there is no out-of-the box functionality to add other graphic decorations like icons. Here is a sample that shows how to achieve this.

decoratedlink.png

The meat of the sample is the DecoratedLink class. It is a subclass of Link with a new Decorations property that contains a collection of LinkDecoration objects. Each LinkDecoration has an Image property (the icon to display), a Position property (Start, Middle or End) and an Offset property that shifts the icon by the specified number of pixels along the link path.

Here is the source code: in C#, and in Visual Basic.

Feel free to use (and adapt) the DecoratedLink class if you need this functionality in your applications.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists

Tags: , ,

9 Responses to “Adding Icons to a Link”

  1. Eric Durocher Says:

    Forgot to attach the source code… Click on the word ’sample’ in the first paragraph to get it.

  2. Eric Durocher Says:

    Added the VB version of the source code.

  3. Alexey Says:

    Great thanks!

  4. Alexey Says:

    I using it with “GraphicObject”(user symbol) instead “Image”(bitmap picture) and it looks good
    And..
    When its not “Link”, but “Line” object, where i can put “PlaceDecorations()” method?
    In “Link” its override of “SetLinkPoints” method.

  5. Eric Durocher Says:

    I think you can call PlaceDecorations() from UpdateGraphicsPath().

  6. Alexey Says:

    Double great thanks! Now i have decorated node lines and decorated links for electrical scheme.

    And now i need a decoration cut for my decoration on link, like textcut
    (for example if i have decoration with “rectangle” image object wich have fill=null, i want to cut line inside this rectangle).

    I use textitem with text opacity = 0, but its not comfortable when i have other text items and not usable when i need to resize my decoration image.

    Can you help me? )

    How it looks:
    http://i021.radikal.ru/0811/23/417b6e65f2e3.jpg

  7. Eric Durocher Says:

    Alexey,

    Your application looks really nice.

    For the cut problem, there is no simple solution. The only way is to override UpdateGraphicsPath and compute the “cuts” yourself… I had a try at it, you can find a modified version of the project here:

    http://blogs.ilog.com/netvisu/wp-content/uploads/2008/11/decoratedlinksample_cut.zip

    As you will see, there is a new “Cut” property in LinkDecoration, you must set it to true to have the link cut at this decoration.

    Note also that you cannot use the normal “cap” arrows, because the arrow would appear before each cut. So, you must use a “shape” arrow instead (using a triangle shape). See the Diagram1.cs example in the project.

    Note that this code is a quick try, and has some tricky edge-cases, but it seems to work (not tested very intensively though). I hope you will find it useful.

    Oh, and please don’t ask the VB version… :-) You can use one of the many C#->VB translators out there on the net.

  8. Alexey Says:

    You are the great man.
    I don`t need VB. And i also don’t need arrows.
    Its exactly what i want x)

    I just little set it right, like that:
    http://upload0000.webasyst.net/files/737cd809
    (vs 2005 solution)
    just another decorations comparison for sort method, and 4 private properties: cut, bounds, corners, computedPosition
    “public bool Cut{ get; set;}” not works )

  9. Eric Durocher Says:

    Oh yes, this was VS 2008 / .NET Framework 3.5 code…

    Glad it works for you.

Leave a Reply