Title: 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){
               
               
                       
                final String value = event.getValue("Value").toString();
                String uidAll = event.getValue("Uid").toString();
                final String[] uids = uidAll.split(":",2);
                String uid = uids[0]+event.getValue("Type");
                String tag = event.getValue("SxTag").toString();
                final 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){
                        // N�o troca de Simbolo (se est� n�o imposto continua se est� imposto continua imposto
               
                        jsvgCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new Runnable(){
                                public void run(){
                                       
                                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);

                                    // busca elemento <g>
                                    NodeList list = svgDoc.getElementsByTagName("svg").item(0).getChildNodes();
                                    final 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);
                                                }
                                        }
                                       
                                    }
                                  
                                        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);
                                                   
                                                    // Insert the copy into doc2
                                                    element.getParentNode().replaceChild(dup,element);
                                                   
                                                    //alterar o valor
                                                        doc.getElementById("value"+uids[0]).getChildNodes().item(0).setNodeValue(value);

                                               
                                                }});

                                   

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

                                   
                                }else {
//                                       se troca para n�o imposto
                                }
                        }
                        // fast repaint
            jsvgCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new Runnable(){public void run(){jsvgCanvas.repaint();           }});

        }
---------------------------------------------------------------
Filipe Marinho
[EMAIL PROTECTED]
EFACEC Sistemas de Electr�nica, S.A
Rua Eng� Frederico Ulrich
Apart. 3078 - 4471-907 Moreira Maia
PORTUGAL
Telf 229402000
---------------------------------------------------------------

Reply via email to