Differences between revisions 4 and 5
Revision 4 as of 2009-09-20 23:47:44
Size: 1645
Editor: localhost
Comment: converted to 1.6 markup
Revision 5 as of 2012-06-22 14:05:31
Size: 1651
Editor: p4FE2079F
Comment: display java code with syntax highlighting
Deletions are marked like this. Additions are marked like this.
Line 25: Line 25:
{{{ {{{#!java

The SVG and CSS DOM Interfaces

When you first create an SVG Document from Java it will only support the DOM Core calls (basically traversal of the tree and accessing attributes).

The really interesting CSS and SVG specific DOM interfaces will not work properly until you initialize them. The code below is the simplest example of how to initialize them.

This defaults a lot of behaviour and in particular for real uses most people will want to provide a custom implementation of the UserAgent class.

If you are using the JSVGCanvas it does this when you associate an SVGDocument with the canvas. It will do this for you asynchronously you can be notified when it is done by registering a GVT!TreeBuilderListener with the canvas before setting an SVGDocument (or URL) on the canvas.


   1 import org.apache.batik.bridge.UserAgent;
   2 import org.apache.batik.bridge.UserAgentAdapter;
   3 import org.apache.batik.bridge.DocumentLoader;
   4 import org.apache.batik.bridge.BridgeContext;
   5 import org.apache.batik.bridge.GVTBuilder;
   7 import org.apache.batik.gvt.GraphicsNode;
   9 /* ..... */
  10         SVGDocument    svgDoc;
  11         UserAgent      userAgent;
  12         DocumentLoader loader;
  13         BridgeContext  ctx;
  14         GVTBuilder     builder;
  15         GraphicsNode   rootGN;
  17         userAgent = new UserAgentAdapter();
  18         loader    = new DocumentLoader(userAgent);
  19         ctx       = new BridgeContext(userAgent, loader);
  20         ctx.setDynamicState(BridgeContext.DYNAMIC);
  21         builder   = new GVTBuilder();
  22         rootGN    = builder.build(ctx, svgDoc);

BootSvgAndCssDom (last edited 2012-06-22 14:05:31 by p4FE2079F)