java - Event clic with DOM / batik : Recovery the use tag which refers a symbol -
good evening,
i working on graphics application (handling svg file) in java use of batik directly manipulate dom document svg.
my various elements declared in "symbol" tags used , / displayed tags' "use ". here document svg:
<?xml version="1.0" encoding="utf-8" standalone="no"?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentscripttype="text/ecmascript" width="100%" zoomandpan="magnify" contentstyletype="text/css" height="100%" preserveaspectratio="xmidymid meet" version="1.0"> <defs> <g id="module-list"> <symbol preserveaspectratio="xmidymid meet" id="chaise_1.1.2" version="1.1.2" viewbox="0 0 200 256" module="chaine"> <polygon fill="inherit" clip-rule="evenodd" fill-rule="evenodd" points="184.055,256.09 184.055,256.09 184.055,148.195 199.135,148.195 199.135,256.09 "/> <polygon fill="inherit" clip-rule="evenodd" fill-rule="evenodd" points="83.006,201.214 83.006,201.214 83.006,187.532 182.656,187.532 182.656,201.214 "/> <polygon fill="inherit" clip-rule="evenodd" fill-rule="evenodd" points="83.006,169.963 83.006,169.963 83.006,149.286 182.656,149.286 182.656,169.963 "/> <path fill="inherit" clip-rule="evenodd" d="m94.664,133.266l94.664,133.266c8.183-2.792,23.189-5.077,45.008-6.836 c21.818-1.76,38.142-1.219,48.972,1.631c10.831,2.85,16.246,9.305,16.246,19.354h82.382 c82.382,140.779,86.473,136.071,94.664,133.266z" fill-rule="evenodd"/> <path fill="inherit" clip-rule="evenodd" d="m55.951,25.838c-5.393-15.133-5.964-23.633-1.714-25.497 c7.672-1.866,13.17,6.633,16.486,25.497c7.25,35.553,10.885,69.858,10.885,102.921v127.33h66.369l0.308-126.706 c66.677,96.004,63.104,61.497,55.951,25.838z" fill-rule="evenodd"/> </symbol> </g> </defs> <g id="plan-list"> <g id="namezone1"> <rect fill="#000000" x="0" width="500" height="500" y="0"/> <use x="50" y="20" fill="#f5a9d0" width="20" xlink:href="#chaise_1.1.2" xlink:type="simple" xlink:actuate="onload" height="200" xlink:show="embed"/> <use x="50" y="60" width="20" xlink:href="#chaise_1.1.2" xlink:type="simple" xlink:actuate="onload" height="200" xlink:show="embed"/> </g> <g id="namezone2"> <rect fill="#0000ff" x="500" width="500" height="500" y="0"/> <use x="550" y="20" width="20" xlink:href="#chaise_1.1.2" xlink:type="simple" xlink:actuate="onload" height="200" xlink:show="embed"/> <use x="550" y="60" width="20" xlink:href="#chaise_1.1.2" xlink:type="simple" xlink:actuate="onload" height="200" xlink:show="embed"/> </g> </g> </svg> i added event on element of svg:
((eventtarget) objadd.getnodeuse()).addeventlistener( svgconstants.svg_mousedown_event_type, new eobject(), false); ((eventtarget) objadd.getnodedefs()).addeventlistener( svgconstants.svg_mousedown_event_type, new eobject(), false); and on zone (match group elements g)
element elt = doc.getelementbyid("namezone1"); eventtarget t = (eventtarget)elt; t.addeventlistener(svgconstants.svg_mousedown_event_type, new eobject(), false); the class eobject implements org.w3c.dom.events.eventlistener:
import org.w3c.dom.element; import org.w3c.dom.events.event; public class eobject implements org.w3c.dom.events.eventlistener { public void handleevent(event evt) { system.out.println("youpiiii je suis clique"); element e = (element) evt.getcurrenttarget(); } } when click on object (theoretically node use), handleevent function return group of element g (id="namezone1).
i retrieve item "use" corresponding clicked item.
when remove code :
element elt = doc.getelementbyid("namezone1"); eventtarget t = (eventtarget)elt; t.addeventlistener(svgconstants.svg_mousedown_event_type, new eobject(), false); a click on element engenders nothing.
this why getcurrenttarget () me references g matching items.
the problem must event add item.
again if have idea, welcome ..
thank help.
defs , symbols not drawn svg.
if add eventlistener use element have give id.
in svg file:
<use id="use3430" xlink:show="embed" height="200" xlink:actuate="onload" xlink:type="simple" xlink:href="#chaise_1.1.2" width="20" y="20" x="550" /> then can doc.getelementbyid("use3430");
greetings
Comments
Post a Comment