Renderers are the most essential parts of the Preview as they contain the code that actually draws the item on the canvas. Each item (e.g. node, edge) should have its renderer.
Rendering is a three-steps process:
preProcess()
method is called on all renderers to let them initialize additional attributes for their items. The best example is the edge renderer which will initialize the source and target position in the EdgeItem
object during this phase. In general the preProcess()
method is the best for complex algorithms or gathering data from other items. Note that the preProcess()
method is called only once per refresh, unlike render()
which is called many times.isRendererForitem()
is then used to determine which renderer should be used to render an item. The method provides an access to the preview properties. For instance, if the properties says the edge display is disabled, the edge renderer should return false
for every item. Note that nothing avoids several renderer to returns true
for the same item.render()
method is finally called for every item which the renderer returned true
at isRendererForitem()
. It receives the properties and the render target. It uses the item attributes and properties to determine item aspects and the render target to obtain the canvas. Renderers also provide a list of {@link PreviewProperty} which the user canedit. All properties are put in the central {@link PreviewProperties} so thougheach renderer defines it's properties it can read/write any property through PreviewProperties
.
If your plugin renderer extends one of the default renderers, your plugin renderer will automatically replace the extended renderer. This means the default renderer will not even be available in the renderers manager.
Also, if more than one plugin extends the same default renderer, the one with lowest position will be enabled by the default, but others will still be available for activation in the renderers manager.
The list of default renderers is the following (contained in Preview Plugin module);
Renderers are singleton services and implementations need to add the following annotation to be recognized by the system:
@ServiceProvider(service=Renderer.class, position=XXX)
Position parameter optional but recommended in order to control the default order in which the available renderers are executed.
@author Yudi Xue, Mathieu Bastian
|
|