Thomas DeWeese wrote:

Muthuganesh Jothi Ramalingam wrote:

I've been searching and trying a bunch of different things over the last couple of days, and I can't seem to get the desired results. Here is my requirement: I have a bunch of Java2D Shapes that I would like to pass through the SVGGenerator to generate my SVG file via SVGGraphics2D.stream(). However, I haven't quite figured out the best way to modify the DOM so I can associate my own intelligent information with the svg paths or even modify the DOM to change or add some SVG tags.


   At any point you can get the generated subtree by
calling 'svgg2d.getRoot(parent)'.  So you can get the just generated
element.  You can also look at extending the SVGGeneratorContext
(see the web page for some examples).

For example: I have drawn a rectangle and on mouse clicked event i am plotting circles over the rectangle. Now, on click of a button i should be able to hide all the circles. This can be done by getting the circle elments from SVG Dom and set the visible attribute.


   Unless you have some funny stacking requirements I would hide/unhide
by toggling visibility on a single 'g' that the circles are children of.

my question is,

1. There is no id element in the DEFAULT SVG content generated by the SVGGraphics2D. How to give id attribute to each element ?


   If you do the above you don't need to, you just need the 'id' of
the 'g' element which can already be in the displayed document.

- Should i create the SVG circle elements myself and should add it to the SVGDom, is that the correct way ? and should take care of adding it under appropriate parents etc., So each time for a mouse click this must be done ? Ooops!!! then lot of work, performance will be poor, i think.


   What do you think the SVGGraphics2D is doing?  This will probably
be faster than using the Graphics2D as you can likely construct
the element quicker since you don't need to handle all cases.

   Just make sure that you only modify the SVGDocument in the
UpdateManager thread.

Any hints would be greatly appreciated because I'm trying to come up with a proof of concept to show off the advantages of on-the-fly, generated SVG.

The way I'm approaching it. Application and Web page embedded(Browser)
By an application(Java2D)
The protocol for binding to Java instead of using JavaScript is implemented in Batik. It works: http://www.w3.org/TR/SVG11/java.html

Then instead of a js or embedded JavaScript(which does not allow you to cast to the Element from a Node and use the Element.setAttribute grrr) The following script is in the svg document.
...
<defs>
<script type="application/java-archive" xlink:href="file:///c:/sourceforge/mathml-x/mathml-x-svg-binding.jar" />
</defs>
...
Code placed in the mathml-x-svg-binding.jar does the dynamic part for example changing the number of ticks by dragging them along an axis. Example is at
http://cvs.sourceforge.net/viewcvs.py/mathml-x/mathml-x/src/com/neuralworks/xml/svg/event/DynamicGraphEventListener.java?view=markup
ScriptHandler impl example:
http://cvs.sourceforge.net/viewcvs.py/mathml-x/mathml-x/src/com/neuralworks/xml/svg/binding/DynamicGraph.java?view=markup
Any of the events of the DOM can be handled.
http://www.w3.org/TR/DOM-Level-2-Events/events.html

In the application it is possible to also use the DOM Events.
...
public void documentLoadingCompleted(org.apache.batik.swing.svg.SVGDocumentLoaderEvent e)
                       {
if(svgDocument instanceof org.apache.batik.dom.svg.SVGOMDocument)
                           {
org.apache.batik.dom.svg.SVGOMDocument svgOMDocument=(org.apache.batik.dom.svg.SVGOMDocument)svgDocument; org.apache.batik.dom.svg.SVGOMSVGElement svgOMSVG=(org.apache.batik.dom.svg.SVGOMSVGElement)svgOMDocument.getRootElement(); svgEventListener=new com.neuralworks.xml.svg.event.EventListener(); svgOMSVG.addEventListener("mousedown", svgEventListener, false); svgOMSVG.addEventListener("mouseup", svgEventListener, false); svgOMSVG.addEventListener("click", svgEventListener, false); svgOMSVG.addEventListener("mousemove", svgEventListener, false); svgOMSVG.addEventListener("DOMActivate", svgEventListener, false); //recursivelyAddEventListeners(svgOMSVG.getChildNodes());
                               //svgDocument.getImplementation();
                           }
                       }
...
Where an example of EventListener is
http://cvs.sourceforge.net/viewcvs.py/mathml-x/mathml-x/src/com/neuralworks/xml/svg/event/EventListener.java?view=markup
Notice a right-click will popup an AttributeDialog which will display the selected Batik svg component and allow the user to change them. After they change the Batik JSVGCanvas will update and show the effects.
AttributeDialog
http://cvs.sourceforge.net/viewcvs.py/mathml-x/mathml-x/src/com/neuralworks/xml/svg/AttributeDialog.java?view=markup

For Web page embedded(Browser)
Since I haven't found a IE component to do binding to Java I made an ATL object and embedded Batik on it. It is very green and is slow because of starting up a JVM for every svg on a page and every refresh but not when the size changes. Also used a BufferedImage of an off screen canvas until I get the JAWT working for GraphicsDevice.TYPE_IMAGE_BUFFER http://java.sun.com/j2se/1.5.0/docs/api/java/awt/GraphicsDevice.html#TYPE_IMAGE_BUFFER The memory image java.awt.Canvas isn't locking. After this is working the same application code above will handle dynamic svg by the script Java binding method.

Current status I can display the svg in IE. Still green and very much bleeding edge. Will also make it embed in Firefox on Windows and Linux. Will need to learn what can be done for Mac.

Looking to make the jvm run in a service and then only one need launch and run for multiple Batik views of svg's on a web page. This one jvm will then run for the life of the browser instance.

What you are doing sounds like an application so you don't need this Browser plugin to be working yet:-).


Note: No swing components only java2d shapes.

Thanks,
Leo



---------------------------------------------------------------------
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]

Reply via email to