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 malliksomepalli <ma...@gmail.com> on 2006/10/26 02:52:19 UTC

How to Attatch Label to DOM node and connectors between nodes

Hi,

Can anyone tell me how i can attatch labels to the nodes.Also how can i
render connectors between nodes.I am using DOM API to create SVGdocument and
rasterizing it with transcoder.I can see the shapes i added,But the
connectors between nodes are not rendered.Here is my code.

DOMImplementation docImpl=SVGDOMImplementation.getDOMImplementation();
	    SVGDocument document=(SVGDocument)
docImpl.createDocument(SVGDOMImplementation.SVG_NAMESPACE_URI, "svg", null);
	    Element rootnode=document.getDocumentElement();
	  
	    Element first=document.createElementNS(SVG_NAMESPACE_URI,"rect");
	    first.setAttributeNS(null,"width","40");
	    first.setAttributeNS(null,"height","20");
	    first.setAttributeNS(null,"x","100");
	    first.setAttributeNS(null,"y","50");
	    first.setAttributeNS(null,"style", "fill:white;stroke:blue;
stroke-width:1");

 Element second=document.createElementNS(SVG_NAMESPACE_URI,"rect");
	    second.setAttributeNS(null,"width","40");
	    second.setAttributeNS(null,"height","20");
	    second.setAttributeNS(null,"x","100");
	    second.setAttributeNS(null,"y","120");
	    second.setAttributeNS(null,"style", "fill:white;stroke:blue;
stroke-width:1");

 rootnode.appendChild(first);
	    rootnode.appendChild(second);

JPEGTranscoder t = new JPEGTranscoder();
        t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,new Float(0.8));
        t.addTranscodingHint(JPEGTranscoder.KEY_MAX_WIDTH,new Float(500));
        t.addTranscodingHint(ImageTranscoder.KEY_BACKGROUND_COLOR,
Color.CYAN); 
        TranscoderInput input = new TranscoderInput(document);
        OutputStream ostream = new FileOutputStream("1.jpg");
        TranscoderOutput output = new TranscoderOutput(ostream);
        t.transcode(input, output);
        ostream.flush();
        ostream.close();

Is there any attribute name for labels?Do i need to do anything other than
creating nodes and appending them to get a tree structure with connectors
between parent and child nodes.Anyhelp is verymuch appreciated.

Thanks.



-- 
View this message in context: http://www.nabble.com/How-to-Attatch-Label-to-DOM-node-and-connectors-between-nodes-tf2511187.html#a7003368
Sent from the Batik - Users mailing list archive at Nabble.com.


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


Re: How to Attatch Label to DOM node and connectors between nodes

Posted by malliksomepalli <ma...@gmail.com>.
Never mind,I figured it out myself.For other beginners of SVG and Batik,like
me......,If you are wondering how to generate a Tree structure with Batik
DOM API,Here is the solution.....

1.Create a "g" element.(this is necessary,If nodes of tree are of shape type
"rect"/ "circle" etc,they cant have children)
2.Create a "rect"/"circle" element with required dimensions.
3.create a "text" element and attatch node label to it.Keep it at same x and
y coordinates,so that label comes on the node shape
3.create a "line" element with from coordinates and to coordinates
4.Append "rect" element to "g" node.(Do this before you append text
element,so that rect element does not overlap on text)
5.Append "text" element to "g" node
6.Append "line" element to "g" node

A node of the tree with a connector attatched is ready for you.

-Mallik.




malliksomepalli wrote:
> 
> Hi,
> 
> Can anyone tell me how i can attatch labels to the nodes.Also how can i
> render connectors between nodes.I am using DOM API to create SVGdocument
> and rasterizing it with transcoder.I can see the shapes i added,But the
> connectors between nodes are not rendered.Here is my code.
> 
> DOMImplementation docImpl=SVGDOMImplementation.getDOMImplementation();
> 	    SVGDocument document=(SVGDocument)
> docImpl.createDocument(SVGDOMImplementation.SVG_NAMESPACE_URI, "svg",
> null);
> 	    Element rootnode=document.getDocumentElement();
> 	  
> 	    Element first=document.createElementNS(SVG_NAMESPACE_URI,"rect");
> 	    first.setAttributeNS(null,"width","40");
> 	    first.setAttributeNS(null,"height","20");
> 	    first.setAttributeNS(null,"x","100");
> 	    first.setAttributeNS(null,"y","50");
> 	    first.setAttributeNS(null,"style", "fill:white;stroke:blue;
> stroke-width:1");
> 
>  Element second=document.createElementNS(SVG_NAMESPACE_URI,"rect");
> 	    second.setAttributeNS(null,"width","40");
> 	    second.setAttributeNS(null,"height","20");
> 	    second.setAttributeNS(null,"x","100");
> 	    second.setAttributeNS(null,"y","120");
> 	    second.setAttributeNS(null,"style", "fill:white;stroke:blue;
> stroke-width:1");
> 
>  rootnode.appendChild(first);
> 	    rootnode.appendChild(second);
> 
> JPEGTranscoder t = new JPEGTranscoder();
>         t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,new Float(0.8));
>         t.addTranscodingHint(JPEGTranscoder.KEY_MAX_WIDTH,new Float(500));
>         t.addTranscodingHint(ImageTranscoder.KEY_BACKGROUND_COLOR,
> Color.CYAN); 
>         TranscoderInput input = new TranscoderInput(document);
>         OutputStream ostream = new FileOutputStream("1.jpg");
>         TranscoderOutput output = new TranscoderOutput(ostream);
>         t.transcode(input, output);
>         ostream.flush();
>         ostream.close();
> 
> Is there any attribute name for labels?Do i need to do anything other than
> creating nodes and appending them to get a tree structure with connectors
> between parent and child nodes.Anyhelp is verymuch appreciated.
> 
> Thanks.
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-Attatch-Label-to-DOM-node-and-connectors-between-nodes-tf2511187.html#a7040390
Sent from the Batik - Users mailing list archive at Nabble.com.


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