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 ra...@blueyonder.co.uk on 2006/03/19 10:52:34 UTC

How to access childNodes

Hi Thomas,

I'm trying to access the childNodes in my 'CircleGroup' I want to retrieve
the value I've set for the attribute 'id' when I created the element
'circle' i.e:

e.setAttributeNS(null,"id","" + pt2d.getX());

Thx

yasmin




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


Re: How to access childNodes - Solved!

Posted by ra...@blueyonder.co.uk.
Solved!




> Hi Thomas,
>
> I'm trying to access the childNodes in my 'CircleGroup' I want to retrieve
> the value I've set for the attribute 'id' when I created the element
> 'circle' i.e:
>
> e.setAttributeNS(null,"id","" + pt2d.getX());
>
> Thx
>
> yasmin
>
>
>
>
> ---------------------------------------------------------------------
> 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 access childNodes

Posted by Javid Alimohideen <ja...@gmail.com>.
Hi Yasmin,
I would suggest you to assign your own namespace variables to the circle
element to determine if they have been clicked or not and then change the
text value based on your local namespace variable's value.
Here is a snipper code;

When a user clicks on a circle for the first time:
elt.setAttributeNS("blueyonder.co.uk/yasmin", "isClicked" "true");

Later, when you want to change the index value:
String val = elt.getAttributeNS("blueyonder.co.uk", "isClicked");
if (val == "false")
	acc++;
else
	// do nothing

Hope it helps,

Javid

-----Original Message-----
From: rafiqy@blueyonder.co.uk [mailto:rafiqy@blueyonder.co.uk]
Sent: Sunday, March 19, 2006 7:12 AM
To: batik-users@xmlgraphics.apache.org
Subject: Re: How to access childNodes


Hi Thomas,

The reason why I set my id to 'pt2d' is that is the point reference, if I
assign a letter value, it will cause me problems when I cast the string
value to 'Double' ...I suppose I can use the string_Tokenizer but I'm not
sure if its worth going through all that trouble since I'm only gnna run
this program with Batik???

Anyway, moving to my next problem :(    ...when a user clicks on a 'circl'
the stroke colour changes from red to yellow hence:

 elt.setAttributeNS(null,"stroke","yellow");

so, later when I assign a mouseClick listener to determine the closest
'circle' the user has clicked and assign a sequenctial numerical reference
to it - here I only want to assign a reference to those circle's whose
stroke is 'red' (i.e have not yet been clicked') ...here's the snippet of
code:

if (clst != null && dist < 11 )
    {

      for (int k=0; k<numNodes; k++)
         {
           Node node = list.item(k).getAttributes().getNamedItem("stroke");
           String colour = node.getNodeValue();

           if (colour == "yellow")
            {
             Element textID = doc.createElementNS(SVGNS, "text");
             Element textSpan = doc.createElementNS(SVGNS, "tspan");
             textSpan.setAttributeNS(null, "x", ""+clst.getX());
             textSpan.setAttributeNS(null, "y", ""+clst.getY());
             textSpan.setAttributeNS(null, "fill", "firebrick");
            textSpan.setAttributeNS(null, "font-family", "'Arial-BoldMT'");
             textSpan.setAttributeNS(null, "text-anchor", "middle");
             textSpan.setAttributeNS(null, "font-size", "5");

             org.w3c.dom.Text tempText = (org.w3c.dom.Text)
             doc.createTextNode(Integer.toString(accNum));
             textSpan.appendChild(tempText);
             textID.appendChild(textSpan);
             g.appendChild(textID);
           }
         }


      accNum++;
    }


But, if I click on a 'yellow' circle it overwrights!

Many Thx

yasmin






> Hi Yasmin,
>
> rafiqy@blueyonder.co.uk wrote on 03/19/2006 04:52:34 AM:
>
>> e.setAttributeNS(null,"id","" + pt2d.getX());
>
>    Just a small comment, it will work in Batik (right now)
> but an ID is not really allowed to start with a number.  You
> should start your ID's with a letter:
>
>         "Loc_"+pt2d.getX()
>
>
>
> ---------------------------------------------------------------------
> 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 access childNodes

Posted by ra...@blueyonder.co.uk.
Hi Thomas,

The reason why I set my id to 'pt2d' is that is the point reference, if I
assign a letter value, it will cause me problems when I cast the string
value to 'Double' ...I suppose I can use the string_Tokenizer but I'm not
sure if its worth going through all that trouble since I'm only gnna run
this program with Batik???

Anyway, moving to my next problem :(    ...when a user clicks on a 'circl'
the stroke colour changes from red to yellow hence:

 elt.setAttributeNS(null,"stroke","yellow");

so, later when I assign a mouseClick listener to determine the closest
'circle' the user has clicked and assign a sequenctial numerical reference
to it - here I only want to assign a reference to those circle's whose
stroke is 'red' (i.e have not yet been clicked') ...here's the snippet of
code:

if (clst != null && dist < 11 )
    {

      for (int k=0; k<numNodes; k++)
         {
           Node node = list.item(k).getAttributes().getNamedItem("stroke");
           String colour = node.getNodeValue();

           if (colour == "yellow")
            {
             Element textID = doc.createElementNS(SVGNS, "text");
             Element textSpan = doc.createElementNS(SVGNS, "tspan");
             textSpan.setAttributeNS(null, "x", ""+clst.getX());
             textSpan.setAttributeNS(null, "y", ""+clst.getY());
             textSpan.setAttributeNS(null, "fill", "firebrick");
            textSpan.setAttributeNS(null, "font-family", "'Arial-BoldMT'");
             textSpan.setAttributeNS(null, "text-anchor", "middle");
             textSpan.setAttributeNS(null, "font-size", "5");

             org.w3c.dom.Text tempText = (org.w3c.dom.Text)
             doc.createTextNode(Integer.toString(accNum));
             textSpan.appendChild(tempText);
             textID.appendChild(textSpan);
             g.appendChild(textID);
           }
         }


      accNum++;
    }


But, if I click on a 'yellow' circle it overwrights!

Many Thx

yasmin






> Hi Yasmin,
>
> rafiqy@blueyonder.co.uk wrote on 03/19/2006 04:52:34 AM:
>
>> e.setAttributeNS(null,"id","" + pt2d.getX());
>
>    Just a small comment, it will work in Batik (right now)
> but an ID is not really allowed to start with a number.  You
> should start your ID's with a letter:
>
>         "Loc_"+pt2d.getX()
>
>
>
> ---------------------------------------------------------------------
> 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 access childNodes

Posted by th...@kodak.com.
Hi Yasmin,

rafiqy@blueyonder.co.uk wrote on 03/19/2006 04:52:34 AM:

> e.setAttributeNS(null,"id","" + pt2d.getX());

   Just a small comment, it will work in Batik (right now)
but an ID is not really allowed to start with a number.  You
should start your ID's with a letter:

        "Loc_"+pt2d.getX()



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