xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m.@mherrn.de
Subject "high-level" way to create SVG Elements of specific type?
Date Thu, 21 Jun 2012 13:28:31 GMT

I am searching for a way to create SVG Elements that provide higher
level methods for setting values.

For example an SVG rect element is represented by the interface
SVGRectElement. This interface provides "higher level" methods to
access its attributes, for example:
 * getX()
 * getY()
 * getWidth()
 * getHeight()

This is quite fine when trying to access existing SVG elements (by
just casting it to the relevant Interface). But what if I need to
_create_ such elements? The (uncomfortable and not very typesafe)
way is by creating an org.w3c.dom.Element:

final Element element= document.createElement("rect");
element.setAttribute("x", "10");
element.setAttribute("y", "10");
element.setAttribute("width", "100");
element.setAttribute("height", "100");

What I am searching for is a way to create a rect like this:

final SVGRect rectElement= ..... //create the element

The interface SVGRect provides the methods I want to use.
SVGSVGElement provides the method createSVGRect():SVGRect
Unfortunately this SVGRect doesn't implement SVGRectElement, so adding
this to the DOM via appendChild() leads to an exception.

I also found the class org.apache.batik.dom.svg.SVGOMRectElement,
but have no idea what this is used for. Anyway, this class also
only has getters, but no setters. Therefore is of no use for me.

Also there is the class
However, it is protected and can therefore not be used by me.

So what should I do? Is there a way to convert an instance of an SVGRect
to an SVGRectElement? Is there another way have these
convenient-methods for setting attributes to specific SVG element types?


To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org

View raw message