xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bartosz Celmer <JOHN...@idea.net.pl>
Subject RE: SVG elemet info - script - applet
Date Thu, 18 Mar 2004 21:08:23 GMT
Hi Thomas

I've made some progress today, but still have some problems with live
connect. My code look like this no:

            public void gvtRenderingCompleted(GVTTreeRendererEvent e) {
                label.setText("");
                BridgeContext  ctx =
jSVGCanvas1.getUpdateManager().getBridgeContext();
                Interpreter interp = ctx.getInterpreter("text/ecmascript");

                interp.bindObject( "appletHost", this); 
            }

My simple function in my applet look like this:

Public void test()
{
 Label.setText("Mission successful !!!");

}

Svg look like this:

<?xml version="1.0" encoding="iso-8859-1" standalone='no'?>

<svg id="svg1" width='400' height='400' viewBox="00 0 400 400"> 
<script type="text/ecmascript"> <![CDATA[
function circle_click() {
 appletHost.Test();}
]]>
</script>
<circle id ="cir1" onclick="circle_click()" style="fill:blue;stroke:navy;"
cx="200" cy="200" r="100"/>
</svg>

Compiling and running goes fine but when I click at my element in SVG I get
this:

TypeError: undefined is not a function. (Inline <script>
file:/D:/Java/Applet/Workspace3/Project1/classes/SVG/svg1_script.svg:4; line
3)

	at
org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:597)

	at
org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:557)

	at
org.mozilla.javascript.NativeGlobal.typeError1(NativeGlobal.java:567)

	at
org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1182)

	at org.mozilla.javascript.gen.c1.call(Inline <script>
file:/D:/Java/Applet/Workspace3/Project1/classes/SVG/svg1_script.svg:4:3)

	at
org.mozilla.javascript.optimizer.OptRuntime.callSimple(OptRuntime.java:275)

	at org.mozilla.javascript.gen.c4.call(Event attribute
file:/D:/Java/Applet/Workspace3/Project1/classes/SVG/svg1_script.svg:9
onclick:1)

	at org.mozilla.javascript.gen.c4.exec(Event attribute
file:/D:/Java/Applet/Workspace3/Project1/classes/SVG/svg1_script.svg:9
onclick)

	at org.mozilla.javascript.Context.evaluateReader(Context.java:820)

	at org.apache.batik.script.rhino.RhinoInterpreter.evaluate(Unknown
Source)

	at
org.apache.batik.bridge.ScriptingEnvironment.runEventHandler(Unknown Source)

	at
org.apache.batik.bridge.ScriptingEnvironment$ScriptingEventListener.handleEv
ent(Unknown Source)

	at
org.apache.batik.dom.events.EventSupport.fireEventListeners(Unknown Source)

	at org.apache.batik.dom.events.EventSupport.dispatchEvent(Unknown
Source)

	at org.apache.batik.dom.AbstractNode.dispatchEvent(Unknown Source)

	at
org.apache.batik.bridge.BridgeEventSupport$Listener.dispatchMouseEvent(Unkno
wn Source)

	at
org.apache.batik.bridge.BridgeEventSupport$Listener.dispatchMouseEvent(Unkno
wn Source)

	at
org.apache.batik.bridge.BridgeEventSupport$Listener.mouseClicked(Unknown
Source)

	at
org.apache.batik.gvt.event.AWTEventDispatcher.processMouseEvent(Unknown
Source)

	at
org.apache.batik.gvt.event.AWTEventDispatcher.dispatchMouseEvent(Unknown
Source)

	at
org.apache.batik.gvt.event.AWTEventDispatcher.dispatchEvent(Unknown Source)

	at
org.apache.batik.gvt.event.AWTEventDispatcher.mouseClicked(Unknown Source)

	at org.apache.batik.swing.svg.JSVGComponent$17.run(Unknown Source)

	at org.apache.batik.util.RunnableQueue.run(Unknown Source)

	at java.lang.Thread.run(Unknown Source)

An idea what I did wrong?

Thanks Bartosz




-----Original Message-----
From: Thomas DeWeese [mailto:Thomas.DeWeese@Kodak.com] 
Sent: Thursday, March 18, 2004 2:37 PM
To: Batik Users
Subject: Re: SVG elemet info - script - applet

Hi Bartosz,

Bartosz Celmer wrote:

 > I tried to do what did you propose, but in first case, I don't
 > know what exactly you mean.
> 
> Should I do something like this?:

    This is close but you can add your event listener on the
Root SVG element and thus get notified of all click events
for any element in the document.

    You can get the element clicked on with:

     Element e = evt.getTarget();

> I also tried your second suggestion but it fails again. (Maybe because I'm
> not as good programmer as I should be ;) )
> 
> I write something like this in my applet code:

    Also very close but you need to use the BridgeContext from
the document you loaded for the bind call, everything else looked
right to me.

> public class SVGBrowser extends JApplet 
> {
> 
>   private JSVGCanvas jSVGCanvas1 = new JSVGCanvas();
> 
> ...
> 
> public static void main(String[] args)
>   {
>     SVGBrowser applet = new SVGBrowser();

       Interpreter interp = 
applet.jSVGCanvas1.getUpdateManager().getBridgeContext();

     Note that you can only get the UpdateManager (and hence
BridgeContext) after the document is loaded:

      * Returns the current update manager.  The update manager becomes
      * available after the first rendering completes.  You can be
      * notifed when the rendering completes by registering a
      * GVTTreeRendererListener with the component and waiting for the
      * <tt>gvtRenderingCompleted</tt> event.

>        Interpreter interp = ctx.getInterpreter("text/ecmascript");
>       interp.bindObject( "appletHost", applet);  
> ...
> 
> 
> Public void someFunction(String info)
> 
> 	{
> 		//some code 
> 	}
> 
> 
> }
> 
> 
> And my svg file look like this 
> 
> <svg id="svg1" width='400' height='400' viewBox="00 0 400 400"> 
> <script type="text/ecmascript"> <![CDATA[
> function circle_click(info) {
>  appletHost.someFunction(info); 
> }
> ]]>
> </script>
> <circle id ="cir1" onclick="circle_click('info about element')"
> style="fill:blue;stroke:navy;" cx="200" cy="200" r="100"/>
> </svg>
> 
> 
> In this case I got SVG error: "appletHost" is not defined
> Probably I do something wrong in line: 
> 
> private static BridgeContext  ctx = ...
> 
> What should I put instead of (...)
> 
> Hope that you will help me solve this problem 
> 
> Thank You 
> 
> Bartosz Celmer
> 
> 
> -----Original Message-----
> From: Thomas DeWeese [mailto:Thomas.DeWeese@Kodak.com] 
> Sent: Wednesday, March 10, 2004 12:10 PM
> To: Batik Users
> Subject: Re: SVG elemet info - script - applet
> 
> bcelmer@idea.net.pl wrote:
> 
> 
>>I'm working on project using Batik to view GIS info in applet. 
>>I'd like to get some info about element clicked by user. Could 
>>you give me some advise how to do this. I tried do use java script, 
>>but I don&#8217;t know how to send info from SVG/script to applet 
>>(call procedure in my applet when clicked on element).  
> 
> 
>    The easiest thing to do is to add Java Objects as event
> handlers on the SVG Elements using 'addEventHandler'.  This would
> totally avoid using JavaScript and have your Java class called
> directly in response to user actions.
> 
> 
> 
>>The best for me would be if I could do something like this in SVG:
>>
>><svg id="svg1" width='400' height='400' viewBox="00 0 400 400"> 
>>
>><script type="text/ecmascript"> <![CDATA[
>>function elem_click(info) {
>>   some code to call applet procedure 
>>}
>>
>>I don't know if is got way I'm thinking but I suspect that I have to 
>>customize Rhino Interpreter. Am I right?
> 
> 
>     Rhino has a feature call 'live connect' so you can call methods on
> Java Objects directly from JavaScript.  Probably the easiest way to do
> this would be to bind a 'host' object into the interpreter. Then you
> can just call methods on that host object from your script.
> 
>       BridgeContext ctx = ...
>       Interpreter interp = ctx.getInterpreter("text/ecmascript");
>       interp.bindObject("appletHost", hostObj);
> 
>  From Script:
> 
>      appletHost.someFunction("Some Text", 10, 20);
> 
> 
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org



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




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


Mime
View raw message