KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > extension > svg > ColorSwitchBridge


1 /*
2
3    Copyright 2001,2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.extension.svg;
19
20 import java.awt.Color JavaDoc;
21 import java.awt.Paint JavaDoc;
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 JavaDoc;
30 import org.w3c.dom.Node JavaDoc;
31
32 /**
33  * Bridge class for a regular polygon element.
34  *
35  * @author <a HREF="mailto:thomas.deweese@kodak.com">Thomas Deweese</a>
36  */

37 public class ColorSwitchBridge
38     extends AbstractSVGBridge
39     implements PaintBridge, BatikExtConstants {
40
41     /**
42      * Constructs a new bridge for the &lt;rect> element.
43      */

44     public ColorSwitchBridge() { /* nothing */ }
45
46     /**
47      * Returns the SVG namespace URI.
48      */

49     public String JavaDoc getNamespaceURI() {
50         return BATIK_EXT_NAMESPACE_URI;
51     }
52
53     /**
54      * Returns 'rect'.
55      */

56     public String JavaDoc getLocalName() {
57         return BATIK_EXT_COLOR_SWITCH_TAG;
58     }
59
60     /**
61      * Creates a <tt>Paint</tt> according to the specified parameters.
62      *
63      * @param ctx the bridge context to use
64      * @param paintElement the element that defines a Paint
65      * @param paintedElement the element referencing the paint
66      * @param paintedNode the graphics node on which the Paint will be applied
67      * @param opacity the opacity of the Paint to create
68      */

69     public Paint JavaDoc createPaint(BridgeContext ctx,
70                              Element JavaDoc paintElement,
71                              Element JavaDoc paintedElement,
72                              GraphicsNode paintedNode,
73                              float opacity) {
74         Element JavaDoc 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 JavaDoc ref = (Element JavaDoc)n;
81             if ( // (ref instanceof SVGTests) &&
82
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