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.getSVGDocument();
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.geom.Line2D)theShape).getP2().distance(endPoint))
{
((java.awt.geom.Line2D)theShape).setLine(((java.awt.geom.Line2D)theShape).getP1(), 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]



Reply via email to