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.geom.Line2D;
022:
023: import org.apache.batik.dom.svg.AnimatedLiveAttributeValue;
024: import org.apache.batik.dom.svg.LiveAttributeException;
025: import org.apache.batik.dom.svg.SVGOMLineElement;
026: import org.apache.batik.gvt.ShapeNode;
027: import org.apache.batik.gvt.ShapePainter;
028:
029: import org.w3c.dom.Element;
030:
031: /**
032: * Bridge class for the <line> element.
033: *
034: * @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
035: * @version $Id: SVGLineElementBridge.java 475477 2006-11-15 22:44:28Z cam $
036: */
037: public class SVGLineElementBridge extends
038: SVGDecoratedShapeElementBridge {
039:
040: /**
041: * Constructs a new bridge for the <line> element.
042: */
043: public SVGLineElementBridge() {
044: }
045:
046: /**
047: * Returns 'line'.
048: */
049: public String getLocalName() {
050: return SVG_LINE_TAG;
051: }
052:
053: /**
054: * Returns a new instance of this bridge.
055: */
056: public Bridge getInstance() {
057: return new SVGLineElementBridge();
058: }
059:
060: /**
061: * Creates the shape painter associated to the specified element.
062: * This implementation creates a shape painter considering the
063: * various fill and stroke properties.
064: *
065: * @param ctx the bridge context to use
066: * @param e the element that describes the shape painter to use
067: * @param shapeNode the shape node that is interested in its shape painter
068: */
069: protected ShapePainter createFillStrokePainter(BridgeContext ctx,
070: Element e, ShapeNode shapeNode) {
071: // 'fill' - ignored
072: // 'fill-opacity' - ignored
073: // 'stroke'
074: // 'stroke-opacity',
075: // 'stroke-width'
076: // 'stroke-linecap'
077: // 'stroke-linejoin'
078: // 'stroke-miterlimit'
079: // 'stroke-dasharray'
080: // 'stroke-dashoffset'
081: return PaintServer.convertStrokePainter(e, shapeNode, ctx);
082: }
083:
084: /**
085: * Constructs a line according to the specified parameters.
086: *
087: * @param ctx the bridge context to use
088: * @param e the element that describes a rect element
089: * @param shapeNode the shape node to initialize
090: */
091: protected void buildShape(BridgeContext ctx, Element e,
092: ShapeNode shapeNode) {
093:
094: try {
095: SVGOMLineElement le = (SVGOMLineElement) e;
096:
097: // 'x1' attribute - default is 0
098: float x1 = le.getX1().getAnimVal().getValue();
099:
100: // 'y1' attribute - default is 0
101: float y1 = le.getY1().getAnimVal().getValue();
102:
103: // 'x2' attribute - default is 0
104: float x2 = le.getX2().getAnimVal().getValue();
105:
106: // 'y2' attribute - default is 0
107: float y2 = le.getY2().getAnimVal().getValue();
108:
109: shapeNode.setShape(new Line2D.Float(x1, y1, x2, y2));
110: } catch (LiveAttributeException ex) {
111: throw new BridgeException(ctx, ex);
112: }
113: }
114:
115: // BridgeUpdateHandler implementation //////////////////////////////////
116:
117: /**
118: * Invoked when the animated value of an animatable attribute has changed.
119: */
120: public void handleAnimatedAttributeChanged(
121: AnimatedLiveAttributeValue alav) {
122: if (alav.getNamespaceURI() == null) {
123: String ln = alav.getLocalName();
124: if (ln.equals(SVG_X1_ATTRIBUTE)
125: || ln.equals(SVG_Y1_ATTRIBUTE)
126: || ln.equals(SVG_X2_ATTRIBUTE)
127: || ln.equals(SVG_Y2_ATTRIBUTE)) {
128: buildShape(ctx, e, (ShapeNode) node);
129: handleGeometryChanged();
130: return;
131: }
132: }
133: super.handleAnimatedAttributeChanged(alav);
134: }
135: }
|