0001: /*
0002:
0003: Licensed to the Apache Software Foundation (ASF) under one or more
0004: contributor license agreements. See the NOTICE file distributed with
0005: this work for additional information regarding copyright ownership.
0006: The ASF licenses this file to You under the Apache License, Version 2.0
0007: (the "License"); you may not use this file except in compliance with
0008: the License. You may obtain a copy of the License at
0009:
0010: http://www.apache.org/licenses/LICENSE-2.0
0011:
0012: Unless required by applicable law or agreed to in writing, software
0013: distributed under the License is distributed on an "AS IS" BASIS,
0014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0015: See the License for the specific language governing permissions and
0016: limitations under the License.
0017:
0018: */
0019: package org.apache.batik.dom.svg;
0020:
0021: import org.apache.batik.parser.DefaultPathHandler;
0022: import org.apache.batik.parser.ParseException;
0023: import org.apache.batik.parser.PathParser;
0024: import org.w3c.dom.DOMException;
0025: import org.w3c.dom.svg.SVGException;
0026: import org.w3c.dom.svg.SVGPathSeg;
0027: import org.w3c.dom.svg.SVGPathSegArcAbs;
0028: import org.w3c.dom.svg.SVGPathSegArcRel;
0029: import org.w3c.dom.svg.SVGPathSegClosePath;
0030: import org.w3c.dom.svg.SVGPathSegCurvetoCubicAbs;
0031: import org.w3c.dom.svg.SVGPathSegCurvetoCubicRel;
0032: import org.w3c.dom.svg.SVGPathSegCurvetoCubicSmoothAbs;
0033: import org.w3c.dom.svg.SVGPathSegCurvetoCubicSmoothRel;
0034: import org.w3c.dom.svg.SVGPathSegCurvetoQuadraticAbs;
0035: import org.w3c.dom.svg.SVGPathSegCurvetoQuadraticRel;
0036: import org.w3c.dom.svg.SVGPathSegCurvetoQuadraticSmoothAbs;
0037: import org.w3c.dom.svg.SVGPathSegCurvetoQuadraticSmoothRel;
0038: import org.w3c.dom.svg.SVGPathSegLinetoAbs;
0039: import org.w3c.dom.svg.SVGPathSegLinetoHorizontalAbs;
0040: import org.w3c.dom.svg.SVGPathSegLinetoHorizontalRel;
0041: import org.w3c.dom.svg.SVGPathSegLinetoRel;
0042: import org.w3c.dom.svg.SVGPathSegLinetoVerticalAbs;
0043: import org.w3c.dom.svg.SVGPathSegLinetoVerticalRel;
0044: import org.w3c.dom.svg.SVGPathSegList;
0045: import org.w3c.dom.svg.SVGPathSegMovetoAbs;
0046: import org.w3c.dom.svg.SVGPathSegMovetoRel;
0047:
0048: /**
0049: * This class is the implementation of
0050: * <code>SVGPathSegList</code>.
0051: *
0052: * @author nicolas.socheleau@bitflash.com
0053: * @version $Id: AbstractSVGPathSegList.java 476924 2006-11-19 21:13:26Z dvholten $
0054: */
0055: public abstract class AbstractSVGPathSegList extends AbstractSVGList
0056: implements SVGPathSegList, SVGPathSegConstants {
0057:
0058: /**
0059: * Separator for a point list.
0060: */
0061: public static final String SVG_PATHSEG_LIST_SEPARATOR = " ";
0062:
0063: /**
0064: * Creates a new SVGPathSegList.
0065: */
0066: protected AbstractSVGPathSegList() {
0067: super ();
0068: }
0069:
0070: /**
0071: * Return the separator between segments in the list.
0072: */
0073: protected String getItemSeparator() {
0074: return SVG_PATHSEG_LIST_SEPARATOR;
0075: }
0076:
0077: /**
0078: * Create an SVGException when the checkItemType fails.
0079: *
0080: * @return SVGException
0081: */
0082: protected abstract SVGException createSVGException(short type,
0083: String key, Object[] args);
0084:
0085: /**
0086: */
0087: public SVGPathSeg initialize(SVGPathSeg newItem)
0088: throws DOMException, SVGException {
0089:
0090: return (SVGPathSeg) initializeImpl(newItem);
0091: }
0092:
0093: /**
0094: */
0095: public SVGPathSeg getItem(int index) throws DOMException {
0096:
0097: return (SVGPathSeg) getItemImpl(index);
0098: }
0099:
0100: /**
0101: */
0102: public SVGPathSeg insertItemBefore(SVGPathSeg newItem, int index)
0103: throws DOMException, SVGException {
0104:
0105: return (SVGPathSeg) insertItemBeforeImpl(newItem, index);
0106: }
0107:
0108: /**
0109: */
0110: public SVGPathSeg replaceItem(SVGPathSeg newItem, int index)
0111: throws DOMException, SVGException {
0112:
0113: return (SVGPathSeg) replaceItemImpl(newItem, index);
0114: }
0115:
0116: /**
0117: */
0118: public SVGPathSeg removeItem(int index) throws DOMException {
0119:
0120: return (SVGPathSeg) removeItemImpl(index);
0121: }
0122:
0123: /**
0124: */
0125: public SVGPathSeg appendItem(SVGPathSeg newItem)
0126: throws DOMException, SVGException {
0127:
0128: return (SVGPathSeg) appendItemImpl(newItem);
0129: }
0130:
0131: /**
0132: */
0133: protected SVGItem createSVGItem(Object newItem) {
0134:
0135: SVGPathSeg pathSeg = (SVGPathSeg) newItem;
0136:
0137: return createPathSegItem(pathSeg);
0138: }
0139:
0140: /**
0141: * Parse the 'd' attribute.
0142: *
0143: * @param value 'd' attribute value
0144: * @param handler : list handler
0145: */
0146: protected void doParse(String value, ListHandler handler)
0147: throws ParseException {
0148:
0149: PathParser pathParser = new PathParser();
0150:
0151: PathSegListBuilder builder = new PathSegListBuilder(handler);
0152:
0153: pathParser.setPathHandler(builder);
0154: pathParser.parse(value);
0155:
0156: }
0157:
0158: /**
0159: * Check if the item is an SVGPathSeg.
0160: */
0161: protected void checkItemType(Object newItem) {
0162: if (!(newItem instanceof SVGPathSeg)) {
0163: createSVGException(SVGException.SVG_WRONG_TYPE_ERR,
0164: "expected SVGPathSeg", null);
0165: }
0166: }
0167:
0168: /**
0169: * create an SVGItem representing this SVGPathSeg.
0170: */
0171: protected SVGPathSegItem createPathSegItem(SVGPathSeg pathSeg) {
0172:
0173: SVGPathSegItem pathSegItem = null;
0174:
0175: short type = pathSeg.getPathSegType();
0176:
0177: switch (type) {
0178: case SVGPathSeg.PATHSEG_ARC_ABS:
0179: case SVGPathSeg.PATHSEG_ARC_REL:
0180: pathSegItem = new SVGPathSegArcItem(pathSeg);
0181: break;
0182: case SVGPathSeg.PATHSEG_CLOSEPATH:
0183: pathSegItem = new SVGPathSegItem(pathSeg);
0184: break;
0185: case SVGPathSeg.PATHSEG_CURVETO_CUBIC_ABS:
0186: case SVGPathSeg.PATHSEG_CURVETO_CUBIC_REL:
0187: pathSegItem = new SVGPathSegCurvetoCubicItem(pathSeg);
0188: break;
0189: case SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_ABS:
0190: case SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_REL:
0191: pathSegItem = new SVGPathSegCurvetoCubicSmoothItem(pathSeg);
0192: break;
0193: case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_ABS:
0194: case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_REL:
0195: pathSegItem = new SVGPathSegCurvetoQuadraticItem(pathSeg);
0196: break;
0197: case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS:
0198: case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL:
0199: pathSegItem = new SVGPathSegCurvetoQuadraticSmoothItem(
0200: pathSeg);
0201: break;
0202: case SVGPathSeg.PATHSEG_LINETO_ABS:
0203: case SVGPathSeg.PATHSEG_LINETO_REL:
0204: case SVGPathSeg.PATHSEG_MOVETO_ABS:
0205: case SVGPathSeg.PATHSEG_MOVETO_REL:
0206: pathSegItem = new SVGPathSegMovetoLinetoItem(pathSeg);
0207: break;
0208: case SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_REL:
0209: case SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_ABS:
0210: pathSegItem = new SVGPathSegLinetoHorizontalItem(pathSeg);
0211: break;
0212: case SVGPathSeg.PATHSEG_LINETO_VERTICAL_REL:
0213: case SVGPathSeg.PATHSEG_LINETO_VERTICAL_ABS:
0214: pathSegItem = new SVGPathSegLinetoVerticalItem(pathSeg);
0215: break;
0216: default:
0217: }
0218: return pathSegItem;
0219: }
0220:
0221: /**
0222: * Internal representation of the item SVGPathSeg.
0223: */
0224: protected class SVGPathSegItem extends AbstractSVGItem implements
0225: SVGPathSeg, SVGPathSegClosePath {
0226:
0227: protected short type;
0228:
0229: protected String letter;
0230:
0231: protected float x;
0232: protected float y;
0233: protected float x1;
0234: protected float y1;
0235: protected float x2;
0236: protected float y2;
0237: protected float r1;
0238: protected float r2;
0239: protected float angle;
0240: protected boolean largeArcFlag;
0241: protected boolean sweepFlag;
0242:
0243: protected SVGPathSegItem() {
0244: }
0245:
0246: public SVGPathSegItem(short type, String letter) {
0247: this .type = type;
0248: this .letter = letter;
0249: }
0250:
0251: public SVGPathSegItem(SVGPathSeg pathSeg) {
0252: type = pathSeg.getPathSegType();
0253: switch (type) {
0254: case SVGPathSeg.PATHSEG_CLOSEPATH:
0255: letter = PATHSEG_CLOSEPATH_LETTER;
0256: break;
0257: default:
0258: }
0259: }
0260:
0261: protected String getStringValue() {
0262: return letter;
0263: }
0264:
0265: public short getPathSegType() {
0266: return type;
0267: }
0268:
0269: public String getPathSegTypeAsLetter() {
0270: return letter;
0271: }
0272:
0273: }
0274:
0275: public class SVGPathSegMovetoLinetoItem extends SVGPathSegItem
0276: implements SVGPathSegMovetoAbs, SVGPathSegMovetoRel,
0277: SVGPathSegLinetoAbs, SVGPathSegLinetoRel {
0278:
0279: public SVGPathSegMovetoLinetoItem(short type, String letter,
0280: float x, float y) {
0281: super (type, letter);
0282: this .x = x;
0283: this .y = y;
0284: }
0285:
0286: public SVGPathSegMovetoLinetoItem(SVGPathSeg pathSeg) {
0287: type = pathSeg.getPathSegType();
0288: switch (type) {
0289: case SVGPathSeg.PATHSEG_LINETO_REL:
0290: letter = PATHSEG_LINETO_REL_LETTER;
0291: x = ((SVGPathSegLinetoRel) pathSeg).getX();
0292: y = ((SVGPathSegLinetoRel) pathSeg).getY();
0293: break;
0294: case SVGPathSeg.PATHSEG_LINETO_ABS:
0295: letter = PATHSEG_LINETO_ABS_LETTER;
0296: x = ((SVGPathSegLinetoAbs) pathSeg).getX();
0297: y = ((SVGPathSegLinetoAbs) pathSeg).getY();
0298: break;
0299: case SVGPathSeg.PATHSEG_MOVETO_REL:
0300: letter = PATHSEG_MOVETO_REL_LETTER;
0301: x = ((SVGPathSegMovetoRel) pathSeg).getX();
0302: y = ((SVGPathSegMovetoRel) pathSeg).getY();
0303: break;
0304: case SVGPathSeg.PATHSEG_MOVETO_ABS:
0305: letter = PATHSEG_MOVETO_ABS_LETTER;
0306: x = ((SVGPathSegMovetoAbs) pathSeg).getX();
0307: y = ((SVGPathSegMovetoAbs) pathSeg).getY();
0308: break;
0309: default:
0310: }
0311: }
0312:
0313: public float getX() {
0314: return x;
0315: }
0316:
0317: public float getY() {
0318: return y;
0319: }
0320:
0321: public void setX(float x) {
0322: this .x = x;
0323: resetAttribute();
0324: }
0325:
0326: public void setY(float y) {
0327: this .y = y;
0328: resetAttribute();
0329: }
0330:
0331: protected String getStringValue() {
0332: return letter + ' ' + Float.toString(x) + ' '
0333: + Float.toString(y);
0334: }
0335: }
0336:
0337: public class SVGPathSegCurvetoCubicItem extends SVGPathSegItem
0338: implements SVGPathSegCurvetoCubicAbs,
0339: SVGPathSegCurvetoCubicRel {
0340:
0341: public SVGPathSegCurvetoCubicItem(short type, String letter,
0342: float x1, float y1, float x2, float y2, float x, float y) {
0343: super (type, letter);
0344: this .x = x;
0345: this .y = y;
0346: this .x1 = x1;
0347: this .y1 = y1;
0348: this .x2 = x2;
0349: this .y2 = y2;
0350: }
0351:
0352: public SVGPathSegCurvetoCubicItem(SVGPathSeg pathSeg) {
0353: this .type = pathSeg.getPathSegType();
0354: switch (type) {
0355: case SVGPathSeg.PATHSEG_CURVETO_CUBIC_ABS:
0356: letter = PATHSEG_CURVETO_CUBIC_ABS_LETTER;
0357: x = ((SVGPathSegCurvetoCubicAbs) pathSeg).getX();
0358: y = ((SVGPathSegCurvetoCubicAbs) pathSeg).getY();
0359: x1 = ((SVGPathSegCurvetoCubicAbs) pathSeg).getX1();
0360: y1 = ((SVGPathSegCurvetoCubicAbs) pathSeg).getY1();
0361: x2 = ((SVGPathSegCurvetoCubicAbs) pathSeg).getX2();
0362: y2 = ((SVGPathSegCurvetoCubicAbs) pathSeg).getY2();
0363: break;
0364: case SVGPathSeg.PATHSEG_CURVETO_CUBIC_REL:
0365: letter = PATHSEG_CURVETO_CUBIC_REL_LETTER;
0366: x = ((SVGPathSegCurvetoCubicRel) pathSeg).getX();
0367: y = ((SVGPathSegCurvetoCubicRel) pathSeg).getY();
0368: x1 = ((SVGPathSegCurvetoCubicRel) pathSeg).getX1();
0369: y1 = ((SVGPathSegCurvetoCubicRel) pathSeg).getY1();
0370: x2 = ((SVGPathSegCurvetoCubicRel) pathSeg).getX2();
0371: y2 = ((SVGPathSegCurvetoCubicRel) pathSeg).getY2();
0372: break;
0373: default:
0374: }
0375: }
0376:
0377: public float getX() {
0378: return x;
0379: }
0380:
0381: public float getY() {
0382: return y;
0383: }
0384:
0385: public void setX(float x) {
0386: this .x = x;
0387: resetAttribute();
0388: }
0389:
0390: public void setY(float y) {
0391: this .y = y;
0392: resetAttribute();
0393: }
0394:
0395: public float getX1() {
0396: return x1;
0397: }
0398:
0399: public float getY1() {
0400: return y1;
0401: }
0402:
0403: public void setX1(float x1) {
0404: this .x1 = x1;
0405: resetAttribute();
0406: }
0407:
0408: public void setY1(float y1) {
0409: this .y1 = y1;
0410: resetAttribute();
0411: }
0412:
0413: public float getX2() {
0414: return x2;
0415: }
0416:
0417: public float getY2() {
0418: return y2;
0419: }
0420:
0421: public void setX2(float x2) {
0422: this .x2 = x2;
0423: resetAttribute();
0424: }
0425:
0426: public void setY2(float y2) {
0427: this .y2 = y2;
0428: resetAttribute();
0429: }
0430:
0431: protected String getStringValue() {
0432: return letter + ' ' + Float.toString(x1) + ' '
0433: + Float.toString(y1) + ' ' + Float.toString(x2)
0434: + ' ' + Float.toString(y2) + ' '
0435: + Float.toString(x) + ' ' + Float.toString(y);
0436: }
0437: }
0438:
0439: public class SVGPathSegCurvetoQuadraticItem extends SVGPathSegItem
0440: implements SVGPathSegCurvetoQuadraticAbs,
0441: SVGPathSegCurvetoQuadraticRel {
0442:
0443: public SVGPathSegCurvetoQuadraticItem(short type,
0444: String letter, float x1, float y1, float x, float y) {
0445: super (type, letter);
0446: this .x = x;
0447: this .y = y;
0448: this .x1 = x1;
0449: this .y1 = y1;
0450: }
0451:
0452: public SVGPathSegCurvetoQuadraticItem(SVGPathSeg pathSeg) {
0453: this .type = pathSeg.getPathSegType();
0454: switch (type) {
0455: case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_ABS:
0456: letter = PATHSEG_CURVETO_QUADRATIC_ABS_LETTER;
0457: x = ((SVGPathSegCurvetoQuadraticAbs) pathSeg).getX();
0458: y = ((SVGPathSegCurvetoQuadraticAbs) pathSeg).getY();
0459: x1 = ((SVGPathSegCurvetoQuadraticAbs) pathSeg).getX1();
0460: y1 = ((SVGPathSegCurvetoQuadraticAbs) pathSeg).getY1();
0461: break;
0462: case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_REL:
0463: letter = PATHSEG_CURVETO_QUADRATIC_REL_LETTER;
0464: x = ((SVGPathSegCurvetoQuadraticRel) pathSeg).getX();
0465: y = ((SVGPathSegCurvetoQuadraticRel) pathSeg).getY();
0466: x1 = ((SVGPathSegCurvetoQuadraticRel) pathSeg).getX1();
0467: y1 = ((SVGPathSegCurvetoQuadraticRel) pathSeg).getY1();
0468: break;
0469: default:
0470:
0471: }
0472: }
0473:
0474: public float getX() {
0475: return x;
0476: }
0477:
0478: public float getY() {
0479: return y;
0480: }
0481:
0482: public void setX(float x) {
0483: this .x = x;
0484: resetAttribute();
0485: }
0486:
0487: public void setY(float y) {
0488: this .y = y;
0489: resetAttribute();
0490: }
0491:
0492: public float getX1() {
0493: return x1;
0494: }
0495:
0496: public float getY1() {
0497: return y1;
0498: }
0499:
0500: public void setX1(float x1) {
0501: this .x1 = x1;
0502: resetAttribute();
0503: }
0504:
0505: public void setY1(float y1) {
0506: this .y1 = y1;
0507: resetAttribute();
0508: }
0509:
0510: protected String getStringValue() {
0511:
0512: return letter + ' ' + Float.toString(x1) + ' '
0513: + Float.toString(y1) + ' ' + Float.toString(x)
0514: + ' ' + Float.toString(y);
0515: }
0516: }
0517:
0518: public class SVGPathSegArcItem extends SVGPathSegItem implements
0519: SVGPathSegArcAbs, SVGPathSegArcRel {
0520:
0521: public SVGPathSegArcItem(short type, String letter, float r1,
0522: float r2, float angle, boolean largeArcFlag,
0523: boolean sweepFlag, float x, float y) {
0524: super (type, letter);
0525: this .x = x;
0526: this .y = y;
0527: this .r1 = r1;
0528: this .r2 = r2;
0529: this .angle = angle;
0530: this .largeArcFlag = largeArcFlag;
0531: this .sweepFlag = sweepFlag;
0532: }
0533:
0534: public SVGPathSegArcItem(SVGPathSeg pathSeg) {
0535: type = pathSeg.getPathSegType();
0536: switch (type) {
0537: case SVGPathSeg.PATHSEG_ARC_ABS:
0538: letter = PATHSEG_ARC_ABS_LETTER;
0539: x = ((SVGPathSegArcAbs) pathSeg).getX();
0540: y = ((SVGPathSegArcAbs) pathSeg).getY();
0541: r1 = ((SVGPathSegArcAbs) pathSeg).getR1();
0542: r2 = ((SVGPathSegArcAbs) pathSeg).getR2();
0543: angle = ((SVGPathSegArcAbs) pathSeg).getAngle();
0544: largeArcFlag = ((SVGPathSegArcAbs) pathSeg)
0545: .getLargeArcFlag();
0546: sweepFlag = ((SVGPathSegArcAbs) pathSeg).getSweepFlag();
0547: break;
0548: case SVGPathSeg.PATHSEG_ARC_REL:
0549: letter = PATHSEG_ARC_REL_LETTER;
0550: x = ((SVGPathSegArcRel) pathSeg).getX();
0551: y = ((SVGPathSegArcRel) pathSeg).getY();
0552: r1 = ((SVGPathSegArcRel) pathSeg).getR1();
0553: r2 = ((SVGPathSegArcRel) pathSeg).getR2();
0554: angle = ((SVGPathSegArcRel) pathSeg).getAngle();
0555: largeArcFlag = ((SVGPathSegArcRel) pathSeg)
0556: .getLargeArcFlag();
0557: sweepFlag = ((SVGPathSegArcRel) pathSeg).getSweepFlag();
0558: break;
0559: default:
0560: }
0561: }
0562:
0563: public float getX() {
0564: return x;
0565: }
0566:
0567: public float getY() {
0568: return y;
0569: }
0570:
0571: public void setX(float x) {
0572: this .x = x;
0573: resetAttribute();
0574: }
0575:
0576: public void setY(float y) {
0577: this .y = y;
0578: resetAttribute();
0579: }
0580:
0581: public float getR1() {
0582: return r1;
0583: }
0584:
0585: public float getR2() {
0586: return r2;
0587: }
0588:
0589: public void setR1(float r1) {
0590: this .r1 = r1;
0591: resetAttribute();
0592: }
0593:
0594: public void setR2(float r2) {
0595: this .r2 = r2;
0596: resetAttribute();
0597: }
0598:
0599: public float getAngle() {
0600: return angle;
0601: }
0602:
0603: public void setAngle(float angle) {
0604: this .angle = angle;
0605: resetAttribute();
0606: }
0607:
0608: public boolean getSweepFlag() {
0609: return sweepFlag;
0610: }
0611:
0612: public void setSweepFlag(boolean sweepFlag) {
0613: this .sweepFlag = sweepFlag;
0614: resetAttribute();
0615: }
0616:
0617: public boolean getLargeArcFlag() {
0618: return largeArcFlag;
0619: }
0620:
0621: public void setLargeArcFlag(boolean largeArcFlag) {
0622: this .largeArcFlag = largeArcFlag;
0623: resetAttribute();
0624: }
0625:
0626: protected String getStringValue() {
0627: return letter + ' ' + Float.toString(r1) + ' '
0628: + Float.toString(r2) + ' ' + Float.toString(angle)
0629: + ' ' + ((largeArcFlag ? "1" : "0")) + ' '
0630: + ((sweepFlag ? "1" : "0")) + (' ')
0631: + Float.toString(x) + ' ' + Float.toString(y);
0632: }
0633: }
0634:
0635: public class SVGPathSegLinetoHorizontalItem extends SVGPathSegItem
0636: implements SVGPathSegLinetoHorizontalAbs,
0637: SVGPathSegLinetoHorizontalRel {
0638:
0639: public SVGPathSegLinetoHorizontalItem(short type,
0640: String letter, float value) {
0641: super (type, letter);
0642: this .x = value;
0643: }
0644:
0645: public SVGPathSegLinetoHorizontalItem(SVGPathSeg pathSeg) {
0646: this .type = pathSeg.getPathSegType();
0647: switch (type) {
0648: case SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_ABS:
0649: letter = PATHSEG_LINETO_HORIZONTAL_ABS_LETTER;
0650: x = ((SVGPathSegLinetoHorizontalAbs) pathSeg).getX();
0651: break;
0652: case SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_REL:
0653: letter = PATHSEG_LINETO_HORIZONTAL_REL_LETTER;
0654: x = ((SVGPathSegLinetoHorizontalRel) pathSeg).getX();
0655: break;
0656: default:
0657: }
0658: }
0659:
0660: public float getX() {
0661: return x;
0662: }
0663:
0664: public void setX(float x) {
0665: this .x = x;
0666: resetAttribute();
0667: }
0668:
0669: protected String getStringValue() {
0670: return letter + ' ' + Float.toString(x);
0671: }
0672: }
0673:
0674: public class SVGPathSegLinetoVerticalItem extends SVGPathSegItem
0675: implements SVGPathSegLinetoVerticalAbs,
0676: SVGPathSegLinetoVerticalRel {
0677:
0678: public SVGPathSegLinetoVerticalItem(short type, String letter,
0679: float value) {
0680: super (type, letter);
0681: this .y = value;
0682: }
0683:
0684: public SVGPathSegLinetoVerticalItem(SVGPathSeg pathSeg) {
0685: type = pathSeg.getPathSegType();
0686: switch (type) {
0687: case SVGPathSeg.PATHSEG_LINETO_VERTICAL_ABS:
0688: letter = PATHSEG_LINETO_VERTICAL_ABS_LETTER;
0689: y = ((SVGPathSegLinetoVerticalAbs) pathSeg).getY();
0690: break;
0691: case SVGPathSeg.PATHSEG_LINETO_VERTICAL_REL:
0692: letter = PATHSEG_LINETO_VERTICAL_REL_LETTER;
0693: y = ((SVGPathSegLinetoVerticalRel) pathSeg).getY();
0694: break;
0695: default:
0696: }
0697: }
0698:
0699: public float getY() {
0700: return y;
0701: }
0702:
0703: public void setY(float y) {
0704: this .y = y;
0705: resetAttribute();
0706: }
0707:
0708: protected String getStringValue() {
0709: return letter + ' ' + Float.toString(y);
0710: }
0711: }
0712:
0713: public class SVGPathSegCurvetoCubicSmoothItem extends
0714: SVGPathSegItem implements SVGPathSegCurvetoCubicSmoothAbs,
0715: SVGPathSegCurvetoCubicSmoothRel {
0716:
0717: public SVGPathSegCurvetoCubicSmoothItem(short type,
0718: String letter, float x2, float y2, float x, float y) {
0719: super (type, letter);
0720: this .x = x;
0721: this .y = y;
0722: this .x2 = x2;
0723: this .y2 = y2;
0724: }
0725:
0726: public SVGPathSegCurvetoCubicSmoothItem(SVGPathSeg pathSeg) {
0727: type = pathSeg.getPathSegType();
0728: switch (type) {
0729: case SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_ABS:
0730: letter = PATHSEG_CURVETO_CUBIC_SMOOTH_ABS_LETTER;
0731: x = ((SVGPathSegCurvetoCubicSmoothAbs) pathSeg).getX();
0732: y = ((SVGPathSegCurvetoCubicSmoothAbs) pathSeg).getY();
0733: x2 = ((SVGPathSegCurvetoCubicSmoothAbs) pathSeg)
0734: .getX2();
0735: y2 = ((SVGPathSegCurvetoCubicSmoothAbs) pathSeg)
0736: .getY2();
0737: break;
0738: case SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_REL:
0739: letter = PATHSEG_CURVETO_CUBIC_SMOOTH_REL_LETTER;
0740: x = ((SVGPathSegCurvetoCubicSmoothRel) pathSeg).getX();
0741: y = ((SVGPathSegCurvetoCubicSmoothRel) pathSeg).getY();
0742: x2 = ((SVGPathSegCurvetoCubicSmoothRel) pathSeg)
0743: .getX2();
0744: y2 = ((SVGPathSegCurvetoCubicSmoothRel) pathSeg)
0745: .getY2();
0746: break;
0747: default:
0748: }
0749: }
0750:
0751: public float getX() {
0752: return x;
0753: }
0754:
0755: public float getY() {
0756: return y;
0757: }
0758:
0759: public void setX(float x) {
0760: this .x = x;
0761: resetAttribute();
0762: }
0763:
0764: public void setY(float y) {
0765: this .y = y;
0766: resetAttribute();
0767: }
0768:
0769: public float getX2() {
0770: return x2;
0771: }
0772:
0773: public float getY2() {
0774: return y2;
0775: }
0776:
0777: public void setX2(float x2) {
0778: this .x2 = x2;
0779: resetAttribute();
0780: }
0781:
0782: public void setY2(float y2) {
0783: this .y2 = y2;
0784: resetAttribute();
0785: }
0786:
0787: protected String getStringValue() {
0788: return letter + ' ' + Float.toString(x2) + ' '
0789: + Float.toString(y2) + ' ' + Float.toString(x)
0790: + ' ' + Float.toString(y);
0791: }
0792: }
0793:
0794: public class SVGPathSegCurvetoQuadraticSmoothItem extends
0795: SVGPathSegItem implements
0796: SVGPathSegCurvetoQuadraticSmoothAbs,
0797: SVGPathSegCurvetoQuadraticSmoothRel {
0798:
0799: public SVGPathSegCurvetoQuadraticSmoothItem(short type,
0800: String letter, float x, float y) {
0801: super (type, letter);
0802: this .x = x;
0803: this .y = y;
0804: }
0805:
0806: public SVGPathSegCurvetoQuadraticSmoothItem(SVGPathSeg pathSeg) {
0807: type = pathSeg.getPathSegType();
0808: switch (type) {
0809: case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS:
0810: letter = PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS_LETTER;
0811: x = ((SVGPathSegCurvetoQuadraticSmoothAbs) pathSeg)
0812: .getX();
0813: y = ((SVGPathSegCurvetoQuadraticSmoothAbs) pathSeg)
0814: .getY();
0815: break;
0816: case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL:
0817: letter = PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL_LETTER;
0818: x = ((SVGPathSegCurvetoQuadraticSmoothRel) pathSeg)
0819: .getX();
0820: y = ((SVGPathSegCurvetoQuadraticSmoothRel) pathSeg)
0821: .getY();
0822: break;
0823: default:
0824: }
0825: }
0826:
0827: public float getX() {
0828: return x;
0829: }
0830:
0831: public float getY() {
0832: return y;
0833: }
0834:
0835: public void setX(float x) {
0836: this .x = x;
0837: resetAttribute();
0838: }
0839:
0840: public void setY(float y) {
0841: this .y = y;
0842: resetAttribute();
0843: }
0844:
0845: protected String getStringValue() {
0846: return letter + ' ' + Float.toString(x) + ' '
0847: + Float.toString(y);
0848: }
0849: }
0850:
0851: protected class PathSegListBuilder extends DefaultPathHandler {
0852:
0853: protected ListHandler listHandler;
0854:
0855: public PathSegListBuilder(ListHandler listHandler) {
0856: this .listHandler = listHandler;
0857: }
0858:
0859: /**
0860: * Implements {@link org.apache.batik.parser.PathHandler#startPath()}.
0861: */
0862: public void startPath() throws ParseException {
0863: listHandler.startList();
0864: }
0865:
0866: /**
0867: * Implements {@link org.apache.batik.parser.PathHandler#endPath()}.
0868: */
0869: public void endPath() throws ParseException {
0870: listHandler.endList();
0871: }
0872:
0873: /**
0874: * Implements {@link org.apache.batik.parser.PathHandler#movetoRel(float,float)}.
0875: */
0876: public void movetoRel(float x, float y) throws ParseException {
0877: listHandler.item(new SVGPathSegMovetoLinetoItem(
0878: SVGPathSeg.PATHSEG_MOVETO_REL,
0879: PATHSEG_MOVETO_REL_LETTER, x, y));
0880: }
0881:
0882: /**
0883: * Implements {@link org.apache.batik.parser.PathHandler#movetoAbs(float,float)}.
0884: */
0885: public void movetoAbs(float x, float y) throws ParseException {
0886: listHandler.item(new SVGPathSegMovetoLinetoItem(
0887: SVGPathSeg.PATHSEG_MOVETO_ABS,
0888: PATHSEG_MOVETO_ABS_LETTER, x, y));
0889: }
0890:
0891: /**
0892: * Implements {@link org.apache.batik.parser.PathHandler#closePath()}.
0893: */
0894: public void closePath() throws ParseException {
0895: listHandler.item(new SVGPathSegItem(
0896: SVGPathSeg.PATHSEG_CLOSEPATH,
0897: PATHSEG_CLOSEPATH_LETTER));
0898:
0899: }
0900:
0901: /**
0902: * Implements {@link org.apache.batik.parser.PathHandler#linetoRel(float,float)}.
0903: */
0904: public void linetoRel(float x, float y) throws ParseException {
0905: listHandler.item(new SVGPathSegMovetoLinetoItem(
0906: SVGPathSeg.PATHSEG_LINETO_REL,
0907: PATHSEG_LINETO_REL_LETTER, x, y));
0908: }
0909:
0910: /**
0911: * Implements {@link org.apache.batik.parser.PathHandler#linetoAbs(float,float)}.
0912: */
0913: public void linetoAbs(float x, float y) throws ParseException {
0914: listHandler.item(new SVGPathSegMovetoLinetoItem(
0915: SVGPathSeg.PATHSEG_LINETO_ABS,
0916: PATHSEG_LINETO_ABS_LETTER, x, y));
0917: }
0918:
0919: /**
0920: * Implements {@link org.apache.batik.parser.PathHandler#linetoHorizontalRel(float)}.
0921: */
0922: public void linetoHorizontalRel(float x) throws ParseException {
0923: listHandler.item(new SVGPathSegLinetoHorizontalItem(
0924: SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_REL,
0925: PATHSEG_LINETO_HORIZONTAL_REL_LETTER, x));
0926: }
0927:
0928: /**
0929: * Implements {@link org.apache.batik.parser.PathHandler#linetoHorizontalAbs(float)}.
0930: */
0931: public void linetoHorizontalAbs(float x) throws ParseException {
0932: listHandler.item(new SVGPathSegLinetoHorizontalItem(
0933: SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_ABS,
0934: PATHSEG_LINETO_HORIZONTAL_ABS_LETTER, x));
0935: }
0936:
0937: /**
0938: * Implements {@link org.apache.batik.parser.PathHandler#linetoVerticalRel(float)}.
0939: */
0940: public void linetoVerticalRel(float y) throws ParseException {
0941: listHandler.item(new SVGPathSegLinetoVerticalItem(
0942: SVGPathSeg.PATHSEG_LINETO_VERTICAL_REL,
0943: PATHSEG_LINETO_VERTICAL_REL_LETTER, y));
0944: }
0945:
0946: /**
0947: * Implements {@link org.apache.batik.parser.PathHandler#linetoVerticalAbs(float)}.
0948: */
0949: public void linetoVerticalAbs(float y) throws ParseException {
0950: listHandler.item(new SVGPathSegLinetoVerticalItem(
0951: SVGPathSeg.PATHSEG_LINETO_VERTICAL_ABS,
0952: PATHSEG_LINETO_VERTICAL_ABS_LETTER, y));
0953: }
0954:
0955: /**
0956: * Implements {@link
0957: * org.apache.batik.parser.PathHandler#curvetoCubicRel(float,float,float,float,float,float)}.
0958: */
0959: public void curvetoCubicRel(float x1, float y1, float x2,
0960: float y2, float x, float y) throws ParseException {
0961: listHandler.item(new SVGPathSegCurvetoCubicItem(
0962: SVGPathSeg.PATHSEG_CURVETO_CUBIC_REL,
0963: PATHSEG_CURVETO_CUBIC_REL_LETTER, x1, y1, x2, y2,
0964: x, y));
0965: }
0966:
0967: /**
0968: * Implements {@link
0969: * org.apache.batik.parser.PathHandler#curvetoCubicAbs(float,float,float,float,float,float)}.
0970: */
0971: public void curvetoCubicAbs(float x1, float y1, float x2,
0972: float y2, float x, float y) throws ParseException {
0973: listHandler.item(new SVGPathSegCurvetoCubicItem(
0974: SVGPathSeg.PATHSEG_CURVETO_CUBIC_ABS,
0975: PATHSEG_CURVETO_CUBIC_ABS_LETTER, x1, y1, x2, y2,
0976: x, y));
0977: }
0978:
0979: /**
0980: * Implements {@link
0981: * org.apache.batik.parser.PathHandler#curvetoCubicSmoothRel(float,float,float,float)}.
0982: */
0983: public void curvetoCubicSmoothRel(float x2, float y2, float x,
0984: float y) throws ParseException {
0985: listHandler.item(new SVGPathSegCurvetoCubicSmoothItem(
0986: SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_REL,
0987: PATHSEG_CURVETO_CUBIC_SMOOTH_REL_LETTER, x2, y2, x,
0988: y));
0989: }
0990:
0991: /**
0992: * Implements {@link
0993: * org.apache.batik.parser.PathHandler#curvetoCubicSmoothAbs(float,float,float,float)}.
0994: */
0995: public void curvetoCubicSmoothAbs(float x2, float y2, float x,
0996: float y) throws ParseException {
0997: listHandler.item(new SVGPathSegCurvetoCubicSmoothItem(
0998: SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_ABS,
0999: PATHSEG_CURVETO_CUBIC_SMOOTH_ABS_LETTER, x2, y2, x,
1000: y));
1001: }
1002:
1003: /**
1004: * Implements {@link
1005: * org.apache.batik.parser.PathHandler#curvetoQuadraticRel(float,float,float,float)}.
1006: */
1007: public void curvetoQuadraticRel(float x1, float y1, float x,
1008: float y) throws ParseException {
1009: listHandler
1010: .item(new SVGPathSegCurvetoQuadraticItem(
1011: SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_REL,
1012: PATHSEG_CURVETO_QUADRATIC_REL_LETTER, x1,
1013: y1, x, y));
1014: }
1015:
1016: /**
1017: * Implements {@link
1018: * org.apache.batik.parser.PathHandler#curvetoQuadraticAbs(float,float,float,float)}.
1019: */
1020: public void curvetoQuadraticAbs(float x1, float y1, float x,
1021: float y) throws ParseException {
1022: listHandler
1023: .item(new SVGPathSegCurvetoQuadraticItem(
1024: SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_ABS,
1025: PATHSEG_CURVETO_QUADRATIC_ABS_LETTER, x1,
1026: y1, x, y));
1027: }
1028:
1029: /**
1030: * Implements {@link org.apache.batik.parser.PathHandler#curvetoQuadraticSmoothRel(float,float)}.
1031: */
1032: public void curvetoQuadraticSmoothRel(float x, float y)
1033: throws ParseException {
1034: listHandler.item(new SVGPathSegCurvetoQuadraticSmoothItem(
1035: SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL,
1036: PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL_LETTER, x, y));
1037: }
1038:
1039: /**
1040: * Implements {@link org.apache.batik.parser.PathHandler#curvetoQuadraticSmoothAbs(float,float)}.
1041: */
1042: public void curvetoQuadraticSmoothAbs(float x, float y)
1043: throws ParseException {
1044: listHandler.item(new SVGPathSegCurvetoQuadraticSmoothItem(
1045: SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS,
1046: PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS_LETTER, x, y));
1047: }
1048:
1049: /**
1050: * Implements {@link
1051: * org.apache.batik.parser.PathHandler#arcRel(float,float,float,boolean,boolean,float,float)}.
1052: */
1053: public void arcRel(float rx, float ry, float xAxisRotation,
1054: boolean largeArcFlag, boolean sweepFlag, float x,
1055: float y) throws ParseException {
1056: listHandler.item(new SVGPathSegArcItem(
1057: SVGPathSeg.PATHSEG_ARC_REL, PATHSEG_ARC_REL_LETTER,
1058: rx, ry, xAxisRotation, largeArcFlag, sweepFlag, x,
1059: y));
1060: }
1061:
1062: /**
1063: * Implements {@link
1064: * org.apache.batik.parser.PathHandler#arcAbs(float,float,float,boolean,boolean,float,float)}.
1065: */
1066: public void arcAbs(float rx, float ry, float xAxisRotation,
1067: boolean largeArcFlag, boolean sweepFlag, float x,
1068: float y) throws ParseException {
1069: listHandler.item(new SVGPathSegArcItem(
1070: SVGPathSeg.PATHSEG_ARC_ABS, PATHSEG_ARC_ABS_LETTER,
1071: rx, ry, xAxisRotation, largeArcFlag, sweepFlag, x,
1072: y));
1073: }
1074: }
1075: }
|