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 Kerschbaum Michael <m....@pke.at> on 2011/02/03 09:39:13 UTC

Updating Dom Tree outside of the UpdateManagerThread for printing ?

Hello,
 
I have a general question ! I would like to print an svg that is
currently visible on the screen. To do that i'am cloning the original
svg document with that code :
 
Document docOrg = svgDoc; // original document

DOMImplementation impl = docOrg.getImplementation();

Document docNew; // new document

docNew = impl.createDocument("http://www.w3.org/2000/svg", "svg", null);

docNew.replaceChild(docNew.importNode(docOrg.getDocumentElement(),
true),

docNew.getDocumentElement());

SVGDocument doc = (SVGDocument) docNew;

((AbstractDocument) doc).setDocumentURI(svgDoc.getURL());

Thats the easy part. But there is an own Animation ( a Thread that sets
some Elements visible and invisible to get a blink animation) ! In the
print this elements should be visible! So i copy the original svg at
anytime and set all elements to visible again. 

Element[] elements = ag.getAnimation().getAllElements(true);

if (elements != null || elements.length > 0) {

    logger.debug("Cleaning up cloned document for printing (e.g. current
blinking elements => visible) ...");

    logger.debug("Will clean up " + elements.length + " elements !");

    for (int i = 0; i < elements.length; i++) {

        String id = elements[i].getAttribute("id");

        Element elt = doc.getElementById(id);

        elt.setAttributeNS(null, "visibility", "visible");

    }

    logger.debug("Cleaned up cloned document for printing.");

}

But this is not done in the UpdateManagerThread ! because i will not
wait with invokeAndWait  ?! Could this be a problem ? I mean after that
i print the copied document and then i gets garbage collected => so i
don't do anything with it ?

mfg
 
Michael Kerschbaum

Re: Updating Dom Tree outside of the UpdateManagerThread for printing ?

Posted by th...@kodak.com.
Hi Michael,

"Kerschbaum Michael " <m....@pke.at> wrote on 02/03/2011 03:39:13 
AM:

> I have a general question ! I would like to print an svg that is 
> currently visible on the screen. To do that i'am cloning the 
> original svg document with that code :

        Once you have cloned the document you dont' have to worry about 
the
UpdateManager (unless you create one, or you associate the document with
anther JSVGCanvas). 

        However, you should probably clone the document in the 
UpdateManager.
In general reads are fairly safe outside of the UpdateManager but, they 
are not 100% safe.
Thomas DeWeese | CDG Advanced Development | 
Eastman Kodak Company | 343 State Street | Rochester, NY 14650-0128 | 
Thomas.DeWeese@Kodak.com | 585 724-0294 | 
www.kodak.com