skip to main content
Diagrammer > Programmer's documentation > Developing with the JViews Diagrammer SDK > Using and adding renderers > Configuring renderers in Java code
 
Configuring renderers in Java code
Shows how to customize a renderer using Java™.
*Overview
*Presents an overview of customizing renderers using Java.
*Accessing a renderer
*Describes the method used to access renderers.
*Modifying a renderer
*Explains how to modify a renderer.
*Setting new renderers
*Describes the method used to set a new renderer.
Overview
The simplest and preferred way to customize renderers is through the style sheet, as explained in Using renderers in the style sheet. There are situations, however, where it is necessary to access and modify renderers dynamically while the application is running. For example, you may want to disable the LinkLayout renderer temporarily and re-enable it later without reloading a new style sheet, which would re-create all the graphic objects. This section explains how to do this in your Java™ code.
Accessing a renderer
You can access renderers by calling the method getRenderer of the class IlvSDMEngine.
This method returns the first element of the list of renderers attached to the SDM engine. All but the last element of this list are instances of subclasses of IlvFilterSDMRenderer. You can retrieve the next element of the list by calling the method getFilteredRenderer. The last element of the list is usually the StyleSheet renderer, which is an instance of the class IlvStyleSheetRenderer.
To make it easier to retrieve a particular renderer, the class IlvRendererUtil provides a static method getRenderer that looks up a renderer by its name in the chained list.
The following code example shows how to retrieve the LinkLayout renderer.
Retrieving a renderer in Java code (symbolic name)
 
IlvSDMEngine engine = ...;
IlvLinkLayoutRenderer r = (IlvLinkLayoutRenderer)
    IlvRendererUtil.getRenderer(engine, "LinkLayout");
The name passed to the getRenderer method can be either the symbolic name of the renderer (the name that is used in the style sheet) as shown in Retrieving a renderer in Java code (symbolic name) or the full class name of the renderer as shown in the following code example.
Retrieving a renderer in Java code (class name)
 
IlvSDMEngine engine = ...;
IlvLinkLayoutRenderer r = (IlvLinkLayoutRenderer)
    IlvRendererUtil.getRenderer(engine,
                                IlvLinkLayoutRenderer.class.getName());
Modifying a renderer
Once you have retrieved the reference to the renderer object, you can simply call its methods to modify it. For example, the following code example shows how to disable and re-enable the LinkLayout renderer.
Disabling and re-enabling the LinkLayout renderer in Java code
 
IlvLinkLayoutRenderer r = ...;
r.setEnabled(false);
...
r.setEnabled(true);
Setting new renderers
The renderers are usually chained by the method getFilteredRenderer. The first one is returned by the method getRenderer. If the first renderer must be changed, just call the method setRenderer, specifying the new renderer.
For example, the following code example shows how to add a renderer to the front of the chained list.
Adding a renderer in Java code
 
public void prependRenderer(IlvSDMEngine engine,
                            IlvFilterSDMRenderer newRenderer) {
   IlvSDMRenderer previous = engine.getRenderer();
   newRenderer.setFilteredRenderer(previous);
   engine.setRenderer(newRenderer);
}

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.