KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Copyright 2001,2003-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.Shape JavaDoc;
21
22 import org.apache.batik.css.engine.SVGCSSEngine;
23 import org.apache.batik.gvt.CompositeShapePainter;
24 import org.apache.batik.gvt.ShapeNode;
25 import org.apache.batik.gvt.ShapePainter;
26 import org.w3c.dom.Element JavaDoc;
27
28 /**
29  * The base bridge class for decorated shapes. Decorated shapes can be
30  * filled, stroked and can have markers.
31  *
32  * @author <a HREF="mailto:tkormann@apache.org">Thierry Kormann</a>
33  * @version $Id: SVGDecoratedShapeElementBridge.java,v 1.10 2004/08/18 07:12:33 vhardy Exp $
34  */

35 public abstract class SVGDecoratedShapeElementBridge
36         extends SVGShapeElementBridge {
37
38     /**
39      * Constructs a new bridge for SVG decorated shapes.
40      */

41     protected SVGDecoratedShapeElementBridge() {}
42
43
44     ShapePainter createFillStrokePainter(BridgeContext ctx,
45                                          Element JavaDoc e,
46                                          ShapeNode shapeNode) {
47         // 'fill'
48
// 'fill-opacity'
49
// 'stroke'
50
// 'stroke-opacity',
51
// 'stroke-width'
52
// 'stroke-linecap'
53
// 'stroke-linejoin'
54
// 'stroke-miterlimit'
55
// 'stroke-dasharray'
56
// 'stroke-dashoffset'
57
return super.createShapePainter(ctx, e, shapeNode);
58     }
59
60     ShapePainter createMarkerPainter(BridgeContext ctx,
61                                      Element JavaDoc e,
62                                      ShapeNode shapeNode) {
63         // marker-start
64
// marker-mid
65
// marker-end
66
return PaintServer.convertMarkers(e, shapeNode, ctx);
67     }
68
69     /**
70      * Creates the shape painter associated to the specified element.
71      * This implementation creates a shape painter considering the
72      * various fill and stroke properties in addition to the marker
73      * properties.
74      *
75      * @param ctx the bridge context to use
76      * @param e the element that describes the shape painter to use
77      * @param shapeNode the shape node that is interested in its shape painter
78      */

79     protected ShapePainter createShapePainter(BridgeContext ctx,
80                                               Element JavaDoc e,
81                                               ShapeNode shapeNode) {
82         ShapePainter fillAndStroke;
83         fillAndStroke = createFillStrokePainter(ctx, e, shapeNode);
84
85         ShapePainter markerPainter = createMarkerPainter(ctx, e, shapeNode);
86
87         Shape JavaDoc shape = shapeNode.getShape();
88         ShapePainter painter;
89
90         if (markerPainter != null) {
91             if (fillAndStroke != null) {
92                 CompositeShapePainter cp = new CompositeShapePainter(shape);
93                 cp.addShapePainter(fillAndStroke);
94                 cp.addShapePainter(markerPainter);
95                 painter = cp;
96             } else {
97                 painter = markerPainter;
98             }
99         } else {
100             painter = fillAndStroke;
101         }
102         return painter;
103     }
104
105     protected void handleCSSPropertyChanged(int property) {
106         switch(property) {
107         case SVGCSSEngine.MARKER_START_INDEX:
108         case SVGCSSEngine.MARKER_MID_INDEX:
109         case SVGCSSEngine.MARKER_END_INDEX:
110             if (!hasNewShapePainter) {
111                 hasNewShapePainter = true;
112                 ShapeNode shapeNode = (ShapeNode)node;
113                 shapeNode.setShapePainter(createShapePainter(ctx, e, shapeNode));
114             }
115             break;
116         default:
117             super.handleCSSPropertyChanged(property);
118         }
119     }
120 }
121
122
Popular Tags