1 18 package org.apache.batik.bridge; 19 20 import java.awt.geom.Line2D ; 21 22 import org.apache.batik.gvt.ShapeNode; 23 import org.apache.batik.gvt.ShapePainter; 24 import org.w3c.dom.Element ; 25 import org.w3c.dom.events.MutationEvent ; 26 27 33 public class SVGLineElementBridge extends SVGDecoratedShapeElementBridge { 34 35 38 public SVGLineElementBridge() {} 39 40 43 public String getLocalName() { 44 return SVG_LINE_TAG; 45 } 46 47 50 public Bridge getInstance() { 51 return new SVGLineElementBridge(); 52 } 53 54 63 protected ShapePainter createFillStrokePainter(BridgeContext ctx, 64 Element e, 65 ShapeNode shapeNode) { 66 return PaintServer.convertStrokePainter(e, shapeNode, ctx); 77 } 78 79 86 protected void buildShape(BridgeContext ctx, 87 Element e, 88 ShapeNode shapeNode) { 89 90 UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, e); 91 String s; 92 93 s = e.getAttributeNS(null, SVG_X1_ATTRIBUTE); 95 float x1 = 0; 96 if (s.length() != 0) { 97 x1 = UnitProcessor.svgHorizontalCoordinateToUserSpace 98 (s, SVG_X1_ATTRIBUTE, uctx); 99 } 100 101 s = e.getAttributeNS(null, SVG_Y1_ATTRIBUTE); 103 float y1 = 0; 104 if (s.length() != 0) { 105 y1 = UnitProcessor.svgVerticalCoordinateToUserSpace 106 (s, SVG_Y1_ATTRIBUTE, uctx); 107 } 108 109 s = e.getAttributeNS(null, SVG_X2_ATTRIBUTE); 111 float x2 = 0; 112 if (s.length() != 0) { 113 x2 = UnitProcessor.svgHorizontalCoordinateToUserSpace 114 (s, SVG_X2_ATTRIBUTE, uctx); 115 } 116 117 s = e.getAttributeNS(null, SVG_Y2_ATTRIBUTE); 119 float y2 = 0; 120 if (s.length() != 0) { 121 y2 = UnitProcessor.svgVerticalCoordinateToUserSpace 122 (s, SVG_Y2_ATTRIBUTE, uctx); 123 } 124 125 shapeNode.setShape(new Line2D.Float (x1, y1, x2, y2)); 126 } 127 128 130 133 public void handleDOMAttrModifiedEvent(MutationEvent evt) { 134 String attrName = evt.getAttrName(); 135 if (attrName.equals(SVG_X1_ATTRIBUTE) || 136 attrName.equals(SVG_Y1_ATTRIBUTE) || 137 attrName.equals(SVG_X2_ATTRIBUTE) || 138 attrName.equals(SVG_Y2_ATTRIBUTE)) { 139 140 buildShape(ctx, e, (ShapeNode)node); 141 handleGeometryChanged(); 142 } else { 143 super.handleDOMAttrModifiedEvent(evt); 144 } 145 } 146 } 147 | Popular Tags |