Hi Roger,
Glad I could help!
Yes, the Java Core only includes DOM core. It doesn't include DOM events. BTW you probably want read:
http://www.w3.org/TR/2000/REC-DOM-Level-2-Events-20001113/
There you will see something called "EventTarget" almost all elements in SVG implement the EventTarget interface which has, add/removeEventListener (the Document is just one example - in fact it is much more common to add 'global' event handers on the root element not on the document it's self). It is even more common to add event listeners on the actual graphical element - although in some cases this isn't what makes the most sense.
Roger I Martin PhD wrote:
Wow Thomas,
I've been missing out. Under http://java.sun.com/j2se/1.5.0/docs/api/index.html there is no mention of the org.w3c.dom.events.* particularly org.w3c.dom.events.Event, org.w3c.dom.events.MouseEvent and org.w3c.dom.events.UIEvent. And I have never found where to add a listener till reading your reply and now I'm employing org.apache.batik.dom.svg.SVGOMDocument.addEventListener. Was looking at org.w3c.dom.svg.SVGDocument interface too much.
Thank you, I can now make a lot of good progress,
Roger
P.S. I'll be able to model my MathML light-weight visual DOM off of this too.
----- Original Message ----- From: "Thomas DeWeese" <[EMAIL PROTECTED]>
To: "Batik Users" <[EMAIL PROTECTED]>
Sent: Wednesday, July 07, 2004 8:44 PM
Subject: Re: JSVGCanvas displayed gvt components, editing and then saving.
Hi Roger,
I applaud your enthusiasm with the GVT, but since you clearly are aware of (and are making use of) modifying the DOM to manipulate the displayed graphics - why don't you do the same thing for your 'interactive' bits?
> > ((java.awt.geom.Line2D)theShape).setLine(endPoint, > ((java.awt.geom.Line2D)theShape).getP2());
This could be replaced with a DOM mouseMove event listener, and setting the attributes on the line element:
Element line; line.setAttribute("x1", endPoint.x); line.setAttribute("y1", endPoint.y);
You can even go back and forth between the GVT and DOM node using the BridgeContext (if you want to peak at the Java2D shapes), but if you have a dynamic document it's really nasty to go changing the GVT 'under the hood'.
Roger I Martin PhD wrote:
Hi,
I'm doing DOM adds, removes, attribute changes and I see the JSVGCanvas rendering update each time. Also the DOM transformed to an svg doc shows all the final states and attributes. For example:
JComponent currentFocus=getCurrentFocus(); if(currentFocus==null) { return; } else if(currentFocus instanceof org.apache.batik.swing.JSVGCanvas) {
svgCanvas=(org.apache.batik.swing.JSVGCanvas)currentFocus;
org.apache.batik.dom.svg.SVGOMDocument
svgOMDocument=(org.apache.batik.dom.svg.SVGOMDocument)svgCanvas.getSVGDocume nt();
org.apache.batik.dom.svg.SVGOMSVGElement
root=(org.apache.batik.dom.svg.SVGOMSVGElement)svgOMDocument.getRootElement( );
org.apache.batik.dom.svg.SVGDOMImplementation svgDOMImplementation=new
org.apache.batik.dom.svg.SVGDOMImplementation();
org.apache.batik.dom.svg.SVGOMImageElement image=new org.apache.batik.dom.svg.SVGOMImageElement("image", svgOMDocument); try { javax.imageio.stream.FileImageInputStream fiis=new javax.imageio.stream.FileImageInputStream(new File(fiob.getFilePath())); java.util.Iterator iterator=javax.imageio.ImageIO.getImageReaders(fiis); if(iterator.hasNext()) { javax.imageio.ImageReader ir=(javax.imageio.ImageReader)iterator.next(); ir.setInput(fiis); java.awt.image.BufferedImage bi=ir.read(0); org.apache.batik.svggen.ImageHandlerBase64Encoder dih=new org.apache.batik.svggen.ImageHandlerBase64Encoder(); dih.handleHREF((java.awt.image.RenderedImage)bi, image,
org.apache.batik.svggen.SVGGeneratorContext.createDefault(svgOMDocument));
org.apache.batik.dom.svg.SVGOMGElement g=new org.apache.batik.dom.svg.SVGOMGElement("g", svgOMDocument);
image.setAttribute("width",Integer.toString(bi.getWidth()));
image.setAttribute("height",Integer.toString(bi.getHeight())); g.appendChild(image); root.appendChild(g); } } catch(FileNotFoundException fnfe) {
} catch(java.io.IOException ioe) {
} } ... This adds a raster image to the DOM as a base 64 encoded image, it shows in the JSVGCanvas update and can be saved to the svg doc.
Now without the DOM I can change the JSVGCanvas position of a selected line by doing this:
public class SVGCanvasAdapter extends org.apache.batik.gvt.event.GraphicsNodeMouseAdapter implements org.apache.batik.gvt.event.GraphicsNodeKeyListener, org.apache.batik.gvt.event.SelectionListener { ... public void mouseClicked(org.apache.batik.gvt.event.GraphicsNodeMouseEvent evt) { switch(mode) { case 0: if(evt.getSource() instanceof org.apache.batik.gvt.ShapeNode) { org.apache.batik.gvt.ShapeNode shapeNode=(org.apache.batik.gvt.ShapeNode)evt.getSource();
java.awt.Graphics2D g2=(java.awt.Graphics2D)svgCanvas.getGraphics(); if(g2!=null) { g2.setColor(Color.blue); g2.draw(shapeNode.getOutline()); g2.dispose(); } java.awt.Shape shape=shapeNode.getShape(); this.shapeNode=shapeNode; } break; } }
public void mouseDragged(org.apache.batik.gvt.event.GraphicsNodeMouseEvent evt) { endPoint=evt.getPoint2D();//getClientPoint(); if(evt.getSource() instanceof org.apache.batik.gvt.ShapeNode) { if(shapeNode!=null) { java.awt.Shape theShape=shapeNode.getShape();
System.out.println("shape="+shapeNode.getShape().getClass().getName()); if(theShape instanceof java.awt.geom.Line2D) {
shapeNode.getParent().fireGraphicsNodeChangeStarted();
if(((java.awt.geom.Line2D)theShape).getP1().distance(endPoint)>((java.awt.ge om.Line2D)theShape).getP2().distance(endPoint))
{
((java.awt.geom.Line2D)theShape).setLine(((java.awt.geom.Line2D)theShape).ge tP1(),
endPoint); System.out.println("near P1"); } else {
((java.awt.geom.Line2D)theShape).setLine(endPoint, ((java.awt.geom.Line2D)theShape).getP2()); System.out.println("near P2"); } //shapeNode.getParent().
shapeNode.getParent().fireGraphicsNodeChangeCompleted(); svgCanvas.repaint(); } //evt. } else { org.apache.batik.gvt.ShapeNode shapeNode=(org.apache.batik.gvt.ShapeNode)evt.getSource(); java.awt.Shape shape=shapeNode.getShape(); this.shapeNode=new org.apache.batik.gvt.ShapeNode(); } } } ...
but I don't get these changes back in the DOM or get to save them to file. Or should I just use svggen to create the file with the changes from the JSVGCanvas and be done with it? But sometimes new primitives are added from the DOM and that update will reset the gvt view. I also want to right-click and popup a dialog with an appropriate primitive dialog for line, ellipse, rectangle, etc. Basically turn it into a full blown editor.
----- Original Message ----- *From:* Andres Toussaint <mailto:[EMAIL PROTECTED]> *To:* Batik Users <mailto:[EMAIL PROTECTED]> *Sent:* Wednesday, July 07, 2004 4:17 PM *Subject:* Re: JSVGCanvas displayed gvt components, editing and then saving.
Hi:
What type of changes are you doing in the GVT component? Why not do the changes to the objects in the DOM and catch the UpdateManager to be sure the modifications are ready before saving.
I have to assume that you are doing Java2D modifications, beacuse if not, then i do not see the reason to do your modifications in the GVT, you can do all modifications in the DOM, by changing the attributes of the Elements in your DOM.
If the modification was triggered by a element.EventListener (i.r OnClickAction), then you are already in the JSCGCanvas runnable queue, if not, then you need to invoke the runnable queue and do your attribute changes there.
To invoke the runnable queue, you need to do several things:
1. in JSVGCanvas.gvtRenderingCompeted(GVTTreeRenderEvent) { UpdateManager updateM = JSVGCanvas.getUpdateManager(); }
2. to call the runnable queue: updateM.getUpdateRunnableQueue().invokelater(new Runnable() { public void run() { //////////////////////////All the Element attribute changes here //For example SVGDocument doc = JSCGCanvas.getSVGDocument(); SVGOMSVGElement docElt = (SVGOMSVGElement) doc.getDocumentElement(); Element group = docElt.getElementById("some id tag"); Element theElement = (Element) group.getFirstChild();
//// The attribute changes here: theElement.setAttribute("width","200"); } } );
Hope this helps,
Andres.
On Jul 7, 2004, at 12:29 PM, Roger I Martin PhD wrote:
Hi,
I've learned to add, remove, modify the JSVGCanvas displayed svg DOM, save it back to a file with the changes. Also learned how to modify a gvt component on the canvas with user keyboard and mouse interaction (i.e. mouseDragged(org.apache.batik.gvt.event.GraphicsNodeMouseEvent evt);). What I don't have is how to "bridge" the results of the gvt modifications back to the DOM and subsequently save the results back to an svg doc. After the change is back in the DOM I could then save it. Anybody have a hint to how it can be
done?
--Roger
--------------------------------------------------------------------- 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]