Hello again

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?:
Element elt = document.getElementById("elt-id");
        EventTarget t = (EventTarget)elt;
// Adds a 'onclick' listener
        t.addEventListener("click", new OnClickAction(), false);
public class OnClickAction implements EventListener {
        public void handleEvent(Event evt) {
            // Make some actions here...

            // ...for example schedule an action for later:
            window.setTimeout(new DelayedTask(), 500);
}
If yes, it's not good for me because I have to know element id, but I don't
know

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:

public class SVGBrowser extends JApplet 
{

  private JSVGCanvas jSVGCanvas1 = new JSVGCanvas();
  private static UserAgent userAgent = new UserAgentAdapter();
  private static DocumentLoader loader = new DocumentLoader(userAgent);
  private static BridgeContext  ctx = new BridgeContext(userAgent, loader);

...

public static void main(String[] args)
  {
    SVGBrowser applet = new SVGBrowser();
       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]

Reply via email to