|
List Info
Thread: RE: JSVGCanvas does not update with modified DOM using Update Manager
|
|
| RE: JSVGCanvas does not update with
modified DOM using Update Manager |

|
2007-11-06 10:16:46 |
|
> Did you set the JSVGCanvas to be dynamic eg: > svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC)
Yes, the JSVGCanvas was set to be dynamic. Turns out the problem was with the setAttributeNS method (see later post).
> Yes, it is namespace aware, because the first line querying the aLinks > using namespace aware, so the result object is already name aware. > Note: when there is a namespace aware, use the namespace aware > methods, if there is none, no choice, just assume it is namespace > aware.
Cool. I was assuming that as well, but with the canvas not updating properly I wanted to be sure.
Regards, Marc
> Date: Tue, 6 Nov 2007 13:25:41 +0700 > From: tonny.kohar gmail.com > To: batik-users xmlgraphics.apache.org; mformales hotmail.com > Subject: Re: JSVGCanvas does not update with modified DOM using Update Manager > > Hi, > > On Nov 6, 2007 8:48 AM, Marc-Wayne M. Formales <mformales msn.com> wrote: > > I modified my code to use the namespace-aware methods wherever it is > > applicable but the canvas is still not updating. My JSVGCanvas is in a > > JTabbedPane, could this have anything to do with the updates not being seen > > (like perhaps making a JTabbedPane dynamic or something)? > > Did you set the JSVGCanvas to be dynamic eg: > svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC) > > > Also, in regards to being namespace aware: > > > > NodeList aLinks = document.getElementsByTagNameNS(svgNS, "a"); > > Node aLink = aLinks.item(0); <- Namespace aware? > > NamedNodeMap aLinkAtts = aLink.getAttributes(); <- Namespace aware? > > Yes, it is namespace aware, because the first line querying the aLinks > using namespace aware, so the result object is already name aware. > Note: when there is a namespace aware, use the namespace aware > methods, if there is none, no choice, just assume it is namespace > aware. > > Cheers > Tonny Kohar > -- > Citra FX Photo Filter > imagine, design, create ... > http://www.kiyut.com > > --------------------------------------------------------------------- > To unsubscribe, e-mail: batik-users-unsubscribe xmlgraphics.apache.org > For additional commands, e-mail: batik-users-help xmlgraphics.apache.org >
|
| JSVGCanvas does not update with modified
DOM using Update Manager |
  United States |
2007-10-24 14:00:33 |
|
I'm fairly new to Swing/Batik/SVG so please bear with me.
I have a JApplet that loads an SVG via JSVGCanvas.setDocument(xmlDoc). If a user clicks on a certain part of the document (any <a> tag), then I have some code that will animate that node and replace it in the document object. I am doing this in the update manager, which does run in the gvtRendering event, but the UI is not updated with the changes I made. I know that the DOM object is correct because if I write that to the file system, the changes are there. Is there something that I'm missing?
Here is a snippet from the OnClickAction method:
NodeList aLinks = diagramSVG.getElementsByTagName("a");
for (int i . . . ) {
final Node aLink = aLinks.item(i);
.....
Some code to find the element that was clicked on
clone the element
append an animate node to the element
.....
}
UpdateManager um = BatikEWD.diaCanvas.getUpdateManager(); um.getUpdateRunnableQueue().invokeLater(new Runnable() { public void run() { System.out.println("connID: " + connID); diagramSVG.getDocumentElement().replaceChild(animatedALink, aLink); //where animatedALink is the modified canvas.setDocument(diagramSVG); canvas.updateUI(); //I've tried repaint too but nothing seems to work panel.updateUI(); //I've tried repaint too but nothing seems to work } });
Regards,
Marc
|
| Re: JSVGCanvas does not update with
modified DOM using Update Manager |

|
2007-11-05 10:08:27 |
Marc,
I think you are using svg name space as the default name
space in the
SVG document you are editing. Well I was doing that and when
I added
some new elements using DOM methods the output was a right
SVG (XML
document) but batik didn't recognize the new tags, so I
defined the
svg name espace: xsl:svgdcs in the document.
xmlns:svgdcs="http://www.w3.org/20
00/svg"
set the name space in the java application:
xPath.setNamespaceContext(new
NamespaceContextProvider("svgdcs",SVG_NS));
and work with the namespace elements in the rest of the
code:
public void changeLocation(String nameLayer,XPath
xPath,AbstractDocumentFragment svgFragment) throws
XPathExpressionException{
Node position=(Node)
xPath.evaluate("//svgdcs:g[ id='"+nameLayer+"']",svgFragment,XPath
Constants.NODE);
position.getAttributes().getNamedItem("transform"
).setNodeValue("translate("+x+","+y+&quo
t;)");
}
Best Regards
Abraham
On Oct 31, 2007 6:52 PM, Marc-Wayne M. Formales
<mformales msn.com> wrote:
>
> Abraham,
>
> Thanks for your input. The DOM Modification flow is
basically:
>
> 1. create Element from the SVG DOM object and set
attributes
> 2. navigate DOM to find specific Node
> 3. clone Node
> 4. navigate cloned Node and append Element to the
cloned Node
> 5. replace Node with cloned Node in Update Manager
>
> I verified that the cloned Node has the appropriate
namespace, are you
> suggesting that I need to declare it from the Element?
And if yes, how?
>
> Here are some snippets of the code:
>
> //create Element from the SVG Document
> Element animate =
diagramSVG.createElement("animateColor"); //where
> diagramSVG is Document type
> //set attributes
> animate.setAttribute( ...);
> ...
>
> //Navigate DOM to find element to append to
> ...
> Node aLink = ... ;
> Node animatedALink = origNode.cloneNode(true);
> //Navigate clonedNode and then append
"animate" to a child of the cloned
> Node
> ...
> (child of
animatedALink).appendChild((Node)animate);
>
>
> //UpdateManager code
>
>
> Regards,
>
> Marc
>
> > Date: Wed, 31 Oct 2007 14:14:29 +0000
> > From: abraham.rdgz gmail.com
> > To: batik-users xmlgraphics.apache.org;
mformales hotmail.com
> > Subject: Re: JSVGCanvas does not update with
modified DOM using Update
> Manager
>
>
> >
> > Hi Marc,
> >
> > You don't say how you are updating the SVGDOM, but
I have a similar
> > problem using Document Fragments. My XML file was
right and worked in
> > Opera browser but not in JSVGCanvas. The solution
I came across was to
> > declare the svg name space in the document (i.e
xmlns:svg ...)and
> > use it when creating the new elements (i.e
svg:rect), so JSVGCanvas
> > will understand that the new elements were SVG
elements and not any
> > other XML flavor.
> >
> >
> > Hope it will helps
> >
> >
> > Abraham
> >
> > On Oct 24, 2007 7:00 PM, Marc-Wayne M. Formales
<mformales msn.com> wrote:
> > >
> > > I'm fairly new to Swing/Batik/SVG so please
bear with me.
> > >
> > > I have a JApplet that loads an SVG via
JSVGCanvas.setDocument(xmlDoc).
> If
> > > a user clicks on a certain part of the
document (any <a> tag), then I
> have
> > > some code that will animate that node and
replace it in the document
> object.
> > > I am doing this in the update manager, which
does run in the
> gvtRendering
> > > event, but the UI is not updated with the
changes I made. I know that
> the
> > > DOM object is correct because if I write that
to the file system, the
> > > changes are there. Is there something that
I'm missing?
> > >
> > > Here is a snippet from the OnClickAction
method:
> > >
> > >
> > > NodeList aLinks =
diagramSVG.getElementsByTagName("a");
> > > for (int i . . . ) {
> > > final Node aLink = aLinks.item(i);
> > > .....
> > > Some code to find the element that was
clicked on
> > > clone the element
> > > append an animate node to the element
> > > .....
> > > }
> > >
> > > UpdateManager um =
BatikEWD.diaCanvas.getUpdateManager();
> > > um.getUpdateRunnableQueue().invokeLater(new
Runnable() {
> > > public void run() {
> > > System.out.println("connID: " +
connID);
> > >
diagramSVG.getDocumentElement().replaceChild(animatedALink,
aLink);
> > > //where animatedALink is the modified
> > > canvas.setDocument(diagramSVG);
> > > canvas.updateUI(); //I've tried repaint too
but nothing seems to
> > > work
> > > panel.updateUI(); //I've tried repaint too
but nothing seems to
> > > work
> > > }
> > > });
> > >
> > >
> > > Regards,
> > >
> > > Marc
> > >
> >
> >
------------------------------------------------------------
---------
> > To unsubscribe, e-mail:
batik-users-unsubscribe xmlgraphics.apache.org
> > For additional commands, e-mail:
batik-users-help xmlgraphics.apache.org
> >
>
>
------------------------------------------------------------
---------
To unsubscribe, e-mail: batik-users-unsubscribe xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help xmlgraphics.apache.org
|
|
| RE: JSVGCanvas does not update with
modified DOM using Update Manager |
  United States |
2007-11-05 19:48:36 |
|
Thanks Tonny.
I modified my code to use the namespace-aware methods wherever it is applicable but the canvas is still not updating. My JSVGCanvas is in a JTabbedPane, could this have anything to do with the updates not being seen (like perhaps making a JTabbedPane dynamic or something)?
Also, in regards to being namespace aware:
NodeList aLinks = document.getElementsByTagNameNS(svgNS, "a");
Node aLink = aLinks.item(0); <- Namespace aware?
NamedNodeMap aLinkAtts = aLink.getAttributes(); <- Namespace aware?
Regards, Marc
> Date: Thu, 1 Nov 2007 11:07:32 +0700 > From: tonny.kohar gmail.com > To: batik-users xmlgraphics.apache.org > Subject: Re: JSVGCanvas does not update with modified DOM using Update Manager > > Hi, > > On 11/1/07, Marc-Wayne M. Formales <mformales msn.com> wrote: > > > > Element animate = diagramSVG.createElement("animateColor"); //where > > diagramSVG is Document type > > //set attributes > > animate.setAttribute( ...); > > ... > > Batik is namespace aware, so you need to use namespace when creating > or set attribute using the namespace aware methods > > String svgNS = SVGConstants.SVG_NAMESPACE_URI; > diagramSVG.createElementNS(svgNS,...) > animate.setAttributeNS(svgNS,...) > > Regards > Tonny Kohar > -- > Inspiration and Expression > http://blogs.kiyut.com/tonny/ > > --------------------------------------------------------------------- > To unsubscribe, e-mail: batik-users-unsubscribe xmlgraphics.apache.org > For additional commands, e-mail: batik-users-help xmlgraphics.apache.org >
|
| Re: JSVGCanvas does not update with
modified DOM using Update Manager |

|
2007-11-06 00:25:41 |
Hi,
On Nov 6, 2007 8:48 AM, Marc-Wayne M. Formales
<mformales msn.com> wrote:
> I modified my code to use the namespace-aware methods
wherever it is
> applicable but the canvas is still not updating. My
JSVGCanvas is in a
> JTabbedPane, could this have anything to do with the
updates not being seen
> (like perhaps making a JTabbedPane dynamic or
something)?
Did you set the JSVGCanvas to be dynamic eg:
svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC)
> Also, in regards to being namespace aware:
>
> NodeList aLinks =
document.getElementsByTagNameNS(svgNS, "a");
> Node aLink = aLinks.item(0); <- Namespace aware?
> NamedNodeMap aLinkAtts = aLink.getAttributes(); <-
Namespace aware?
Yes, it is namespace aware, because the first line querying
the aLinks
using namespace aware, so the result object is already name
aware.
Note: when there is a namespace aware, use the namespace
aware
methods, if there is none, no choice, just assume it is
namespace
aware.
Cheers
Tonny Kohar
--
Citra FX Photo Filter
imagine, design, create ...
http://www.kiyut.com
------------------------------------------------------------
---------
To unsubscribe, e-mail: batik-users-unsubscribe xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help xmlgraphics.apache.org
|
|
| Re: JSVGCanvas does not update with
modified DOM using Update Manager |
  United States |
2007-11-06 05:17:00 |
|
Hi Marc,
"Marc-Wayne M. Formales" <mformales msn.com>
wrote on 10/24/2007 03:00:33 PM:
> I have a JApplet that loads an SVG via JSVGCanvas.
> setDocument(xmlDoc). If a user clicks on a certain part of the
> document (any <a> tag), then I have some code that will animate
that
> node and replace it in the document object. I am doing this
in the
> update manager, which does run in the gvtRendering event, but the
UI
> is not updated with the changes I made.
> um.getUpdateRunnableQueue().invokeLater(new
Runnable() {
> public void run() {
> System.out.println("connID:
" + connID);
> diagramSVG.getDocumentElement().replaceChild(animatedALink,
> aLink); //where animatedALink is the modified
> canvas.setDocument(diagramSVG);
You should not reset the document. This
will be _very_ slow.
However if that did not work then there is almost
certainly something
wrong with the elements you construct.
> I know that the DOM object is correct because
if I write that
> to the file system, the changes are there. Is
there something
> that I'm missing?
This test is almost useless for detecting
namespace problems.
The majority of common namespace errors are corrected
by writing
the file and reparsing it.
"Tonny Kohar" <tonny.kohar gmail.com>
wrote on 11/01/2007 12:07:32 AM:
> On 11/1/07, Marc-Wayne M. Formales <mformales msn.com> wrote:
> >
> > Element animate = diagramSVG.createElement("animateColor");
//where
> > diagramSVG is Document type
> Batik is namespace aware, so you need to use
namespace when creating
> or set attribute using the namespace aware methods
> String svgNS = SVGConstants.SVG_NAMESPACE_URI;
> diagramSVG.createElementNS(svgNS,...)
Tonny is correct here. 'createElement("animateColor")'
will not work. It needs to be 'createElementNS(svgNS,
"animateColor")'.
However:
> > //set attributes
> > animate.setAttribute( ...);
>
> animate.setAttributeNS(svgNS,...)
This is generally _not_ correct. With
the exception of
the 'xlink' attributes (most notably xlink:href),
all attributes
in SVN need to be set with:
animate.setAttributeNS(null, ...)
This could be your problem as if you
don't set any
attributes on the animate element (which is what it
would
look like to Batik if you put them all in the SVG
Namespace
instead of the null namespace).
|
| RE: JSVGCanvas does not update with
modified DOM using Update Manager |
  United States |
2007-11-06 10:20:52 |
|
Thomas,
Thanks for all your input. It turns out that you were right about the setAttributeNS(null, ...,...) method.
Regards, Marc
To: batik-users xmlgraphics.apache.org CC: batik-users xmlgraphics.apache.org Subject: Re: JSVGCanvas does not update with modified DOM using Update Manager From: thomas.deweese kodak.com Date: Tue, 6 Nov 2007 06:17:00 -0500
Hi Marc,
"Marc-Wayne M. Formales" <mformales msn.com> wrote on 10/24/2007 03:00:33 PM:
> I have a JApplet that loads an SVG via JSVGCanvas. > setDocument(xmlDoc). If a user clicks on a certain part of the > document (any <a> tag), then I have some code that will animate that > node and replace it in the document object. I am doing this in the > update manager, which does run in the gvtRendering event, but the UI > is not updated with the changes I made.
> um.getUpdateRunnableQueue().invokeLater(new Runnable() { > public void run() { > System.out.println("connID: " + connID); > diagramSVG.getDocumentElement().replaceChild(animatedALink, > aLink); //where animatedALink is the modified > canvas.setDocument(diagramSVG);
You should not reset the document. This will be _very_ slow. However if that did not work then there is almost certainly something wrong with the elements you construct.
> I know that the DOM object is correct because if I write that > to the file system, the changes are there. Is there something > that I'm missing?
This test is almost useless for detecting namespace problems. The majority of common namespace errors are corrected by writing the file and reparsing it.
"Tonny Kohar" <tonny.kohar gmail.com> wrote on 11/01/2007 12:07:32 AM:
> On 11/1/07, Marc-Wayne M. Formales <mformales msn.com> wrote: > > > > Element animate = diagramSVG.createElement("animateColor"); //where > > diagramSVG is Document type
> Batik is namespace aware, so you need to use namespace when creating > or set attribute using the namespace aware methods
> String svgNS = SVGConstants.SVG_NAMESPACE_URI; > diagramSVG.createElementNS(svgNS,...)
Tonny is correct here. 'createElement("animateColor")' will not work. It needs to be 'createElementNS(svgNS, "animateColor")'.
However:
> > //set attributes > > animate.setAttribute( ...); > > animate.setAttributeNS(svgNS,...)
This is generally _not_ correct. With the exception of the 'xlink' attributes (most notably xlink:href), all attributes in SVN need to be set with:
animate.setAttributeNS(null, ...)
This could be your problem as if you don't set any attributes on the animate element (which is what it would look like to Batik if you put them all in the SVG Namespace instead of the null namespace).
|
[1-7]
|
|