001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.bridge;
020:
021: import java.awt.Shape;
022:
023: import org.apache.batik.css.engine.SVGCSSEngine;
024: import org.apache.batik.gvt.CompositeShapePainter;
025: import org.apache.batik.gvt.ShapeNode;
026: import org.apache.batik.gvt.ShapePainter;
027: import org.w3c.dom.Element;
028:
029: /**
030: * The base bridge class for decorated shapes. Decorated shapes can be
031: * filled, stroked and can have markers.
032: *
033: * @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
034: * @version $Id: SVGDecoratedShapeElementBridge.java 475477 2006-11-15 22:44:28Z cam $
035: */
036: public abstract class SVGDecoratedShapeElementBridge extends
037: SVGShapeElementBridge {
038:
039: /**
040: * Constructs a new bridge for SVG decorated shapes.
041: */
042: protected SVGDecoratedShapeElementBridge() {
043: }
044:
045: ShapePainter createFillStrokePainter(BridgeContext ctx, Element e,
046: ShapeNode shapeNode) {
047: // 'fill'
048: // 'fill-opacity'
049: // 'stroke'
050: // 'stroke-opacity',
051: // 'stroke-width'
052: // 'stroke-linecap'
053: // 'stroke-linejoin'
054: // 'stroke-miterlimit'
055: // 'stroke-dasharray'
056: // 'stroke-dashoffset'
057: return super .createShapePainter(ctx, e, shapeNode);
058: }
059:
060: ShapePainter createMarkerPainter(BridgeContext ctx, Element e,
061: ShapeNode shapeNode) {
062: // marker-start
063: // marker-mid
064: // marker-end
065: return PaintServer.convertMarkers(e, shapeNode, ctx);
066: }
067:
068: /**
069: * Creates the shape painter associated to the specified element.
070: * This implementation creates a shape painter considering the
071: * various fill and stroke properties in addition to the marker
072: * properties.
073: *
074: * @param ctx the bridge context to use
075: * @param e the element that describes the shape painter to use
076: * @param shapeNode the shape node that is interested in its shape painter
077: */
078: protected ShapePainter createShapePainter(BridgeContext ctx,
079: Element e, ShapeNode shapeNode) {
080: ShapePainter fillAndStroke;
081: fillAndStroke = createFillStrokePainter(ctx, e, shapeNode);
082:
083: ShapePainter markerPainter = createMarkerPainter(ctx, e,
084: shapeNode);
085:
086: Shape shape = shapeNode.getShape();
087: ShapePainter painter;
088:
089: if (markerPainter != null) {
090: if (fillAndStroke != null) {
091: CompositeShapePainter cp = new CompositeShapePainter(
092: shape);
093: cp.addShapePainter(fillAndStroke);
094: cp.addShapePainter(markerPainter);
095: painter = cp;
096: } else {
097: painter = markerPainter;
098: }
099: } 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,
114: shapeNode));
115: }
116: break;
117: default:
118: super.handleCSSPropertyChanged(property);
119: }
120: }
121: }
|