01: /*
02:
03: Licensed to the Apache Software Foundation (ASF) under one or more
04: contributor license agreements. See the NOTICE file distributed with
05: this work for additional information regarding copyright ownership.
06: The ASF licenses this file to You under the Apache License, Version 2.0
07: (the "License"); you may not use this file except in compliance with
08: the License. You may obtain a copy of the License at
09:
10: http://www.apache.org/licenses/LICENSE-2.0
11:
12: Unless required by applicable law or agreed to in writing, software
13: distributed under the License is distributed on an "AS IS" BASIS,
14: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: See the License for the specific language governing permissions and
16: limitations under the License.
17:
18: */
19: package org.apache.batik.extension.svg;
20:
21: import java.awt.Color;
22: import java.awt.Paint;
23:
24: import org.apache.batik.bridge.AbstractSVGBridge;
25: import org.apache.batik.bridge.Bridge;
26: import org.apache.batik.bridge.BridgeContext;
27: import org.apache.batik.bridge.PaintBridge;
28: import org.apache.batik.bridge.SVGUtilities;
29: import org.apache.batik.gvt.GraphicsNode;
30: import org.w3c.dom.Element;
31: import org.w3c.dom.Node;
32:
33: /**
34: * Bridge class for the "color switch" extension element.
35: *
36: * @author <a href="mailto:thomas.deweese@kodak.com">Thomas Deweese</a>
37: * @version $Id: ColorSwitchBridge.java 475477 2006-11-15 22:44:28Z cam $
38: */
39: public class ColorSwitchBridge extends AbstractSVGBridge implements
40: PaintBridge, BatikExtConstants {
41:
42: /**
43: * Constructs a new bridge for the <batik:colorSwitch> element.
44: */
45: public ColorSwitchBridge() { /* nothing */
46: }
47:
48: /**
49: * Returns the SVG namespace URI.
50: */
51: public String getNamespaceURI() {
52: return BATIK_EXT_NAMESPACE_URI;
53: }
54:
55: /**
56: * Returns 'colorSwitch'.
57: */
58: public String getLocalName() {
59: return BATIK_EXT_COLOR_SWITCH_TAG;
60: }
61:
62: /**
63: * Creates a <tt>Paint</tt> according to the specified parameters.
64: *
65: * @param ctx the bridge context to use
66: * @param paintElement the element that defines a Paint
67: * @param paintedElement the element referencing the paint
68: * @param paintedNode the graphics node on which the Paint will be applied
69: * @param opacity the opacity of the Paint to create
70: */
71: public Paint createPaint(BridgeContext ctx, Element paintElement,
72: Element paintedElement, GraphicsNode paintedNode,
73: float opacity) {
74: Element clrDef = null;
75: for (Node n = paintElement.getFirstChild(); n != null; n = n
76: .getNextSibling()) {
77: if ((n.getNodeType() != Node.ELEMENT_NODE))
78: continue;
79: Element ref = (Element) n;
80: if ( // (ref instanceof SVGTests) &&
81: SVGUtilities.matchUserAgent(ref, ctx.getUserAgent())) {
82: clrDef = ref;
83: break;
84: }
85: }
86:
87: if (clrDef == null)
88: return Color.black;
89:
90: Bridge bridge = ctx.getBridge(clrDef);
91: if (bridge == null || !(bridge instanceof PaintBridge))
92: return Color.black;
93:
94: return ((PaintBridge) bridge).createPaint(ctx, clrDef,
95: paintedElement, paintedNode, opacity);
96: }
97: }
|