You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by Geeta Shukla <ge...@persistent.co.in> on 2003/02/17 07:14:13 UTC

Refreshing JSVGCanvas

Hi,

I am using Batik 1.5b4b version.
Through the app i am developing i let the user select a svg file and open
it. It opens and renders properly. The app also allows user to add more
<text> nodes to the SVG document. I take the value for the text node in a
JTextArea and create a text node and append to the SVGDocument. My problem
is that even after appending the new <text> node it doesn't show up on the
JSVGCanvas.
I tried doing the following:
1) setSVGDocument(doc)
2) repaint() on JSVGCanvas
3) repaint() on UpdateManager of the canvas.

but nothing worked. If i try writing the SVGDocument to a file, it contains
the <text> node which i appened. If i reopen this file again thru my app the
text node shows up. But i don't want it that way. I need the canvas to
refresh when the SVGDocument changes.


Please help!
I have appended my method which creates the new text node below.

Thanks,
Geeta Shukla
Persistent Systems Ltd, Pune, India - 16
Ph: (020)5678900*671
Email: geeta_shukla@persistent.co.in


-----------------------------------------------------------------
Note: i have tried creating attribute and element with NS, without NS and
with a null NS.. nothing works

	public void createAnnotationNode( String annotation, int x, int y, int
SVGWidth) throws Exception
	{
		SVGDocument document = this.getSVGDocument();
		SVGSVGElement root = document.getRootElement();

		int xScale = x + (annotation.length()*12);
		if(xScale > SVGWidth)
		{
			root.setAttributeNS(null, "width", String.valueOf(xScale));
		}

		// create the text
		Element text = document.createElementNS(null, "text");
		text.setAttributeNS(null,"x", String.valueOf(x));
		text.setAttributeNS(null,"y", String.valueOf(y));
		text.setAttributeNS(null,"style", "font-size:12");
		Text value = document.createTextNode(annotation);
		text.appendChild(value);


		// attach the text to the svg root element
		root.appendChild(text);
		this.setSVGDocument(document);


	}//end of method createTextNode





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


RE: Refreshing JSVGCanvas

Posted by Geeta Shukla <ge...@persistent.co.in>.
Thanks alot !
It did work with the namespace stuff.


-----Original Message-----
From: Thomas E Deweese [mailto:thomas.deweese@kodak.com]
Sent: Monday, February 17, 2003 6:07 PM
To: batik-dev@xml.apache.org
Cc: batik-dev-owner@xml.apache.org
Subject: RE: Refreshing JSVGCanvas


>>>>> "GS" == Geeta Shukla <ge...@persistent.co.in> writes:

GS> Hi, I am using Batik 1.5b4b version.  Through the app i am
GS> developing i let the user select a svg file and open it. It opens
GS> and renders properly. The app also allows user to add more <text>
GS> nodes to the SVG document. I take the value for the text node in a
GS> JTextArea and create a text node and append to the SVGDocument. My
GS> problem is that even after appending the new <text> node it
GS> doesn't show up on the JSVGCanvas.  I tried doing the following:
GS> 1) setSVGDocument(doc) 2) repaint() on JSVGCanvas 3) repaint() on
GS> UpdateManager of the canvas.

GS> but nothing worked. If i try writing the SVGDocument to a file, it
GS> contains the <text> node which i appened. If i reopen this file
GS> again thru my app the text node shows up. But i don't want it that
GS> way. I need the canvas to refresh when the SVGDocument changes.

    Sure, I suspect the problem is namespaces.  You need to create
elements with namespaces and set Attributes with out namespace with
the exception of the 'xlink:href' attribute.  You also don't need to
set the SVG document at the end just modifying it should cause the
repaint to happen.

    One other things occurs to me is that the height of the svg
element might be clipping the new text elements.  I suggest you try
setting the height of the outermost SVG element large enough to show
any text elements ahead of time (there have been issues with updates
to the width/height on the outermost svg element so don't count on
those changes happening automatically).

    I updated your function as I think it should be.

GS> Please help!  I have appended my method which creates the new text
GS> node below.

public void createAnnotationNode( String annotation, int x, int y, int
SVGWidth) throws Exception
{
	SVGDocument document = this.getSVGDocument();
	SVGSVGElement root = document.getRootElement();

	int xScale = x + (annotation.length()*12);
	if(xScale > SVGWidth)
	{
		root.setAttribute("width", String.valueOf(xScale));
	}

	// create the text
	Element text = document.createElementNS(SVG_NAMESPACE, "text");
	text.setAttribute("x", String.valueOf(x));
	text.setAttribute("y", String.valueOf(y));
	text.setAttribute("style", "font-size:12");
	Text value = document.createTextNode(annotation);
	text.appendChild(value);


	// attach the text to the svg root element
	root.appendChild(text);
}//end of method createTextNode

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


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


RE: Refreshing JSVGCanvas

Posted by Thomas E Deweese <th...@kodak.com>.
>>>>> "GS" == Geeta Shukla <ge...@persistent.co.in> writes:

GS> Hi, I am using Batik 1.5b4b version.  Through the app i am
GS> developing i let the user select a svg file and open it. It opens
GS> and renders properly. The app also allows user to add more <text>
GS> nodes to the SVG document. I take the value for the text node in a
GS> JTextArea and create a text node and append to the SVGDocument. My
GS> problem is that even after appending the new <text> node it
GS> doesn't show up on the JSVGCanvas.  I tried doing the following:
GS> 1) setSVGDocument(doc) 2) repaint() on JSVGCanvas 3) repaint() on
GS> UpdateManager of the canvas.

GS> but nothing worked. If i try writing the SVGDocument to a file, it
GS> contains the <text> node which i appened. If i reopen this file
GS> again thru my app the text node shows up. But i don't want it that
GS> way. I need the canvas to refresh when the SVGDocument changes.

    Sure, I suspect the problem is namespaces.  You need to create
elements with namespaces and set Attributes with out namespace with
the exception of the 'xlink:href' attribute.  You also don't need to
set the SVG document at the end just modifying it should cause the
repaint to happen.

    One other things occurs to me is that the height of the svg
element might be clipping the new text elements.  I suggest you try
setting the height of the outermost SVG element large enough to show
any text elements ahead of time (there have been issues with updates
to the width/height on the outermost svg element so don't count on
those changes happening automatically).

    I updated your function as I think it should be.

GS> Please help!  I have appended my method which creates the new text
GS> node below.

public void createAnnotationNode( String annotation, int x, int y, int
SVGWidth) throws Exception
{
	SVGDocument document = this.getSVGDocument();
	SVGSVGElement root = document.getRootElement();

	int xScale = x + (annotation.length()*12);
	if(xScale > SVGWidth)
	{
		root.setAttribute("width", String.valueOf(xScale));
	}

	// create the text
	Element text = document.createElementNS(SVG_NAMESPACE, "text");
	text.setAttribute("x", String.valueOf(x));
	text.setAttribute("y", String.valueOf(y));
	text.setAttribute("style", "font-size:12");
	Text value = document.createTextNode(annotation);
	text.appendChild(value);


	// attach the text to the svg root element
	root.appendChild(text);
}//end of method createTextNode

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