The appearance of JDiagram items can be customized in several additional ways, as described below.
The Shape class provides the means for defining complex node shapes, made of straight lines, arcs and Bezier curves. A shape must always contain an outline to be used for hit testing, clipping and finding intersections with other objects. Optionally shapes can contain decoration elements and text region definitions. Decorations are visual elements that do not take part in hit testing and clipping. Text regions are the parts of shapes in which node's text is laid-out and rendered. JDiagram provides a set of over 100 predefined shape templates, which can be accessed by calling the getShapes method of the Shape class. Each predefined shape has a string identifier assigned to it. Use the fromId method to find a shape with the specified id. A shape template can be assigned to the Shape member of shape nodes through the setShape method.
The ShapeDesigner tool that comes with the JDiagram suite lets you draw custom shapes and store them in shape libraries. Note that the tool is not available yet as a Java application, and the JDiagram shape designer runs only under Microsoft Windows. A library file can be loaded into your application using the ShapeLibrary class. The definitions loaded from a shape library are automatically added to the shared shapes collection and can be accessed through the getShapes and fromId methods of the Shape class, just as the predefined shapes.
Another way to customize a item's appearance is implemented by firing events each time an item is painted, giving you the option to attach your own drawing code to the JDiagram's rendering engine. Use the setCustomDraw method to enable that feature in your application. JDiagram gives you five options for custom drawing. If you choose Additional drawing style, your drawing code will be executed after the standard item drawing code is executed and the image is rendered, but before the text is rendered. Furthermore, the Graphics object you receive to draw on has a clipping region applied that corresponds to the node's shape. If using Full drawing mode, none of the standard JDiagram drawing code is executed - just yours. The ShadowOnly mode performs standard painting of items, but leaves the drawing of shadows to your code. Place your own drawing code in a handler of the drawNode, drawLink and drawCell events. This events are fired for each item with custom-draw style that needs repainting.
Finally, you could combine user-defined shapes with the Additional custom-painting style. Thus, you can get custom shapes enabled for a node and your custom painting code executing with the node shape used as clipping region. You might clear the clipping region, but be careful - if you draw outside node's bounding rectangle, the view may not update correctly.