Hi Thomas,
I read the DOM interface, but I still can't get the red circles to change
the colour when clicked, here's my code ...I'm sorry for being a nuisance.
Element element = doc.getElementById("circleGroup");
EventTarget eventTarget = (EventTarget) element;
eventTarget.addEventListener("click",new CircleAction(),false);
class CircleAction implements EventListener
{
public void handleEvent(Event evt)
{
Element elt = (Element) evt.getCurrentTarget();
if (evt.getType() == "click")
{
elt.setAttributeNS("circle","fill","yellow");
}
}
ThankU
yasmin
> Hi Yasmin,
>
> Please read the DOM interfaces. This is the third time you have
> failed to lookup
> the interface that provides a method. BTW most of the time you want to
> use
> evt.getTarget().
>
> [EMAIL PROTECTED] wrote on 03/12/2006 08:08:23 PM:
>
>> Hi Thomas,
>>
>> This is the code for my CircleAction,
>>
>> public class CircleAction implements EventListener
>> {
>> public void handleEvent(Event evt)
>> {
>> Element elt = (Element) evt.getCurrentTarget();
>>
>> if (evt.getType() == "click")
>> {
>> elt.setAttributeNS(SVG_NS, "fill", "yellow");
>> }
>> }
>> }
>>
>> The evt.getCurrentTarget() is not recognised?
>>
>> Thx
>>
>> yasmin
>>
>>
>>
>>
>> > Hi Yasmin,
>> >
>> > [EMAIL PROTECTED] wrote on 03/12/2006 06:24:15 PM:
>> >
>> >> I've tried this, but again I have a problem with the paranthesis of
> the
>> >> addEventListener?
>> >
>> > What is the error?
>> > Does CircleAction implement the DOM EventListener interface?
>> >
>> > org.w3c.dom.events.EventListener;
>> >
>> >
>> >> NodeList circleList = doc.getElementsByTagName("circle");
>> >
>> > You only need to add one event listener to the circleGroup.
>> > Then use evt.getTarget() to know what circle it is.
>> >
>> >> for (int count = 0; count < circleList.getLength(); count++) {
>> >> EventTarget eventTarget = (EventTarget) circleList.item(count);
>> >> eventTarget.addEventListener("click",new CircleAction(),false);
>> >> }
>> >>
>> >> Thx
>> >>
>> >> yasmin
>> >>
>> >>
>> >>
>> >> > Hi Yasmin,
>> >> >
>> >> > [EMAIL PROTECTED] wrote on 03/12/2006 05:54:00 PM:
>> >> >
>> >> >> Now I'm trying to make the red circles clickable, I've tried this
>> > code
>> >> > but
>> >> >> for some reason I can't get the element.addEventListener?
>> >> >
>> >> > addEventListener is on the EventTarget interface. So you
>> >> > will need to cast the element to add the listener.
>> >> >
>> >> >>
>> >> >> Element element = doc.getElementById("circleGroup");
>> >> >> element.addEventListener("click", new CircleAction(), false);
>> >> >>
>> >> >> Thx
>> >> >>
>> >> >> yasmin
>> >> >>
>> >> >> > Hi Yasmin,
>> >> >> >
>> >> >> > [EMAIL PROTECTED] wrote on 03/12/2006 03:44:08 PM:
>> >> >> >
>> >> >> >> Here's the heading of my svg file, can you see anything that
> might
>> > be
>> >> >> >> causing the red circles not appearing?
>> >> >> >
>> >> >> >> viewBox="424000.000 -518000 2000 2000"
>> >> >> >
>> >> >> > Your viewBox certainly doesn't intersect any of the coords
>> >> >> > in your example source code. When you add the elements to the
>> >> >> > Document you need to place your circles in the 'maps' coordinate
>> >> >> > system (which normally is simplier for you).
>> >> >> >
>> >> >> > So the cx & cy for a circle should look something like
>> >> >> > cx="425100"
>> >> >> > cy="-519100"
>> >> >> >
>> >> >> >> > One other comment on the code. I would suggest using the
>> >> >> >> > JSVGScrollPane
>> >> >> >> > instead of the swing JScrollPane. The JScrollPane works in
> most
>> >> > cases
>> >> >> >> > it tends to be much less efficient than the JSVGScrollPane.
>> >> >> >> >
>> >> >> >> > [EMAIL PROTECTED] wrote on 03/12/2006 03:01:19 PM:
>> >> >> >> >
>> >> >> >> >> Hi Yasmin,
>> >> >> >> >>
>> >> >> >> >> Your test code worked fine for me with one change, you
> had:
>> >> >> >> >>
>> >> >> >> >> Element e =
>> >> >> >> >> doc.createElementNS(SVGNS,"spot");
>> >> >> >> >>
>> >> >> >> >> This isn't right you want:
>> >> >> >> >>
>> >> >> >> >> Element e =
>> >> >> >> >> doc.createElementNS(SVGNS,"circle");
>> >> >> >> >>
>> >> >> >> >> Which is odd because an earlier e-mail had 'circle'
>> >> >> >> >> I tested by opening 'samples/mapSpain.svg'. I think two of
>> > your
>> >> >> > circles
>> >> >> >> >> still didn't show because mapSpain isn't quite large enough
> but
>> >> > the
>> >> >> > ones
>> >> >> >> >> that should show did.
>> >> >> >> >>
>> >> >> >> >> [EMAIL PROTECTED] wrote on 03/12/2006 02:07:00 PM:
>> >> >> >> >>
>> >> >> >> >> > I've just attached the java file only!
>> >> >> >> >> >
>> >> >> >> >> > Tx
>> >> >> >> >> > yasmin
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> > > Hi Yasmin,
>> >> >> >> >> > >
>> >> >> >> >> > > [EMAIL PROTECTED] wrote on 03/12/2006 10:45:17 AM:
>> >> >> >> >> > >
>> >> >> >> >> > >> Now when I run my code I get the following error:
>> >> >> >> >> > >>
>> >> >> >> >> > >> org.w3c.dom.DOMException: The current document is
> unable
>> > to
>> >> >> > create
>> >> >> >> > an
>> >> >> >> >> > >> element of the requested type (namespace:
>> >> >> >> > http://www.w3.org/2000/svg,
>> >> >> >> >> > >> name: spot).
>> >> >> >> >> > >
>> >> >> >> >> > > Batik's DOM implementation prevents you from creating
>> >> > elements
>> >> >> > in
>> >> >> >> >
>> >> >> >> >> the
>> >> >> >> >> > > SVG Namespace that aren't part of the SVG specification.
>> >> >> >> >> > >
>> >> >> >> >> > > As far as path forward, I would suggest taking the
> code
>> > to
>> >> >> > create
>> >> >> >> >
>> >> >> >> >> the
>> >> >> >> >> > > circles and put it in a small example that just puts of
> the
>> >> >> > canvas
>> >> >> >> >> > > (with any old document) and a button that adds a list of
>> >> > preset
>> >> >> >> >> circles.
>> >> >> >> >> > >
>> >> >> >> >> > > Then with all the code together I can either spot the
>> > error
>> >> > or
>> >> >> >> >> > > run it and debug why it isn't working for you.
>> >> >> >> >> > >
>> >> >> >> >> > >>
>> >> >> >> >> > >> at
>> >> >> > org.apache.batik.dom.AbstractNode.createDOMException(Unknown
>> >> >> >> >> > > Source)
>> >> >> >> >> > >>
>> >> >> >> >> > >> at
>> >> >> >> >> > >
>> >> >> >> >
>> >> >
> org.apache.batik.dom.svg.SVGDOMImplementation.createElementNS(Unknown
>> >> >> >> >> > >> Source)
>> >> >> >> >> > >>
>> >> >> >> >> > >> at
>> >> >> >> >
> org.apache.batik.dom.svg.SVGOMDocument.createElementNS(Unknown
>> >> >> >> >> > > Source)
>> >> >> >> >> > >>
>> >> >> >> >> > >> at
>> >> >> >> >
> mypackage22.KeyAccidentClient$4.run(KeyAccidentClient.java:349)
>> >> >> >> >> > >>
>> >> >> >> >> > >> at org.apache.batik.util.RunnableQueue.run(Unknown
>> > Source)
>> >> >> >> >> > >>
>> >> >> >> >> > >> at java.lang.Thread.run(Thread.java:534)
>> >> >> >> >> > >>
>> >> >> >> >> > >> Pls advice.
>> >> >> >> >> > >>
>> >> >> >> >> > >> Thx
>> >> >> >> >> > >>
>> >> >> >> >> > >> yasmin
>> >> >> >> >> > >>
>> >> >> >> >> > >>
>> >> >> >> >> > >>
>> >> >> >> >> > >>
>> >> >> >> >> > >> > Hi Yasmin,
>> >> >> >> >> > >> >
>> >> >> >> >> > >> > [EMAIL PROTECTED] wrote on 03/12/2006 06:04:36
> AM:
>> >> >> >> >> > >> >
>> >> >> >> >> > >> >> When I tried putting a line to test if the code is
>> >> > running,
>> >> >> > the
>> >> >> >> >> code
>> >> >> >> >> > >> > does
>> >> >> >> >> > >> >> run, but apparently it does not create any elements,
>> >> > here's
>> >> >> > what
>> >> >> >> > I
>> >> >> >> >> > >> > tested:
>> >> >> >> >> > >> >>
>> >> >> >> >> > >> >> System.out.println("This is just testing :" +
>> >> >> >> >> > >> > g.getAttribute("circleGroup"));
>> >> >> >> >> > >> >>
>> >> >> >> >> > >> >> and nothing prints for g.getAttribute ...
>> >> >> >> >> > >> >
>> >> >> >> >> > >> > This is expected, I think you want to use:
>> >> >> >> >> > >> > g.getAttributeNS(null, "id");
>> >> >> >> >> > >> >
>> >> >> >> >> > >> > This should result in the string 'circleGroup'.
>> >> >> >> >> > >> >
>> >> >> >> >> > >> >> > [EMAIL PROTECTED] wrote on 03/11/2006
> 05:44:31
>> > PM:
>> >> >> >> >> > >> >> >
>> >> >> >> >> > >> >> >> I did initially try to add the red circles to the
>> > svg
>> >> >> >> > document
>> >> >> >> >> > >> >> >> programatically, infact I think you emailed me a
>> >> > snippet
>> >> >> > of
>> >> >> >> >> your
>> >> >> >> >> > > code
>> >> >> >> >> > >> >> >> but it doesn't work, the code compiles but does
> not
>> >> >> > display
>> >> >> >> > the
>> >> >> >> >> > >> >> >> red-circles, I tried to repaint my canvas, that
>> > don't
>> >> >> > work...
>> >> >> >> >> > > here's
>> >> >> >> >> > >> >> >> the code I'm using maybe you might be able to
> spot
>> >> > where
>> >> >> > I'm
>> >> >> >> >> > > making
>> >> >> >> >> > >> >> >> the error...
>> >> >> >> >> > >> >> >
>> >> >> >> >> > >> >> > The code looks pretty good. You aren't that
> far
>> > from
>> >> > a
>> >> >> >> >> > >> >> > standalone example, this would help me help you...
>> >> >> >> >> > >> >> >
>> >> >> >> >> > >> >> >> //I added this in my constructor
>> >> >> >> >> > >> >> >>
> canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
>> >> >> >> >> > >> >> >
>> >> >> >> >> > >> >> > This must be done _before_ you set the document
> on
>> >> > the
>> >> >> >> >> canvas.
>> >> >> >> >> > >> >> >
>> >> >> >> >> > >> >> >> //The following code I added in my ActionListener
>> >> > triggred
>> >> >> > by
>> >> >> >> > a
>> >> >> >> >> > >> > button
>> >> >> >> >> > >> >> >
>> >> >> >> >> > >> >> > Are you sure this code runs? Some println's
> might
>> >> > help
>> >> >> >> > make
>> >> >> >> >> > > sure
>> >> >> >> >> > >> >> > that your spots list isn't empty for some reason,
>> > etc.
>> >> > You
>> >> >> >> >> don't
>> >> >> >> >> > >> >> > need to 'repaint' the canvas.
>> >> >> >> >> > >> >> >
>> >> >> >> >> > >> >> >>
>> >> >> >> >>
>> > canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new
>> >> >> >> >> > >> >> >> Runnable() {
>> >> >> >> >> > >> >> >>
>> >> >> >> >> > >> >> >> public void run()
>> >> >> >> >> > >> >> >> {
>> >> >> >> >> > >> >> >> SVGDocument doc =
>> >> >> >> >> canvas.getSVGDocument();
>> >> >> >> >> > >> >> >> String SVGNS =
>> >> >> >> >> > > "http://www.w3.org/2000/svg";
>> >> >> >> >> > >> >> >> Iterator i =
>> > spots.iterator();
>> >> >> >> >> > >> >> >> Element g =
>> >> >> >> >> > >> > doc.getElementById("circleGroup");
>> >> >> >> >> > >> >> >> if (g == null)
>> >> >> >> >> > >> >> >> {
>> >> >> >> >> > >> >> >> g =
>> >> >> > doc.createElementNS(SVGNS,"g");
>> >> >> >> >> > >> >> >> g.setAttributeNS(null,
>> > "id",
>> >> >> >> >> > >> > "circleGroup");
>> >> >> >> >> > >> >> >> doc.getRootElement().appendChild(g);
>> >> >> >> >> > >> >> >> }
>> >> >> >> >> > >> >> >>
>> >> >> >> >> > >> >> >>
>> >> >> >> >> > >> >> >> while (i.hasNext())
>> >> >> >> >> > >> >> >> {
>> >> >> >> >> > >> >> >> Point2D pt2d =
> (Point2D)
>> >> >> > i.next();
>> >> >> >> >> > >> >> >> Element e =
>> >> >> >> >> > >> >> > doc.createElementNS(SVGNS,"circle");
>> >> >> >> >> > >> >> >> e.setAttributeNS(null,"cx",""+pt2d.getX());
>> >> >> >> >> > >> >> >> e.setAttributeNS(null,"cy",""+pt2d.getY());
>> >> >> >> >> > >> >> >> e.setAttributeNS(null,"r","8");
>> >> >> >> >> > >> >> >> e.setAttributeNS(null,"fill","Red");
>> >> >> >> >> > >> >> >> g.appendChild(e);
>> >> >> >> >> > >> >> >> }
>> >> >> >> >> > >> >> >> }
>> >> >> >> >> > >> >> >> });
>> >> >> >> >> > >> >> >>
>> >> >> >> >> > >> >> >> canvas.repaint();
>> >> >> >> >> > >> >> >
>> >> >> >> >> > >> >> >
>> >> >> >> >> > >> >> >
>> >> >> >> >> > >
>> >> >> >> >
>> >> >
> ---------------------------------------------------------------------
>> >> >> >> >> > >> >> > 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]
>> >> >> >> >> > >> >
>> >> >> >> >> > >> >
>> >> >> >> >> > >> >
>> >> >> >> >> > >>
>> >> >> >> >> > >>
>> >> >> >> >> > >>
>> >> >> >> >> > >>
>> >> >> >> >
>> >> >
> ---------------------------------------------------------------------
>> >> >> >> >> > >> 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]
>> >> >> >> >> > >
>> >> >> >> >> > >
>> >> >> >> >> > >
>> >> >> >> >> > [attachment "TestProgram.java" deleted by Thomas E.
>> >> >> >> > DeWeese/449433/EKC]
>> >> >> >> >> >
>> >> >> >
>> > ---------------------------------------------------------------------
>> >> >> >> >> > 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]
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> > ---------------------------------------------------------------------
>> >> >> >> 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]
>> >> >>
>> >> >
>> >> >
>> >> >
> ---------------------------------------------------------------------
>> >> > 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]
>> >
>> >
>> >
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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]