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 Javid Alimohideen <ja...@evl.uic.edu> on 2005/07/19 03:27:24 UTC

How to extend SVGOMGElement

Hi,
I have three different polygons (A, B and C) in my SVG document and based on
some input data, i have to create several of the above mentioned polygons
and add event listeners to it. When a user click on any of the shape, i am
trying to open an information box that would display some related
information (Something like google maps icons). I have to keep a track if an
icon has been clicked so that i would not create an another information box
and also store the related information. So my solution was to extend
SVGOMGElement in Batik and add some attributes to it to make it trackable
like "isClicked" and description.
Here is my code:
Class EventElement extends SVGOMGElement {
String desc; boolean isVisible;
}

and in my applet code i do this
EventElement elt = (EventElement) document.createElementNS(svgNS, "g");

I get a class cast Exception: org.apache.batik.svg.SVGOMGElement.

Can someone tell me what i am doing wrong?
Any other solutions are also appreciated.

Thanks,
Javid

A clever person solves a problem.
A wise person avoids it.

-- Einstein



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


RE: How to extend SVGOMGElement

Posted by Javid Alimohideen <ja...@evl.uic.edu>.
Thanks Thomas,
The way you suggested seems to be more appropriate.

Javid

A clever person solves a problem.
A wise person avoids it.

-- Einstein


-----Original Message-----
From: Thomas DeWeese [mailto:Thomas.DeWeese@Kodak.com]
Sent: Tuesday, July 19, 2005 4:58 AM
To: batik-users@xmlgraphics.apache.org
Subject: Re: How to extend SVGOMGElement


Javid Alimohideen wrote:

> I have three different polygons (A, B and C) in my SVG document and based
on
> some input data, i have to create several of the above mentioned polygons
> and add event listeners to it. When a user click on any of the shape, i am
> trying to open an information box that would display some related
> information (Something like google maps icons).

> I have to keep a track if an icon has been clicked so that i would
> not create an another information box and also store the related
> information. So my solution was to extend SVGOMGElement in Batik
> and add some attributes to it to make it trackable like "isClicked"
> and description.
> Here is my code:
> Class EventElement extends SVGOMGElement {
> String desc; boolean isVisible;
> }

    I would use the power of XML namespaces to do this.  Rather than
creating subclass you can just add new attributes to the existing
G element in your own namespace:

    g.setAttributeNS("edu.uic.evl.javid.maps", "is-visible", "true");

    The you can get the value with:

    String v = g.getAttributeNS("edu.uic.evl.javid.maps", "is-visible");

    This is I think the "correct" way to do.

> and in my applet code i do this
> EventElement elt = (EventElement) document.createElementNS(svgNS, "g");
>
> I get a class cast Exception: org.apache.batik.svg.SVGOMGElement.

    The basic problem is that you haven't told the DOM implementation
that you want it to use your G element when someone requests an
SVG 'g' element (BTW it's not really very nice to replace every
g with your custom impl, once again I would be tempted to make
your special 'g' a 'javid:eventGroup' element instead.

    But the answer to your question is that you need to register
a batik.dom.DomExtension these use the Java Services API. Take a
look at:

	http://xml.apache.org/batik/extendingBatik.html#domExtension

    And of course the example extensions in Batik:

	sources/org/apache/batik/extensions/svg/*

> Can someone tell me what i am doing wrong?
> Any other solutions are also appreciated.

    As I said I think a new element is barking up the wrong
tree and you should just add custom attributes.

>
> Thanks,
> Javid
>
> A clever person solves a problem.
> A wise person avoids it.
>
> -- Einstein
>
>
>
> ---------------------------------------------------------------------
> 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


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


Re: How to extend SVGOMGElement

Posted by Thomas DeWeese <Th...@Kodak.com>.
Javid Alimohideen wrote:

> I have three different polygons (A, B and C) in my SVG document and based on
> some input data, i have to create several of the above mentioned polygons
> and add event listeners to it. When a user click on any of the shape, i am
> trying to open an information box that would display some related
> information (Something like google maps icons). 

> I have to keep a track if an icon has been clicked so that i would 
> not create an another information box and also store the related 
> information. So my solution was to extend SVGOMGElement in Batik 
> and add some attributes to it to make it trackable like "isClicked" 
> and description.
> Here is my code:
> Class EventElement extends SVGOMGElement {
> String desc; boolean isVisible;
> }

    I would use the power of XML namespaces to do this.  Rather than
creating subclass you can just add new attributes to the existing
G element in your own namespace:

    g.setAttributeNS("edu.uic.evl.javid.maps", "is-visible", "true");

    The you can get the value with:

    String v = g.getAttributeNS("edu.uic.evl.javid.maps", "is-visible");

    This is I think the "correct" way to do.

> and in my applet code i do this
> EventElement elt = (EventElement) document.createElementNS(svgNS, "g");
> 
> I get a class cast Exception: org.apache.batik.svg.SVGOMGElement.

    The basic problem is that you haven't told the DOM implementation
that you want it to use your G element when someone requests an
SVG 'g' element (BTW it's not really very nice to replace every
g with your custom impl, once again I would be tempted to make
your special 'g' a 'javid:eventGroup' element instead.

    But the answer to your question is that you need to register
a batik.dom.DomExtension these use the Java Services API. Take a
look at:

	http://xml.apache.org/batik/extendingBatik.html#domExtension

    And of course the example extensions in Batik:

	sources/org/apache/batik/extensions/svg/*

> Can someone tell me what i am doing wrong?
> Any other solutions are also appreciated.

    As I said I think a new element is barking up the wrong
tree and you should just add custom attributes.

> 
> Thanks,
> Javid
> 
> A clever person solves a problem.
> A wise person avoids it.
> 
> -- Einstein
> 
> 
> 
> ---------------------------------------------------------------------
> 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