1 18 package org.apache.batik.extension.svg; 19 20 import java.awt.Color ; 21 import java.awt.Paint ; 22 23 import org.apache.batik.bridge.AbstractSVGBridge; 24 import org.apache.batik.bridge.Bridge; 25 import org.apache.batik.bridge.BridgeContext; 26 import org.apache.batik.bridge.PaintBridge; 27 import org.apache.batik.bridge.SVGUtilities; 28 import org.apache.batik.gvt.GraphicsNode; 29 import org.w3c.dom.Element ; 30 import org.w3c.dom.Node ; 31 32 37 public class ColorSwitchBridge 38 extends AbstractSVGBridge 39 implements PaintBridge, BatikExtConstants { 40 41 44 public ColorSwitchBridge() { } 45 46 49 public String getNamespaceURI() { 50 return BATIK_EXT_NAMESPACE_URI; 51 } 52 53 56 public String getLocalName() { 57 return BATIK_EXT_COLOR_SWITCH_TAG; 58 } 59 60 69 public Paint createPaint(BridgeContext ctx, 70 Element paintElement, 71 Element paintedElement, 72 GraphicsNode paintedNode, 73 float opacity) { 74 Element clrDef = null; 75 for (Node n = paintElement.getFirstChild(); 76 n != null; 77 n = n.getNextSibling()) { 78 if ((n.getNodeType() != Node.ELEMENT_NODE)) 79 continue; 80 Element ref = (Element )n; 81 if ( SVGUtilities.matchUserAgent(ref, ctx.getUserAgent())) { 83 clrDef = ref; 84 break; 85 } 86 } 87 88 if (clrDef == null) 89 return Color.black; 90 91 Bridge bridge = ctx.getBridge(clrDef); 92 if (bridge == null || !(bridge instanceof PaintBridge)) 93 return Color.black; 94 95 return ((PaintBridge)bridge).createPaint(ctx, clrDef, 96 paintedElement, 97 paintedNode, 98 opacity); 99 } 100 } 101 | Popular Tags |