xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andres Toussaint <and...@onemileup.com>
Subject Re: Replace an Element on DOMtree and refresh the jsvgcanvas.
Date Thu, 09 Jun 2005 14:15:26 GMT
You need to do your change to the DOMTree inside the UpdateManager  
thread (leave the repaint to Batik, you do not need to call it, as long  
as your changes are made in the update canvas thread).

             
jsvgCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new  
Runnable(){
		public void run(){

                           // Make a copy of the element subtree  
suitable for inserting into doc2
                           Node dup = doc.importNode(gElement, true);
                                   
                            
element.getParentNode().replaceChild(dup,element);
                                   
                          //alterar o valor
                       
    doc.getElementById("value"+uids[0]).getChildNodes().item(0).setNodeV 
alue(value);

                         //ver resultado num ficheiro
                          
svgCreator.writeXmlToFile("d:\\marinho\\svgbib\\tmp.svg", doc);
}});

Your variables need to be Class wide, or declared final to work.

Regards,
Andres.

On Jun 9, 2005, at 9:50 AM, Filipe Marinho wrote:

>
> well sorry i've done a bad copy paste...
>
> here it is
>
>
>         void treatMedida(final pt.efacec.se.aut.frk.cmp.Event event){
>                
>                
>                        
>                 String value = event.getValue("Value").toString();
>                 String uidAll = event.getValue("Uid").toString();
>                 String[] uids = uidAll.split(":",2);
>                 String uid = uids[0]+event.getValue("Type");
>                 String tag = event.getValue("SxTag").toString();
>                 Element element = doc.getElementById(uid);// elemento 

> da medida
>                 NodeList nl = element.getChildNodes();
>                 // vai buscar a posição y
>                 Element element_temp =  
> (Element)nl.item(nl.getLength()-4);
>                 String posY = element_temp.getAttribute("y");
>                 // vai buscar a secção cdata
>                 String cdata =  
> nl.item(nl.getLength()-2).getNodeValue();
>                
>                 if (event.getValue("STImposed").toString().equals("0")
>                                         &&
 
> cdata.indexOf("notImposed")!=-1
>                                 ||  
> event.getValue("STImposed").toString().equals("1")
>                                         &&
 
> cdata.indexOf("notImposed")==-1){
>
>                         Node n =  
> doc.getElementById("value"+uids[0]).getChildNodes().item(0);
>                         n.setNodeValue(value);
>
>                        
>                      
> svgCreator.writeXmlToFile("d:\\marinho\\svgbib\\tmp2.svg", doc);
>                                
>                         }else {
>                                
>                                
>                                 if  
> (event.getValue("STImposed").toString().equals("1")){
>                                        
> //                                       se troca para
imposto
>                                         Document svgDoc
= svgDoc =  
> svgCreator.parseXmlFile(lib_dir+medida_imposta_dir, false);
>
>                                     // busca elemento
<g>
>                                     NodeList list =  
> svgDoc.getElementsByTagName("svg").item(0).getChildNodes();
>                                     Element gElement =
 
> (Element)list.item(1);
>                                     gElement.setAttribute("id",
uid );
>                                    
>                                     // Tratar da posição
dos elementos  
> e texto
>                                     NodeList l =  
> gElement.getChildNodes();
>                                    
>                                     for ( int i = 0 ;
i <  
> l.getLength() ; i++){
>                                        
>                                         if (  
> l.item(i).getNodeName().equals("text")){
>                                                
Element el = (Element)  
> l.item(i);
>                                                
>                                                
//para o elemento onde  
> o valor está contido tenha id unico
>                                                
 
> if(el.getAttribute("id").equals("value")) el.setAttribute("id",  
> el.getAttribute("id")+uids[0]);
>
>                                                
 
> el.setAttribute("y",posY);
>                                                
NodeList textList =  
> el.getChildNodes();
>                                                
>                                                
for (int j =0; j <  
> textList.getLength() ; j++){
>                                                
        if  
> (textList.item(j).getNodeValue()!=null &&  
> textList.item(j).getNodeValue().equals("XXXXXUIDXXXXX"))
>
>                                                
                 
> textList.item(j).setNodeValue(uid);
>                                                
        if  
> (textList.item(j).getNodeValue()!=null &&  
> textList.item(j).getNodeValue().equals("XXXXXTAGXXXXX"))
>
>                                                
                 
> textList.item(j).setNodeValue(tag);
>                                                
}
>                                         }
>                                        
>                                     }
>                                   
>                                    
>                                     // Make a copy of
the element  
> subtree suitable for inserting into doc2
>                                     Node dup =  
> doc.importNode(gElement, true);
>                                    
>                                      
> element.getParentNode().replaceChild(dup,element);
>                                    
>                                     //alterar o valor
>                                          
> doc.getElementById("value"+uids[0]).getChildNodes().item(0).setNodeValu 
> e(value);
>
>                                     //ver resultado num
ficheiro
>                                      
> svgCreator.writeXmlToFile("d:\\marinho\\svgbib\\tmp.svg", doc);
>                                        
>
>                                    
>                                 }else {
> //                                       not implemented
>                                 }
>                         }
>                         // fast repaint
>              
> jsvgCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new  
> Runnable(){public void run(){jsvgCanvas.repaint();}});
>
>         }
> ---------------------------------------------------------------
> Filipe Marinho
> filipe.marinho@se.efacec.pt
> EFACEC Sistemas de Electrónica, S.A
> Rua Engº Frederico Ulrich
> Apart. 3078 - 4471-907 Moreira Maia
> PORTUGAL
> Telf 229402000
> ---------------------------------------------------------------

Mime
View raw message