1 18 package org.apache.batik.bridge; 19 20 import java.awt.RenderingHints ; 21 import java.awt.geom.Rectangle2D ; 22 23 import org.apache.batik.gvt.CompositeGraphicsNode; 24 import org.apache.batik.gvt.GraphicsNode; 25 import org.w3c.dom.Element ; 26 import org.w3c.dom.Node ; 27 import org.w3c.dom.events.MutationEvent ; 28 29 35 public class SVGGElementBridge extends AbstractGraphicsNodeBridge { 36 37 40 public SVGGElementBridge() {} 41 42 45 public String getLocalName() { 46 return SVG_G_TAG; 47 } 48 49 52 public Bridge getInstance() { 53 return new SVGGElementBridge(); 54 } 55 56 63 public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) { 64 CompositeGraphicsNode gn = 65 (CompositeGraphicsNode)super.createGraphicsNode(ctx, e); 66 if (gn == null) 67 return null; 68 69 RenderingHints hints = null; 71 hints = CSSUtilities.convertColorRendering(e, hints); 72 if (hints != null) 73 gn.setRenderingHints(hints); 74 75 Rectangle2D r = CSSUtilities.convertEnableBackground(e); 77 if (r != null) 78 gn.setBackgroundEnable(r); 79 80 return gn; 81 } 82 83 86 protected GraphicsNode instantiateGraphicsNode() { 87 return new CompositeGraphicsNode(); 88 } 89 90 93 public boolean isComposite() { 94 return true; 95 } 96 97 99 102 public void handleDOMNodeInsertedEvent(MutationEvent evt) { 103 if ( evt.getTarget() instanceof Element ){ 104 handleElementAdded((CompositeGraphicsNode)node, 105 e, 106 (Element )evt.getTarget()); 107 } 108 } 109 110 113 public void handleElementAdded(CompositeGraphicsNode gn, 114 Node parent, 115 Element childElt) { 116 GVTBuilder builder = ctx.getGVTBuilder(); 118 GraphicsNode childNode = builder.build(ctx, childElt); 119 if (childNode == null) { 120 return; } 122 123 int idx = -1; 125 for(Node ps = childElt.getPreviousSibling(); ps != null; 126 ps = ps.getPreviousSibling()) { 127 if (ps.getNodeType() != Node.ELEMENT_NODE) 128 continue; 129 Element pse = (Element )ps; 130 GraphicsNode psgn = ctx.getGraphicsNode(pse); 131 while ((psgn != null) && (psgn.getParent() != gn)) { 132 psgn = psgn.getParent(); 135 } 136 if (psgn == null) 137 continue; 138 idx = gn.indexOf(psgn); 139 if (idx == -1) 140 continue; 141 break; 142 } 143 idx++; 146 gn.add(idx, childNode); 147 } 148 } 149 | Popular Tags |