You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by ch...@infowayconsulting.net on 2004/12/09 08:11:04 UTC
dynamically adding an element to svgdocument
Hi All
Iam trying to add an element dynamically to the svgdocument
bound to a JSVGCanvas. Iam doing this inside
updatemanagerthread but it doesn't work. can anybody suggest
what iam doing wrong here.
The following code snippet is inside a
dynamicUpdatebutton.addActionListener(new ActionListener() {
public void actionPerformed
(ActionEvent ae) {
svgCanvas.getUpdateManager().getUpdateRunnableQueue
().invokeLater(
new
Runnable() {
public void run() {
SVGDocument svgdoc=svgCanvas.getSVGDocument();
Element elt = svgdoc.createElement("a");
elt.setAttribute("xlink:href","http://www.ibm.com/");
Element polygon = svgdoc.createElement("polygon");
polygon.setAttribute("points","60 160,165 172,180
60,290 290,272 280,172 285,250 255");
polygon.setAttribute("style","fill:dimgrey");
elt.appendChild(polygon);
svgdoc.getRootElement().appendChild(elt);
svgCanvas.setDocumentState
(JSVGCanvas.ALWAYS_DYNAMIC);
svgCanvas.setSVGDocument(svgdoc);
}
});
Thanks in advance
Chandra
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org
Re: dynamically adding an element to svgdocument
Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Chandra,
>> Element elt = svgdoc.createElement("a");
>> elt.setAttribute("xlink:href","http://www.ibm.com/");
There is one more thing you are missing. SVG/Batik is a namespace
aware language/processor so you need to take care to use namespaces
properly:
SVG_NS = "http://www.w3.org/2000/svg";
XLINK_NS = "http://www.w3.org/1999/xlink";
// Use this for all SVG elements.
Element elt = svgdoc.createElementNS(SVG_NS, "a");
// Use this for "xlink" attributes.
elt.setAttributeNS(XLINK_NS, "xlink:href","http://www.ibm.com/");
// Use either for "unprefixed" attributes (I've been told that
// the ns one is better than the non-ns one but I'm not 100%
// certain I agree there should be a difference).
elt.setAttributeNS(null, "style", "fill:blue");
elt.setAttribute("stroke", "none");
Jorg Heymans wrote:
> This should come first:
>
> svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
>
> furthermore, there is no need IMO to set the document back on the canvas
> as you're updating it in place.
>
> And not all of your code below needs to be invoked from the update mgr
> thread, only the svgdoc.getRootElement().appendChild(elt); is modifying
> the document really.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org
Re: dynamically adding an element to svgdocument
Posted by Jorg Heymans <jh...@domek.be>.
This should come first:
svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
furthermore, there is no need IMO to set the document back on the canvas
as you're updating it in place.
And not all of your code below needs to be invoked from the update mgr
thread, only the svgdoc.getRootElement().appendChild(elt); is modifying
the document really.
HTH
Jorg
chandrasrini@infowayconsulting.net wrote:
> Hi All
>
> Iam trying to add an element dynamically to the svgdocument
> bound to a JSVGCanvas. Iam doing this inside
> updatemanagerthread but it doesn't work. can anybody suggest
> what iam doing wrong here.
> The following code snippet is inside a
> dynamicUpdatebutton.addActionListener(new ActionListener() {
> public void actionPerformed
> (ActionEvent ae) {
> svgCanvas.getUpdateManager().getUpdateRunnableQueue
> ().invokeLater(
> new
> Runnable() {
>
> public void run() {
>
>
> SVGDocument svgdoc=svgCanvas.getSVGDocument();
>
> Element elt = svgdoc.createElement("a");
> elt.setAttribute("xlink:href","http://www.ibm.com/");
> Element polygon = svgdoc.createElement("polygon");
> polygon.setAttribute("points","60 160,165 172,180
> 60,290 290,272 280,172 285,250 255");
> polygon.setAttribute("style","fill:dimgrey");
> elt.appendChild(polygon);
> svgdoc.getRootElement().appendChild(elt);
> svgCanvas.setDocumentState
> (JSVGCanvas.ALWAYS_DYNAMIC);
> svgCanvas.setSVGDocument(svgdoc);
> }
>
> });
>
> Thanks in advance
> Chandra
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org