The translate
method of your
class should build a new Element
instance,
and, after filling it with the information contained in the graphic
object and applying a style, should return that instance. To fill
the Element
, you can use regular DOM methods
(Element.setAttribute()
) or the methods
provided by the SVG DOM. Note, however, that only limited support
of SVG DOM is implemented in Rogue Wave JViews,
and not all the methods are accessible.
The following code shows how to create the translator.
import org.w3c.dom.*;
import org.w3c.svg.dom.*;
public class MyGraphicTranslator
implements SVGDocumentBuilderConfigurator.GraphicTranslator
{
// Method that translates the graphic to SVG
public Element translate(IlvGraphic graphic, IlvTransformer t,
SVGDocumentBuilder builder)
{
SVGDocument doc = builder.getDocument();
// The SVG ’group’ element will contain
// all drawings necessary to display MyGraphic.
SVGGElement group = (SVGGElement)doc.createElementNS
("http://www.w3.org/2000/svg", "g");
// First add to the group the element corresponding
// to the parent class of MyRect (IlvRectangle).
group.appendChild(builder.getConfigurator().
getTranslator(“ilog.views.graphic.IlvRectangle”).
translate(graphic, t));
// Create the SVG element corresponding to
// the drawing added at MyGraphic level.
SVGPathElement path = (SVGPathElement)doc.createElementNS
("http://www.w3.org/2000/svg", "path");
IlvRect rect = graphic.boundingBox(graphic, t);
SVGList list = path.getPathSegList();
// Go to the beginning point of the Bezier.
list.appendItem(path.createPathSegMovetoAbs(rect.x,
rect.y + rect.height));
// Add the Bezier.
list.appendItem(path.
createPathSegCurvetoCubicAbs(rect.x + rect.width,
rect.y,
rect.x + rect.width / 4,
rect.y + rect.height / 4,
rect.x + 3*rect.width / 4,
rect.y + 3*rect.height / 4));
// Start to style the path.
builder.startStyleElement(path, null);
// Really apply the style (blue color...).
builder.appendStyle("stroke", "blue");
builder.appendStyle("stroke-width", "1");
builder.appendStyle("stroke-join", "miter");
builder.appendStyle("stroke-cap", "round");
builder.appendStyle("stroke-dasharray", "4 2");
// Finish to style the path.
builder.endStylingElement();
group.appendChild(path);
return group;
}
}