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 darkshadow <ed...@hotmail.com> on 2011/07/26 17:45:53 UTC

Applet does not display

Hi guys this is my first post in the forum.

I'm just started to use the batik framework.
I'm writing an applet to show a svg file. I use eclipse as IDE to develop
the applet an it works. It show me the svg file.
When i tried to do the same on an html page using the applet tag, the applet
doesn't show at all.
I've added an display message on start of the applet and i see it but the
svg file isn't show.
Can anyone help me?

the Source of the applet is the following:

public class SVGViewer extends JApplet {

    JSVGCanvas svgCanvas;
    Document document;
    Window window;
    
	public void init()
	{
		String svgName;
		try
		{
			svgCanvas = new JSVGCanvas();
			getContentPane().add(svgCanvas);
			
			svgName = getParameter("svgName");
			
			// Parse the barChart.svg file into a Document.
	        String parser = XMLResourceDescriptor.getXMLParserClassName();
	        //SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
			URL url = new URL(getCodeBase(), svgName);
			svgCanvas.setURI(url.toString());
			
	        //document = f.createDocument(url.toString());
			setBackground(Color.ORANGE);
		}
		catch (Exception e) {
			// TODO: handle exception
		}
	}
	
	public void start()
	{
		JOptionPane.showMessageDialog(this, "STart");
		svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
		//svgCanvas.setDocument(document);
		//svgCanvas.setURI("a/846004349.image");
		try
		{
		svgCanvas.addSVGLoadEventDispatcherListener
        (new SVGLoadEventDispatcherAdapter() {
                public void svgLoadEventDispatchStarted
                    (SVGLoadEventDispatcherEvent e) {
                    // At this time the document is available...
                    document = svgCanvas.getSVGDocument();
                    Element root = document.getDocumentElement();
                    int w =
(int)Double.parseDouble(root.getAttribute("width"));
                    int h =
(int)Double.parseDouble(root.getAttribute("height"));
                    
                    setSize(w, h);
                    
                    // ...and the window object too.
                    window =
svgCanvas.getUpdateManager().getScriptingEnvironment().createWindow();
                    //window.alert("INIt");
                    // Registers the listeners on the document
                    // just before the SVGLoad event is dispatched.
                    registerListeners();
                    // It is time to pack the frame.
                }
            });
		}
		catch (Exception e) {
			// TODO: handle exception
		}
		//window =
svgCanvas.getUpdateManager().getScriptingEnvironment().createWindow();
	}
	
	public void stop()
	{
		svgCanvas.setDocument(null);
	}
	
	public void destroy()
	{
		svgCanvas.dispose();
	}
	
	public void registerListeners() {
        // Gets an element from the loaded document.
    	String QS = document.getDocumentURI();
        
    	if(QS.indexOf("schemazoompre.aspx")!=-1)
    	{
    	    QS = QS.replace("schemazoompre.aspx","main.aspx");
    	}
    	
    	// Gets an element from the loaded document.
    	NodeList nl = document.getElementsByTagName("g");
    	for (int i = 0; i < nl.getLength(); i++)
    	{
    		if(nl.item(i).getAttributes().getNamedItem("onload") != null)
    		{
    			EventTarget t = (EventTarget)nl.item(i);
    			t.addEventListener("mouseover", new OnMouseOver(), false);
    			t.addEventListener("mouseout", new OnMouseOut(), false);
    		}
    	}
    }
    public class OnMouseOver implements EventListener {
        public void handleEvent(Event evt) {
            // Make some actions here...
            // ... for example schedule an action for later:
        	Element target = (Element)evt.getTarget();
        	target = (Element)target.getParentNode();
        	//window.alert(target.getTagName() + " : " +
target.getNodeValue());
        	NodeList nl = target.getElementsByTagName("*");
        	for (int i = 0; i < nl.getLength(); i++)
        	{
        		//window.alert(nl.item(i).getNodeName());
        		if(nl.item(i).getAttributes().getNamedItem("stroke") != null)
        		{
        			//window.alert("Stroke");
	        		Attr a = document.createAttribute("stroke");
	        		a.setNodeValue("#03a8f8");
	        		nl.item(i).getAttributes().setNamedItem(a);
        		}
        		else if(nl.item(i).getAttributes().getNamedItem("fill")!= null &&
nl.item(i).getNodeName() != "rect")
                {
        			//window.alert("fill & !rect");
        			Attr a = document.createAttribute("fill");
	        		a.setNodeValue("#03a8f8");
	        		nl.item(i).getAttributes().setNamedItem(a);
                }
                else if(nl.item(i).getNodeName() == "text")
                {
                	//window.alert("text1");
                	Attr a = document.createAttribute("fill");
	        		a.setNodeValue("#03a8f8");
	        		nl.item(i).getAttributes().setNamedItem(a);
                }
        	}
        }
    }
    
    public class OnMouseOut implements EventListener {
        public void handleEvent(Event evt) {
            // Make some actions here...
            // ... for example schedule an action for later:
        	Element target = (Element)evt.getTarget();
        	target = (Element)target.getParentNode();
        	//window.alert(target.getTagName() + " : " +
target.getNodeValue());
        	NodeList nl = target.getElementsByTagName("*");
        	for (int i = 0; i < nl.getLength(); i++)
        	{
        		//window.alert(nl.item(i).getNodeName());
        		if(nl.item(i).getAttributes().getNamedItem("stroke") != null &&
nl.item(i).getAttributes().getNamedItem("stroke").getNodeValue() ==
"#03a8f8")
        		{
        			//window.alert("Stroke");
	        		Attr a = document.createAttribute("stroke");
	        		a.setNodeValue("#000000");
	        		nl.item(i).getAttributes().setNamedItem(a);
        		}
        		else if(nl.item(i).getAttributes().getNamedItem("fill")!= null &&
nl.item(i).getAttributes().getNamedItem("fill").getNodeValue() == "#03a8f8")
                {
        			//window.alert("fill & !rect");
        			Attr a = document.createAttribute("fill");
	        		a.setNodeValue("#000000");
	        		nl.item(i).getAttributes().setNamedItem(a);
                }
        	}
        }
    }
}

Thanks

E

--
View this message in context: http://batik.2283329.n4.nabble.com/Applet-does-not-display-tp3696178p3696178.html
Sent from the Batik - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org