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 Janice Tan <ta...@gmail.com> on 2006/05/04 03:24:00 UTC
Re: using Java to write functions in SVG
okies think i get it thanks...
On 4/27/06, thomas.deweese@kodak.com <th...@kodak.com> wrote:
>
> Hi Janice,
>
> I suggest you read the DOM Events specification:
> http://www.w3.org/TR/2000/REC-DOM-Level-2-Events-20001113/events.html
>
> "Janice Tan" <ta...@gmail.com> wrote on 04/25/2006 10:21:38 PM:
>
> > i have another class to create the SVGDocument. in this class, i use a
> for
> > loop to create 'rect' elements for the bar segments.
> > Element e = document.createElementNS(svgNS, "rect");
> > e.setAttributeNS(null, "x", "xPos");
> > ....
> > root.appendChild(e);
> >
> > based on ur solution, does it mean that i would have to do something
> like
> > assign an id to the rect element and then:
>
> If you want you can attach the listener directly to the rects as
> you are creating them. The important part of the whole thing is that
> essentially all SVG elements implement the 'EventTarget' interface so
> you can call 'addEventListener(String type, EventListener l, boolean
> useCapture)'
> on them to register to have your listener object's handleEvent method
> called
> when an event of type 'type' occurs with that element.
>
> > also i would have to create another class for the DisplayAbout
> EventListener.
> > does this mean that for each event, i have to create a separate class?
> or can
> > i put them all into a single class?
>
> You can have a single class and check the 'type' member of the Event
> object
> passed to know why you're listener is called, but I typically register
> different listeners for different event types.
>
> It can also be useful to add custom attributes to elements that your
> listener can use to decide what action to take.
>
> > On 4/26/06, Lewis Keen <ye...@gmail.com> wrote:
> > Janice,
> >
> > In my project (Texas Hold'em poker game) I have an about button
> > element called "about" that has the register listener following line
> > in Java:
> >
> > pokerTable.registerListener("about","click",new DisplayAbout());
> >
> > which calls the following method in my PokerTable (Main GUI) class:
> >
> > public void registerListener(String element,String
> > action,EventListener listener)
> > {
> > try
> > {
> > Element elt = doc.getElementById(element);
> > EventTarget t = (EventTarget)elt;
> > t.addEventListener(action,listener,false);
> > }catch(Exception ex)
> > {
> > System.out.println("Error whilst registering
> Listener:
> > "+ex.getMessage());
> > }
> > }
> >
> > then my DisplayAbout EventListener does this:
> >
> > public class DisplayAbout implements EventListener {
> > public void handleEvent(Event evt) {
> > Thread displayThread=new Thread(){
> > public void run(){
> > try{
> > SplashScreen splash=new SplashScreen();
> > splash.setVisible(true);
> > }
> > catch (Exception ex)
> > {
> > System.out.println("An error with the poker client
> has
> > occured: "+ex.getMessage());
> > }
> > }
> > };
> > displayThread.start();
> > }
> > }
> >
> > So basically my method assigns a click EventListener on an XML element
> > in the document.
> >
> > Rinse and repeat for other elements/eventlisteners. I love how simple
> > and consequently how quick it is to expand :)
> >
> > Hope this helps,
> >
> > Lewis Keen
> > Final Year, Software Engineering
> > De Montfort University, Leicester
> >
> > On 4/25/06, janice tan < tan.janice@gmail.com> wrote:
> > >
> > > hi,
> > >
> > > am trying to implement a java application and have been trying to make
> use
> > > of the batik plugin with eclipse. i have been sucessful in creating a
> svg
> > > document for a bar chart and adding it to a JSVGCanvas to display.
> however,
> > > i would like to make my svg interactive and would need to include some
> > > mouseevents, linking and even loading anotehr svg on top.
> > > i have previously managed to do this in javascript. but am not sure if
> its
> > > possible through java.
> > >
> > > thanks
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>