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 Erik Blankinship <er...@media.mit.edu> on 2002/08/04 01:49:48 UTC

getting a group element for each component

hi batik users

i want to create a custom svg document.  i want a group element for each
component in my parent component.  i also want to add some additional
attibutes to each group element in my svg document.

so:
SVGGraphics2D svgGenerator = new SVGGraphics2D(svgDoc);
myJComonent.paint(svgGenerator);
this snippet generates a document with one group element <g>, which paints
all of myJComponent's visible child components.

if i want to add additional attribute elements to this <g> element, all i
have to do is ask my svgGenerator for getTopLevelGroup().  pretty easy.  but
what if I want to add custom attribute tags to each subcomponent?

my current thought is to create a SVGGraphics2D for each sub-component,
strip out each topLevelGroup, add x and y attributes (to place them in their
positions in their parent component).  then stitch all these group elements
together into a new document.  does that make sense?  is there an easier
way?

thanks much
ERIK!


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


Re: getting a group element for each component

Posted by Erik Blankinship <er...@media.mit.edu>.
> anyone know of a solution?  is there a way to tell <g>'s generated from
> other documents to not repeat already used clipPath id #s?

solved this by constructing my multiple svgGraphics2D with the same
svgGeneratorContext.


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


Re: getting a group element for each component

Posted by Erik Blankinship <er...@media.mit.edu>.
i am able to get the <g> element for any JComponent using:
SwingSVGPrettyPrint.print(myJComponent, mysvgGenerator);

once i have the <g> element, i can then call
mysvgGenerator.translate( thisManyX, thisManyY );
to successfully reposition my <g> element where i want it.

i do this iteratively, to all of a parent component's children, each with
its own <g> element.  then i add these all to another, final document.

the problem:
the width and height of different JComponents are applied to other
JComponents!

what is happening:
digging into the generated .svg document, i found that there are repeated
clipPath elements.
for example:
under one <g>:
<g id="javax.swing.JTextArea1">
<defs id="defs4">
<clipPath clipPathUnits="userSpaceOnUse" id="clipPath6">
<path d="M0 0 L0 116 L139 116 L139 0 Z" />
</clipPath>
</defs>

and under another <g> in the same final document:
<g id="javax.swing.JToggleButton2">
<defs id="defs3">
<clipPath clipPathUnits="userSpaceOnUse" id="clipPath6">
<path d="M0 0 L0 18 L296 18 L296 0 Z" />
</clipPath>
</defs>

anyone know of a solution?  is there a way to tell <g>'s generated from
other documents to not repeat already used clipPath id #s?

thanks
ERIK!



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


Re: getting a group element for each component

Posted by Thomas E Deweese <th...@kodak.com>.
>>>>> "EB" == Erik Blankinship <er...@media.mit.edu> writes:

>> if i want to add additional attribute elements to this <g> element,
>> all i have to do is ask my svgGenerator for getTopLevelGroup().
>> pretty easy. but what if I want to add custom attribute tags to
>> each subcomponent?

EB> this did not work.  asking SVGGraphics2D for getroot() or
EB> getTopLevelGroup() doesn't return anything.  evidently, it is not
EB> until you call stream() that the SVG document is generated at all?

    I don't think this is correct, as all stream does is call
'getRoot'.  Have you drawn anything to the Graphics2D when you call
this method?

    Also when you call this method it create a new group to do it's
drawing into.  So calling it up front then drawing then looking at the
group will not show you anything.

EB> is there a way to use SVGGraphics2D to just get a <g> element back
EB> from a component?

    Draw just the one component then get the root.  If you use a
JComponent you can override paintChildren and handle this correctly
for your case.

EB> thanks again ERIK!

    Hope it helps.  The real expert on this (Vicent Hardy) is away for
a while.

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


Re: getting a group element for each component

Posted by Erik Blankinship <er...@media.mit.edu>.
> if i want to add additional attribute elements to this <g> element, all i
> have to do is ask my svgGenerator for getTopLevelGroup().  pretty easy.
but
> what if I want to add custom attribute tags to each subcomponent?

this did not work.  asking SVGGraphics2D for getroot() or getTopLevelGroup()
doesn't return anything.  evidently, it is not until you call stream() that
the SVG document is generated at all?

is there a way to use SVGGraphics2D to just get a <g> element back from a
component?

thanks again
ERIK!


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