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.
|
- JSVGCanvas displayed gvt components, editing and then s... Roger I Martin PhD
- Re: JSVGCanvas displayed gvt components, editing a... Andres Toussaint
- Re: JSVGCanvas displayed gvt components, editi... Roger I Martin PhD
- Re: JSVGCanvas displayed gvt components, e... Thomas DeWeese
- Re: JSVGCanvas displayed gvt component... Roger I Martin PhD
- Re: JSVGCanvas displayed gvt comp... Thomas DeWeese
- Re: JSVGCanvas displayed gvt components, editing a... Tonny Kohar