sir, i tried what you suggested but it gives me the wrong node.. are there
any solutions for getting an attribute of a use element?

Here is the code.. use.svg is a simple svg file that has a use element..

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;

import org.apache.batik.swing.JSVGCanvas;
import org.apache.batik.swing.svg.SVGLoadEventDispatcherAdapter;
import org.apache.batik.swing.svg.SVGLoadEventDispatcherEvent;
import org.apache.batik.script.Window;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.events.Event;
import org.w3c.dom.events.EventListener;
import org.w3c.dom.events.EventTarget;
import org.w3c.dom.svg.SVGElement;

public class SVGApplication {

    public static void main(String[] args) {
        new SVGApplication();
    }
    JFrame frame;
    JSVGCanvas canvas;
    Document document;
    SVGElement svgRoot;
    Window window;

    public SVGApplication() {
        frame = new JFrame();
        canvas = new JSVGCanvas();
        // Forces the canvas to always be dynamic even if the current
        // document does not contain scripting or animation.
        canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
        canvas.addSVGLoadEventDispatcherListener(new
SVGLoadEventDispatcherAdapter() {

            public void
svgLoadEventDispatchStarted(SVGLoadEventDispatcherEvent e) {
                // At this time the document is available...
                document = canvas.getSVGDocument();
                // ...and the window object too.
                window = canvas.getUpdateManager().
                        getScriptingEnvironment().createWindow();
                // Registers the listeners on the document
                // just before the SVGLoad event is
                // dispatched.
                svgRoot = canvas.getSVGDocument().getRootElement();
                registerListeners();
                // It is time to pack the frame.
                frame.pack();
            }
        });

        frame.addWindowListener(new WindowAdapter() {

            public void windowOpened(WindowEvent e) {
                // The canvas is ready to load the base document
                // now, from the AWT thread.
                canvas.setURI("use.svg");
            }
            });

        frame.getContentPane().add(canvas);
        frame.setSize(800, 600);
        frame.show();
    }

    public void registerListeners() {
        // Gets an element from the loaded document.
        EventTarget t = (EventTarget) svgRoot;

        // Adds a 'onload' listener
        t.addEventListener("SVGLoad", new OnLoadAction(), false);

        // Adds a 'onclick' listener
        t.addEventListener("click", new OnClickAction(), false);
    }

    public class OnLoadAction implements EventListener {

        public void handleEvent(Event evt) {
        }
    }

    public class OnClickAction implements EventListener {

        public void handleEvent(Event evt) {
            System.out.println(((Element)evt.getTarget()).getNodeName());
           
System.out.println(((Element)evt.getCurrentTarget()).getNodeName());
        }
    }
}
-- 
View this message in context: 
http://www.nabble.com/attributes-of-%3Cuse%3E-element-tp16136023p16243939.html
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to