1 18 package org.apache.batik.bridge; 19 20 import java.awt.geom.Ellipse2D ; 21 import java.awt.geom.Rectangle2D ; 22 23 import org.apache.batik.gvt.ShapeNode; 24 import org.apache.batik.gvt.ShapePainter; 25 import org.w3c.dom.Element ; 26 import org.w3c.dom.events.MutationEvent ; 27 28 34 public class SVGCircleElementBridge extends SVGShapeElementBridge { 35 36 39 public SVGCircleElementBridge() {} 40 41 44 public String getLocalName() { 45 return SVG_CIRCLE_TAG; 46 } 47 48 51 public Bridge getInstance() { 52 return new SVGCircleElementBridge(); 53 } 54 55 62 protected void buildShape(BridgeContext ctx, 63 Element e, 64 ShapeNode shapeNode) { 65 UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, e); 66 String s; 67 68 s = e.getAttributeNS(null, SVG_CX_ATTRIBUTE); 70 float cx = 0; 71 if (s.length() != 0) { 72 cx = UnitProcessor.svgHorizontalCoordinateToUserSpace 73 (s, SVG_CX_ATTRIBUTE, uctx); 74 } 75 76 s = e.getAttributeNS(null, SVG_CY_ATTRIBUTE); 78 float cy = 0; 79 if (s.length() != 0) { 80 cy = UnitProcessor.svgVerticalCoordinateToUserSpace 81 (s, SVG_CY_ATTRIBUTE, uctx); 82 } 83 84 s = e.getAttributeNS(null, SVG_R_ATTRIBUTE); 86 float r; 87 if (s.length() != 0) { 88 r = UnitProcessor.svgOtherLengthToUserSpace 89 (s, SVG_R_ATTRIBUTE, uctx); 90 } else { 91 throw new BridgeException(e, ERR_ATTRIBUTE_MISSING, 92 new Object [] {SVG_R_ATTRIBUTE, s}); 93 } 94 float x = cx - r; 95 float y = cy - r; 96 float w = r * 2; 97 shapeNode.setShape(new Ellipse2D.Float (x, y, w, w)); 98 } 99 100 102 105 public void handleDOMAttrModifiedEvent(MutationEvent evt) { 106 String attrName = evt.getAttrName(); 107 if (attrName.equals(SVG_CX_ATTRIBUTE) || 108 attrName.equals(SVG_CY_ATTRIBUTE) || 109 attrName.equals(SVG_R_ATTRIBUTE)) { 110 111 buildShape(ctx, e, (ShapeNode)node); 112 handleGeometryChanged(); 113 } else { 114 super.handleDOMAttrModifiedEvent(evt); 115 } 116 } 117 118 protected ShapePainter createShapePainter(BridgeContext ctx, 119 Element e, 120 ShapeNode shapeNode) { 121 Rectangle2D r2d = shapeNode.getShape().getBounds2D(); 122 if ((r2d.getWidth() == 0) || (r2d.getHeight() == 0)) 123 return null; 124 return super.createShapePainter(ctx, e, shapeNode); 125 } 126 } 127 | Popular Tags |