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:[EMAIL PROTECTED] Sent: Wednesday, March 10, 2004 12:10 PM
To: Batik Users
Subject: Re: SVG elemet info - script - applet


[EMAIL PROTECTED] 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




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



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



Reply via email to