KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Copyright 2001-2004 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 java.awt.geom.Line2D JavaDoc;
21
22 import org.apache.batik.gvt.ShapeNode;
23 import org.apache.batik.gvt.ShapePainter;
24 import org.w3c.dom.Element JavaDoc;
25 import org.w3c.dom.events.MutationEvent JavaDoc;
26
27 /**
28  * Bridge class for the <line> element.
29  *
30  * @author <a HREF="mailto:tkormann@apache.org">Thierry Kormann</a>
31  * @version $Id: SVGLineElementBridge.java,v 1.14 2004/08/18 07:12:35 vhardy Exp $
32  */

33 public class SVGLineElementBridge extends SVGDecoratedShapeElementBridge {
34
35     /**
36      * Constructs a new bridge for the &lt;line> element.
37      */

38     public SVGLineElementBridge() {}
39
40     /**
41      * Returns 'line'.
42      */

43     public String JavaDoc getLocalName() {
44         return SVG_LINE_TAG;
45     }
46
47     /**
48      * Returns a new instance of this bridge.
49      */

50     public Bridge getInstance() {
51         return new SVGLineElementBridge();
52     }
53
54     /**
55      * Creates the shape painter associated to the specified element.
56      * This implementation creates a shape painter considering the
57      * various fill and stroke properties.
58      *
59      * @param ctx the bridge context to use
60      * @param e the element that describes the shape painter to use
61      * @param shapeNode the shape node that is interested in its shape painter
62      */

63     protected ShapePainter createFillStrokePainter(BridgeContext ctx,
64                                                    Element JavaDoc e,
65                                                    ShapeNode shapeNode) {
66         // 'fill' - ignored
67
// 'fill-opacity' - ignored
68
// 'stroke'
69
// 'stroke-opacity',
70
// 'stroke-width'
71
// 'stroke-linecap'
72
// 'stroke-linejoin'
73
// 'stroke-miterlimit'
74
// 'stroke-dasharray'
75
// 'stroke-dashoffset'
76
return PaintServer.convertStrokePainter(e, shapeNode, ctx);
77     }
78
79     /**
80      * Constructs a line according to the specified parameters.
81      *
82      * @param ctx the bridge context to use
83      * @param e the element that describes a rect element
84      * @param shapeNode the shape node to initialize
85      */

86     protected void buildShape(BridgeContext ctx,
87                               Element JavaDoc e,
88                               ShapeNode shapeNode) {
89
90         UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, e);
91         String JavaDoc s;
92
93         // 'x1' attribute - default is 0
94
s = e.getAttributeNS(null, SVG_X1_ATTRIBUTE);
95         float x1 = 0;
96         if (s.length() != 0) {
97             x1 = UnitProcessor.svgHorizontalCoordinateToUserSpace
98                 (s, SVG_X1_ATTRIBUTE, uctx);
99         }
100
101         // 'y1' attribute - default is 0
102
s = e.getAttributeNS(null, SVG_Y1_ATTRIBUTE);
103         float y1 = 0;
104         if (s.length() != 0) {
105             y1 = UnitProcessor.svgVerticalCoordinateToUserSpace
106                 (s, SVG_Y1_ATTRIBUTE, uctx);
107         }
108
109         // 'x2' attribute - default is 0
110
s = e.getAttributeNS(null, SVG_X2_ATTRIBUTE);
111         float x2 = 0;
112         if (s.length() != 0) {
113             x2 = UnitProcessor.svgHorizontalCoordinateToUserSpace
114                 (s, SVG_X2_ATTRIBUTE, uctx);
115         }
116
117         // 'y2' attribute - default is 0
118
s = e.getAttributeNS(null, SVG_Y2_ATTRIBUTE);
119         float y2 = 0;
120         if (s.length() != 0) {
121             y2 = UnitProcessor.svgVerticalCoordinateToUserSpace
122                 (s, SVG_Y2_ATTRIBUTE, uctx);
123         }
124
125         shapeNode.setShape(new Line2D.Float JavaDoc(x1, y1, x2, y2));
126     }
127
128     // BridgeUpdateHandler implementation //////////////////////////////////
129

130     /**
131      * Invoked when an MutationEvent of type 'DOMAttrModified' is fired.
132      */

133     public void handleDOMAttrModifiedEvent(MutationEvent JavaDoc evt) {
134         String JavaDoc attrName = evt.getAttrName();
135         if (attrName.equals(SVG_X1_ATTRIBUTE) ||
136             attrName.equals(SVG_Y1_ATTRIBUTE) ||
137             attrName.equals(SVG_X2_ATTRIBUTE) ||
138             attrName.equals(SVG_Y2_ATTRIBUTE)) {
139
140             buildShape(ctx, e, (ShapeNode)node);
141             handleGeometryChanged();
142         } else {
143             super.handleDOMAttrModifiedEvent(evt);
144         }
145     }
146 }
147
Popular Tags