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 SVGEllipseElementBridge extends SVGShapeElementBridge { 35 36 39 public SVGEllipseElementBridge() {} 40 41 44 public String getLocalName() { 45 return SVG_ELLIPSE_TAG; 46 } 47 48 51 public Bridge getInstance() { 52 return new SVGEllipseElementBridge(); 53 } 54 55 62 protected void buildShape(BridgeContext ctx, 63 Element e, 64 ShapeNode shapeNode) { 65 66 UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, e); 67 String s; 68 69 s = e.getAttributeNS(null, SVG_CX_ATTRIBUTE); 71 float cx = 0; 72 if (s.length() != 0) { 73 cx = UnitProcessor.svgHorizontalCoordinateToUserSpace 74 (s, SVG_CX_ATTRIBUTE, uctx); 75 } 76 77 s = e.getAttributeNS(null, SVG_CY_ATTRIBUTE); 79 float cy = 0; 80 if (s.length() != 0) { 81 cy = UnitProcessor.svgVerticalCoordinateToUserSpace 82 (s, SVG_CY_ATTRIBUTE, uctx); 83 } 84 85 s = e.getAttributeNS(null, SVG_RX_ATTRIBUTE); 87 float rx; 88 if (s.length() != 0) { 89 rx = UnitProcessor.svgHorizontalLengthToUserSpace 90 (s, SVG_RX_ATTRIBUTE, uctx); 91 } else { 92 throw new BridgeException(e, ERR_ATTRIBUTE_MISSING, 93 new Object [] {SVG_RX_ATTRIBUTE, s}); 94 } 95 96 s = e.getAttributeNS(null, SVG_RY_ATTRIBUTE); 98 float ry; 99 if (s.length() != 0) { 100 ry = UnitProcessor.svgVerticalLengthToUserSpace 101 (s, SVG_RY_ATTRIBUTE, uctx); 102 } else { 103 throw new BridgeException(e, ERR_ATTRIBUTE_MISSING, 104 new Object [] {SVG_RY_ATTRIBUTE, s}); 105 } 106 107 shapeNode.setShape(new Ellipse2D.Float (cx-rx, cy-ry, rx*2, ry*2)); 108 } 109 110 112 115 public void handleDOMAttrModifiedEvent(MutationEvent evt) { 116 String attrName = evt.getAttrName(); 117 if (attrName.equals(SVG_CX_ATTRIBUTE) || 118 attrName.equals(SVG_CY_ATTRIBUTE) || 119 attrName.equals(SVG_RX_ATTRIBUTE) || 120 attrName.equals(SVG_RY_ATTRIBUTE)) { 121 122 buildShape(ctx, e, (ShapeNode)node); 123 handleGeometryChanged(); 124 } else { 125 super.handleDOMAttrModifiedEvent(evt); 126 } 127 } 128 129 protected ShapePainter createShapePainter(BridgeContext ctx, 130 Element e, 131 ShapeNode shapeNode) { 132 Rectangle2D r2d = shapeNode.getShape().getBounds2D(); 133 if ((r2d.getWidth() == 0) || (r2d.getHeight() == 0)) 134 return null; 135 return super.createShapePainter(ctx, e, shapeNode); 136 } 137 } 138 | Popular Tags |