KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > dom > svg > SVGPathSupport


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.dom.svg;
20
21 import java.awt.geom.Point2D JavaDoc;
22
23 import org.w3c.dom.svg.SVGPoint;
24 import org.w3c.dom.svg.SVGMatrix;
25 import org.w3c.dom.DOMException JavaDoc;
26
27 /**
28  * The clas provides support for the SVGPath interface.
29  *
30  * @author <a HREF="mailto:deweese@apache.org">deweese</a>
31  * @version $Id: SVGPathSupport.java,v 1.3 2005/04/02 14:26:09 deweese Exp $
32  */

33 public class SVGPathSupport {
34
35     /**
36      * To implement {@link org.w3c.dom.svg.SVGPathElement#getTotalLength()}.
37      */

38     public static float getTotalLength(SVGOMPathElement path) {
39         SVGPathContext pathCtx = (SVGPathContext)path.getSVGContext();
40         return pathCtx.getTotalLength();
41     }
42
43
44     /**
45      * To implement {@link org.w3c.dom.svg.SVGPathElement#getPointAtLength(float)}.
46      */

47     public static SVGPoint getPointAtLength(final SVGOMPathElement path,
48                                             final float distance) {
49         final SVGPathContext pathCtx = (SVGPathContext)path.getSVGContext();
50         if (pathCtx == null) return null;
51
52         return new SVGPoint() {
53                 public float getX() {
54                     Point2D JavaDoc pt = pathCtx.getPointAtLength(distance);
55                     return (float)pt.getX();
56                 }
57                 public float getY() {
58                     Point2D JavaDoc pt = pathCtx.getPointAtLength(distance);
59                     return (float)pt.getY();
60                 }
61                 public void setX(float x) throws DOMException JavaDoc {
62                     throw path.createDOMException
63                         (DOMException.NO_MODIFICATION_ALLOWED_ERR,
64                          "readonly.point", null);
65                 }
66                 public void setY(float y) throws DOMException JavaDoc {
67                     throw path.createDOMException
68                         (DOMException.NO_MODIFICATION_ALLOWED_ERR,
69                          "readonly.point", null);
70                 }
71                 public SVGPoint matrixTransform ( SVGMatrix matrix ) {
72                     throw path.createDOMException
73                         (DOMException.NO_MODIFICATION_ALLOWED_ERR,
74                          "readonly.point", null);
75                 }
76             };
77     }
78 };
79
Popular Tags