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 J Aaron Farr <ja...@yahoo.com> on 2002/08/02 19:40:42 UTC

Scripting Batik...

Does anyone have a nice example showing how to use javascript (in an svg file
displayed in batik) to call java methods?

I was looking at Mozilla's Rhino documentation (the javascript package used in
Batik).  At http://www.mozilla.org/rhino/scriptjava.html they have a nice
example of scripting java using LiveConnect, part of Rhino.  I thought this
would help in one of my current projects, so I included the following in an svg
document:

	function testjs(){
          importPackage(java.awt);
	  var frame = new Frame("JavaScript");
	  frame.show();
	  frame.setSize(new Dimension(200,100));
	  var but = new Button("OK");
	  frame.add(but);
	  frame.show();
	}

Then, on a <text> object, I added an "onclick" attribute and set it to
"testjs()".  I then loaded the svg file in a Batik SVGCanvas object.  Sure
enough, when I clicked the text, a little java frame and button popped up.

Cool.

So then I wanted to open one of my own frames, already defined in another part
of my package.  So I changed the javascript to something like this:

	function testjs(){
	 importPackage(Packages.mypackage);
	 var b = new MyFrame();
	 b.setUrl("http://myserver.com");
	 b.show();
	}

Now, the jar file that holds the batik browser I have contains both the batik
libraries and also my own package.  So I'm thinking they should be all in the
classpath.  But when I click on the text now, I get an error message saying
"MyFrame()" is not a defined function.

Does anyone know what I'm doing wrong here?  Anyone else know how to use
javascript to call some of my java classes and methods?

Thanks for any tips!
jaaron

__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com

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


Re: Scripting Batik...

Posted by Vincent Hardy <vi...@sun.com>.
Aaron,

J Aaron Farr wrote:
> [...]
> 
> So then I wanted to open one of my own frames, already defined in another part
> of my package.  So I changed the javascript to something like this:
> 
> 	function testjs(){
> 	 importPackage(Packages.mypackage);
> 	 var b = new MyFrame();
> 	 b.setUrl("http://myserver.com");
> 	 b.show();
> 	}
> 
> Now, the jar file that holds the batik browser I have contains both the batik
> libraries and also my own package.  So I'm thinking they should be all in the
> classpath.  But when I click on the text now, I get an error message saying
> "MyFrame()" is not a defined function.
> 
> Does anyone know what I'm doing wrong here?  Anyone else know how to use
> javascript to call some of my java classes and methods?
> 

You seem to be doing the right thing, so I suspect a typo in your class 
name or in the importPackage statement....

Vincent.


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