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 Filipe Marinho <fi...@SE.EFACEC.PT> on 2005/06/09 15:46:23 UTC

Replace an Element on DOMtree and refresh the jsvgcanvas.

Hi, 

Well i have a usual problem but still hard to get the solution ( at least
for me :p ). 
I wanted to replace an element in the DOMtree and get the consequent results
at the jsvgcanvas.
I've manage to replace correctly the element on the DOM but i couldn't
visualise it. 
I've tried to change only an nodeValue, and the canvas refreshed perfectly,
but when i try to replace an node (element) the canvas erase the element but
it dont draw the new one...!!!
I saved the DOM to a file and it was as i wanted.  Here is the method i
use...

P.S. 

        - My Document is dynamic.
        - I'm new in SVG. I realy neaded some help   :P


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();
		Element element_temp = (Element)nl.item(nl.getLength()-4);
		String posY = element_temp.getAttribute("y");
		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);
				
			}else {
				
				
				if
(event.getValue("STImposed").toString().equals("1")){
					
//					 se troca para imposto
					Document svgDoc = svgDoc =
svgCreator.parseXmlFile(lib_dir+medida_imposta_dir, false);

				    // element "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);

				    
				    //alterar o valor
	
doc.getElementById("value"+uids[0]).getChildNodes().item(0).setNodeValue(val
ue);

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

				    
				}else {
//					 not implemented
				}
			}
			// repaint !!!!

	
jsvgCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new
Runnable(){public void run(){jsvgCanvas.repaint();	
	}
---------------------------------------------------------------
Filipe Marinho
filipe.marinho@se.efacec.pt
---------------------------------------------------------------