KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > bridge > SVGSwitchElementBridge


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.bridge;
19
20 import org.apache.batik.gvt.CompositeGraphicsNode;
21 import org.apache.batik.gvt.GraphicsNode;
22 import org.w3c.dom.Element JavaDoc;
23 import org.w3c.dom.Node JavaDoc;
24 import org.w3c.dom.svg.SVGTests;
25
26 /**
27  * Bridge class for the <switch> element.
28  *
29  * @author <a HREF="mailto:tkormann@apache.org">Thierry Kormann</a>
30  * @version $Id: SVGSwitchElementBridge.java,v 1.17 2004/08/18 07:12:35 vhardy Exp $
31  */

32 public class SVGSwitchElementBridge extends AbstractSVGBridge
33     implements GraphicsNodeBridge {
34
35     /**
36      * Constructs a new bridge for the &lt;switch> element.
37      */

38     public SVGSwitchElementBridge() {}
39
40     /**
41      * Returns 'switch'.
42      */

43     public String JavaDoc getLocalName() {
44         return SVG_SWITCH_TAG;
45     }
46
47     public Bridge getInstance(){
48         return this;
49     }
50
51     /**
52      * Creates a <tt>GraphicsNode</tt> according to the specified parameters.
53      *
54      * @param ctx the bridge context to use
55      * @param e the element that describes the graphics node to build
56      * @return a graphics node that represents the specified element
57      */

58     public GraphicsNode createGraphicsNode(BridgeContext ctx, Element JavaDoc e) {
59         GraphicsNode refNode = null;
60         GVTBuilder builder = ctx.getGVTBuilder();
61         for (Node n = e.getFirstChild(); n != null; n = n.getNextSibling()) {
62             if (n.getNodeType() == Node.ELEMENT_NODE) {
63                 Element JavaDoc ref = (Element JavaDoc)n;
64                 if (n instanceof SVGTests
65                     && SVGUtilities.matchUserAgent(ref, ctx.getUserAgent())) {
66                     refNode = builder.build(ctx, ref);
67                     break;
68                 }
69             }
70         }
71         if (refNode == null) {
72             return null;
73         }
74         CompositeGraphicsNode group = new CompositeGraphicsNode();
75         group.add(refNode);
76         // 'transform'
77
String JavaDoc s = e.getAttributeNS(null, SVG_TRANSFORM_ATTRIBUTE);
78         if (s.length() != 0) {
79             group.setTransform
80                 (SVGUtilities.convertTransform(e, SVG_TRANSFORM_ATTRIBUTE, s));
81         }
82         return group;
83     }
84
85     /**
86      * Builds using the specified BridgeContext and element, the
87      * specified graphics node.
88      *
89      * @param ctx the bridge context to use
90      * @param e the element that describes the graphics node to build
91      * @param node the graphics node to build
92      */

93     public void buildGraphicsNode(BridgeContext ctx,
94                                   Element JavaDoc e,
95                                   GraphicsNode node) {
96         // bind the specified element and its associated graphics node if needed
97
if (ctx.isInteractive()) {
98             ctx.bind(e, node);
99         }
100     }
101
102     /**
103      * Returns true if the graphics node has to be displayed, false
104      * otherwise.
105      */

106     public boolean getDisplay(Element JavaDoc e) {
107         return CSSUtilities.convertDisplay(e);
108     }
109
110     /**
111      * Returns false as the &lt;switch> element is not a container.
112      */

113     public boolean isComposite() {
114         return false;
115     }
116 }
117
Popular Tags