KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Copyright 2005 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
19 package org.apache.batik.bridge;
20
21 import java.awt.geom.AffineTransform JavaDoc;
22 import java.awt.geom.Rectangle2D JavaDoc;
23
24 import org.w3c.dom.Element JavaDoc;
25 import org.w3c.dom.events.MutationEvent JavaDoc;
26
27 import org.apache.batik.css.engine.CSSEngineEvent;
28 import org.apache.batik.dom.svg.SVGContext;
29 import org.apache.batik.dom.svg.SVGOMElement;
30
31 /**
32  * Base class for 'descriptive' elements, mostly title and desc.
33  *
34  * @author <a HREF="mailto:deweese@apache.org">deweese</a>
35  * @version $Id: SVGDescriptiveElementBridge.java,v 1.2 2005/03/27 08:58:30 cam Exp $
36  */

37 public abstract class SVGDescriptiveElementBridge extends AbstractSVGBridge
38     implements GenericBridge, BridgeUpdateHandler, SVGContext {
39
40     Element JavaDoc theElt;
41     Element JavaDoc parent;
42     BridgeContext theCtx;
43
44     public SVGDescriptiveElementBridge() {
45     }
46
47
48     /**
49      * Invoked to handle an <tt>Element</tt> for a given
50      * <tt>BridgeContext</tt>. For example, see the
51      * <tt>SVGDescElementBridge</tt>.
52      *
53      * @param ctx the bridge context to use
54      * @param e the element that describes the graphics node to build
55      */

56     public void handleElement(BridgeContext ctx, Element JavaDoc e){
57         UserAgent ua = ctx.getUserAgent();
58         ua.handleElement(e, Boolean.TRUE);
59         
60         if (ctx.isDynamic()) {
61             SVGDescriptiveElementBridge b;
62             b = (SVGDescriptiveElementBridge)getInstance();
63             b.theElt = e;
64             b.parent = (Element JavaDoc)e.getParentNode();
65             b.theCtx = ctx;
66             ((SVGOMElement)e).setSVGContext(b);
67         }
68
69     }
70
71     // BridgeUpdateHandler implementation ////////////////////////////////////
72

73     public void dispose() {
74         UserAgent ua = theCtx.getUserAgent();
75         ((SVGOMElement)theElt).setSVGContext(null);
76         ua.handleElement(theElt, parent);
77         theElt = null;
78         parent = null;
79     }
80     public void handleDOMNodeInsertedEvent(MutationEvent JavaDoc evt) {
81         UserAgent ua = theCtx.getUserAgent();
82         ua.handleElement(theElt, Boolean.TRUE);
83     }
84     public void handleDOMCharacterDataModified(MutationEvent JavaDoc evt) {
85         UserAgent ua = theCtx.getUserAgent();
86         ua.handleElement(theElt, Boolean.TRUE);
87     }
88
89     public void handleDOMNodeRemovedEvent (MutationEvent JavaDoc evt) {
90         dispose();
91     }
92
93     public void handleDOMAttrModifiedEvent(MutationEvent JavaDoc evt) { }
94     public void handleCSSEngineEvent(CSSEngineEvent evt) { }
95
96     // SVGContext implementation ///////////////////////////////////////////
97

98     /**
99      * Returns the size of a px CSS unit in millimeters.
100      */

101     public float getPixelUnitToMillimeter() {
102         return theCtx.getUserAgent().getPixelUnitToMillimeter();
103     }
104
105     /**
106      * Returns the size of a px CSS unit in millimeters.
107      * This will be removed after next release.
108      * @see #getPixelUnitToMillimeter()
109      */

110     public float getPixelToMM() {
111         return getPixelUnitToMillimeter();
112             
113     }
114
115     public Rectangle2D JavaDoc getBBox() { return null; }
116     public AffineTransform JavaDoc getScreenTransform() {
117         return theCtx.getUserAgent().getTransform();
118     }
119     public void setScreenTransform(AffineTransform JavaDoc at) {
120         theCtx.getUserAgent().setTransform(at);
121     }
122     public AffineTransform JavaDoc getCTM() { return null; }
123     public AffineTransform JavaDoc getGlobalTransform() { return null; }
124     public float getViewportWidth() {
125         return theCtx.getBlockWidth(theElt);
126     }
127     public float getViewportHeight() {
128         return theCtx.getBlockHeight(theElt);
129     }
130     public float getFontSize() { return 0; }
131 };
132
Popular Tags