KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Copyright 2003 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.dom.svg;
19
20 import org.apache.batik.parser.DefaultPathHandler;
21 import org.apache.batik.parser.ParseException;
22 import org.apache.batik.parser.PathParser;
23 import org.w3c.dom.DOMException JavaDoc;
24 import org.w3c.dom.svg.SVGException;
25 import org.w3c.dom.svg.SVGPathSeg;
26 import org.w3c.dom.svg.SVGPathSegArcAbs;
27 import org.w3c.dom.svg.SVGPathSegArcRel;
28 import org.w3c.dom.svg.SVGPathSegClosePath;
29 import org.w3c.dom.svg.SVGPathSegCurvetoCubicAbs;
30 import org.w3c.dom.svg.SVGPathSegCurvetoCubicRel;
31 import org.w3c.dom.svg.SVGPathSegCurvetoCubicSmoothAbs;
32 import org.w3c.dom.svg.SVGPathSegCurvetoCubicSmoothRel;
33 import org.w3c.dom.svg.SVGPathSegCurvetoQuadraticAbs;
34 import org.w3c.dom.svg.SVGPathSegCurvetoQuadraticRel;
35 import org.w3c.dom.svg.SVGPathSegCurvetoQuadraticSmoothAbs;
36 import org.w3c.dom.svg.SVGPathSegCurvetoQuadraticSmoothRel;
37 import org.w3c.dom.svg.SVGPathSegLinetoAbs;
38 import org.w3c.dom.svg.SVGPathSegLinetoHorizontalAbs;
39 import org.w3c.dom.svg.SVGPathSegLinetoHorizontalRel;
40 import org.w3c.dom.svg.SVGPathSegLinetoRel;
41 import org.w3c.dom.svg.SVGPathSegLinetoVerticalAbs;
42 import org.w3c.dom.svg.SVGPathSegLinetoVerticalRel;
43 import org.w3c.dom.svg.SVGPathSegList;
44 import org.w3c.dom.svg.SVGPathSegMovetoAbs;
45 import org.w3c.dom.svg.SVGPathSegMovetoRel;
46
47 /**
48  * This class is the implementation of
49  * <code>SVGPathSegList</code>.
50  *
51  * @author nicolas.socheleau@bitflash.com
52  * @version $Id: AbstractSVGPathSegList.java,v 1.7 2004/08/18 07:13:13 vhardy Exp $
53  */

54 public abstract class AbstractSVGPathSegList
55     extends AbstractSVGList
56     implements SVGPathSegList,
57                SVGPathSegConstants {
58
59     /**
60      * Separator for a point list.
61      */

62     public final static String JavaDoc SVG_PATHSEG_LIST_SEPARATOR
63         =" ";
64     /**
65      * Creates a new SVGPathSegList.
66      */

67     protected AbstractSVGPathSegList() {
68         super();
69     }
70
71     /**
72      * Return the separator between segments in the list.
73      */

74     protected String JavaDoc getItemSeparator(){
75         return SVG_PATHSEG_LIST_SEPARATOR;
76     }
77
78     /**
79      * Create an SVGException when the checkItemType fails.
80      *
81      * @return SVGException
82      */

83     protected abstract SVGException createSVGException(short type,
84                                                        String JavaDoc key,
85                                                        Object JavaDoc[] args);
86
87
88     /**
89      */

90     public SVGPathSeg initialize ( SVGPathSeg newItem )
91         throws DOMException JavaDoc, SVGException {
92
93         return (SVGPathSeg)initializeImpl(newItem);
94     }
95
96     /**
97      */

98     public SVGPathSeg getItem ( int index )
99         throws DOMException JavaDoc {
100
101         return (SVGPathSeg)getItemImpl(index);
102     }
103
104     /**
105      */

106     public SVGPathSeg insertItemBefore ( SVGPathSeg newItem, int index )
107         throws DOMException JavaDoc, SVGException {
108
109         return (SVGPathSeg)insertItemBeforeImpl(newItem,index);
110     }
111
112     /**
113      */

114     public SVGPathSeg replaceItem ( SVGPathSeg newItem, int index )
115         throws DOMException JavaDoc, SVGException {
116
117         return (SVGPathSeg)replaceItemImpl(newItem,index);
118     }
119
120     /**
121      */

122     public SVGPathSeg removeItem ( int index )
123         throws DOMException JavaDoc {
124
125         return (SVGPathSeg)removeItemImpl(index);
126     }
127
128     /**
129      */

130     public SVGPathSeg appendItem ( SVGPathSeg newItem )
131         throws DOMException JavaDoc, SVGException {
132
133         return (SVGPathSeg) appendItemImpl(newItem);
134     }
135
136     /**
137      */

138     protected SVGItem createSVGItem(Object JavaDoc newItem){
139         
140         SVGPathSeg pathSeg = (SVGPathSeg)newItem;
141
142         return createPathSegItem(pathSeg);
143     }
144     
145     /**
146      * Parse the 'd' attribute.
147      *
148      * @param value 'd' attribute value
149      * @param handler : list handler
150      */

151     protected void doParse(String JavaDoc value, ListHandler handler)
152         throws ParseException{
153
154         PathParser pathParser = new PathParser();
155         
156         PathSegListBuilder builder = new PathSegListBuilder(handler);
157         
158         pathParser.setPathHandler(builder);
159         pathParser.parse(value);
160         
161     }
162
163     /**
164      * Check if the item is an SVGPathSeg.
165      */

166     protected void checkItemType(Object JavaDoc newItem){
167         if ( !( newItem instanceof SVGPathSeg ) ){
168             createSVGException(SVGException.SVG_WRONG_TYPE_ERR,
169                                "expected SVGPathSeg",
170                                null);
171         }
172     }
173
174     /**
175      * create an SVGItem representing this SVGPathSeg.
176      */

177     protected SVGPathSegItem createPathSegItem(SVGPathSeg pathSeg){
178
179         SVGPathSegItem pathSegItem = null;
180
181         short type = pathSeg.getPathSegType();
182
183         switch(type){
184         case SVGPathSeg.PATHSEG_ARC_ABS:
185         case SVGPathSeg.PATHSEG_ARC_REL:
186             pathSegItem = new SVGPathSegArcItem(pathSeg);
187             break;
188         case SVGPathSeg.PATHSEG_CLOSEPATH:
189             pathSegItem = new SVGPathSegItem(pathSeg);
190             break;
191         case SVGPathSeg.PATHSEG_CURVETO_CUBIC_ABS:
192         case SVGPathSeg.PATHSEG_CURVETO_CUBIC_REL:
193             pathSegItem = new SVGPathSegCurvetoCubicItem(pathSeg);
194             break;
195         case SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_ABS:
196         case SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_REL:
197             pathSegItem = new SVGPathSegCurvetoCubicSmoothItem(pathSeg);
198             break;
199         case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_ABS:
200         case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_REL:
201             pathSegItem = new SVGPathSegCurvetoQuadraticItem(pathSeg);
202             break;
203         case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS:
204         case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL:
205             pathSegItem = new SVGPathSegCurvetoQuadraticSmoothItem(pathSeg);
206             break;
207         case SVGPathSeg.PATHSEG_LINETO_ABS:
208         case SVGPathSeg.PATHSEG_LINETO_REL:
209         case SVGPathSeg.PATHSEG_MOVETO_ABS:
210         case SVGPathSeg.PATHSEG_MOVETO_REL:
211             pathSegItem = new SVGPathSegMovetoLinetoItem(pathSeg);
212             break;
213         case SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_REL:
214         case SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_ABS:
215             pathSegItem = new SVGPathSegLinetoHorizontalItem(pathSeg);
216             break;
217         case SVGPathSeg.PATHSEG_LINETO_VERTICAL_REL:
218         case SVGPathSeg.PATHSEG_LINETO_VERTICAL_ABS:
219             pathSegItem = new SVGPathSegLinetoVerticalItem(pathSeg);
220             break;
221         default:
222         }
223         return pathSegItem;
224     }
225
226     /**
227      * Internal representation of the item SVGPathSeg.
228      */

229     protected class SVGPathSegItem extends AbstractSVGItem
230         implements SVGPathSeg,
231                    SVGPathSegClosePath {
232
233         protected short type;
234
235         protected String JavaDoc letter;
236
237         protected float x;
238         protected float y;
239         protected float x1;
240         protected float y1;
241         protected float x2;
242         protected float y2;
243         protected float r1;
244         protected float r2;
245         protected float angle;
246         protected boolean largeArcFlag;
247         protected boolean sweepFlag;
248
249         protected SVGPathSegItem(){}
250
251         public SVGPathSegItem(short type,String JavaDoc letter){
252             this.type = type;
253             this.letter = letter;
254         }
255
256         public SVGPathSegItem(SVGPathSeg pathSeg){
257             this.type = pathSeg.getPathSegType();
258             switch(type){
259             case SVGPathSeg.PATHSEG_CLOSEPATH:
260                 letter = PATHSEG_CLOSEPATH_LETTER;
261                 break;
262             default:
263             }
264         }
265         protected String JavaDoc getStringValue(){
266             return letter;
267         }
268
269         public short getPathSegType() {
270             return type;
271         }
272           
273         
274         public String JavaDoc getPathSegTypeAsLetter(){
275             return letter;
276         }
277         
278     }
279
280     public class SVGPathSegMovetoLinetoItem extends SVGPathSegItem
281         implements SVGPathSegMovetoAbs,
282                    SVGPathSegMovetoRel,
283                    SVGPathSegLinetoAbs,
284                    SVGPathSegLinetoRel {
285
286         public SVGPathSegMovetoLinetoItem(short type, String JavaDoc letter,
287                                           float x, float y){
288             super(type,letter);
289             this.x = x;
290             this.y = y;
291         }
292
293         public SVGPathSegMovetoLinetoItem(SVGPathSeg pathSeg){
294             this.type = pathSeg.getPathSegType();
295             switch(type){
296             case SVGPathSeg.PATHSEG_LINETO_REL:
297                 letter = PATHSEG_LINETO_REL_LETTER;
298                 x = ((SVGPathSegLinetoRel)pathSeg).getX();
299                 y = ((SVGPathSegLinetoRel)pathSeg).getY();
300                 break;
301             case SVGPathSeg.PATHSEG_LINETO_ABS:
302                 letter = PATHSEG_LINETO_ABS_LETTER;
303                 x = ((SVGPathSegLinetoAbs)pathSeg).getX();
304                 y = ((SVGPathSegLinetoAbs)pathSeg).getY();
305                 break;
306             case SVGPathSeg.PATHSEG_MOVETO_REL:
307                 letter = PATHSEG_MOVETO_REL_LETTER;
308                 x = ((SVGPathSegMovetoRel)pathSeg).getX();
309                 y = ((SVGPathSegMovetoRel)pathSeg).getY();
310                 break;
311             case SVGPathSeg.PATHSEG_MOVETO_ABS:
312                 letter = PATHSEG_MOVETO_ABS_LETTER;
313                 x = ((SVGPathSegMovetoAbs)pathSeg).getX();
314                 y = ((SVGPathSegMovetoAbs)pathSeg).getY();
315                 break;
316             default:
317             }
318         }
319
320         public float getX(){
321             return x;
322         }
323         public float getY(){
324             return y;
325         }
326
327         public void setX(float x){
328             this.x = x;
329             resetAttribute();
330         }
331         public void setY(float y){
332             this.y = y;
333             resetAttribute();
334         }
335
336         protected String JavaDoc getStringValue(){
337             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
338             buf.append(letter);
339             buf.append(' ');
340             buf.append(Float.toString(x));
341             buf.append(' ');
342             buf.append(Float.toString(y));
343             
344             return buf.toString();
345         }
346     }
347     
348     public class SVGPathSegCurvetoCubicItem extends SVGPathSegItem
349         implements SVGPathSegCurvetoCubicAbs,
350                    SVGPathSegCurvetoCubicRel {
351
352         public SVGPathSegCurvetoCubicItem(short type,String JavaDoc letter,
353                                       float x1,float y1,float x2, float y2,
354                                       float x, float y){
355             super(type,letter);
356             this.x = x;
357             this.y = y;
358             this.x1 = x1;
359             this.y1 = y1;
360             this.x2 = x2;
361             this.y2 = y2;
362         }
363
364         public SVGPathSegCurvetoCubicItem(SVGPathSeg pathSeg){
365             this.type = pathSeg.getPathSegType();
366             switch(type){
367             case SVGPathSeg.PATHSEG_CURVETO_CUBIC_ABS:
368                 letter = PATHSEG_CURVETO_CUBIC_ABS_LETTER;
369                 x = ((SVGPathSegCurvetoCubicAbs)pathSeg).getX();
370                 y = ((SVGPathSegCurvetoCubicAbs)pathSeg).getY();
371                 x1 = ((SVGPathSegCurvetoCubicAbs)pathSeg).getX1();
372                 y1 = ((SVGPathSegCurvetoCubicAbs)pathSeg).getY1();
373                 x2 = ((SVGPathSegCurvetoCubicAbs)pathSeg).getX2();
374                 y2 = ((SVGPathSegCurvetoCubicAbs)pathSeg).getY2();
375                 break;
376             case SVGPathSeg.PATHSEG_CURVETO_CUBIC_REL:
377                 letter = PATHSEG_CURVETO_CUBIC_REL_LETTER;
378                 x = ((SVGPathSegCurvetoCubicRel)pathSeg).getX();
379                 y = ((SVGPathSegCurvetoCubicRel)pathSeg).getY();
380                 x1 = ((SVGPathSegCurvetoCubicRel)pathSeg).getX1();
381                 y1 = ((SVGPathSegCurvetoCubicRel)pathSeg).getY1();
382                 x2 = ((SVGPathSegCurvetoCubicRel)pathSeg).getX2();
383                 y2 = ((SVGPathSegCurvetoCubicRel)pathSeg).getY2();
384                 break;
385             default:
386             }
387         }
388
389         public float getX(){
390             return x;
391         }
392         public float getY(){
393             return y;
394         }
395
396         public void setX(float x){
397             this.x = x;
398             resetAttribute();
399         }
400         public void setY(float y){
401             this.y = y;
402             resetAttribute();
403         }
404
405         public float getX1(){
406             return x1;
407         }
408         public float getY1(){
409             return y1;
410         }
411
412         public void setX1(float x1){
413             this.x1 = x1;
414             resetAttribute();
415         }
416         public void setY1(float y1){
417             this.y1 = y1;
418             resetAttribute();
419         }
420
421         public float getX2(){
422             return x2;
423         }
424         public float getY2(){
425             return y2;
426         }
427
428         public void setX2(float x2){
429             this.x2 = x2;
430             resetAttribute();
431         }
432         public void setY2(float y2){
433             this.y2 = y2;
434             resetAttribute();
435         }
436
437         protected String JavaDoc getStringValue(){
438             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
439             buf.append(letter);
440             buf.append(' ');
441             buf.append(Float.toString(x1));
442             buf.append(' ');
443             buf.append(Float.toString(y1));
444             buf.append(' ');
445             buf.append(Float.toString(x2));
446             buf.append(' ');
447             buf.append(Float.toString(y2));
448             buf.append(' ');
449             buf.append(Float.toString(x));
450             buf.append(' ');
451             buf.append(Float.toString(y));
452
453             return buf.toString();
454         }
455     }
456
457     public class SVGPathSegCurvetoQuadraticItem extends SVGPathSegItem
458         implements SVGPathSegCurvetoQuadraticAbs,
459                    SVGPathSegCurvetoQuadraticRel {
460
461         public SVGPathSegCurvetoQuadraticItem(short type,String JavaDoc letter,
462                                           float x1,float y1,float x, float y ){
463             super(type,letter);
464             this.x = x;
465             this.y = y;
466             this.x1 = x1;
467             this.y1 = y1;
468         }
469
470         public SVGPathSegCurvetoQuadraticItem(SVGPathSeg pathSeg){
471             this.type = pathSeg.getPathSegType();
472             switch(type){
473             case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_ABS:
474                 letter = PATHSEG_CURVETO_QUADRATIC_ABS_LETTER;
475                 x = ((SVGPathSegCurvetoQuadraticAbs)pathSeg).getX();
476                 y = ((SVGPathSegCurvetoQuadraticAbs)pathSeg).getY();
477                 x1 = ((SVGPathSegCurvetoQuadraticAbs)pathSeg).getX1();
478                 y1= ((SVGPathSegCurvetoQuadraticAbs)pathSeg).getY1();
479                 break;
480             case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_REL:
481                 letter = PATHSEG_CURVETO_QUADRATIC_REL_LETTER;
482                 x = ((SVGPathSegCurvetoQuadraticRel)pathSeg).getX();
483                 y = ((SVGPathSegCurvetoQuadraticRel)pathSeg).getY();
484                 x1 = ((SVGPathSegCurvetoQuadraticRel)pathSeg).getX1();
485                 y1= ((SVGPathSegCurvetoQuadraticRel)pathSeg).getY1();
486                 break;
487         default:
488  
489             }
490         }
491
492         public float getX(){
493             return x;
494         }
495         public float getY(){
496             return y;
497         }
498
499         public void setX(float x){
500             this.x = x;
501             resetAttribute();
502         }
503         public void setY(float y){
504             this.y = y;
505             resetAttribute();
506         }
507
508         public float getX1(){
509             return x1;
510         }
511         public float getY1(){
512             return y1;
513         }
514
515         public void setX1(float x1){
516             this.x1 = x1;
517             resetAttribute();
518         }
519         public void setY1(float y1){
520             this.y1 = y1;
521             resetAttribute();
522         }
523
524         protected String JavaDoc getStringValue(){
525             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
526             buf.append(letter);
527             buf.append(' ');
528             buf.append(Float.toString(x1));
529             buf.append(' ');
530             buf.append(Float.toString(y1));
531             buf.append(' ');
532             buf.append(Float.toString(x));
533             buf.append(' ');
534             buf.append(Float.toString(y));
535             
536             return buf.toString();
537         }
538     }
539
540     public class SVGPathSegArcItem extends SVGPathSegItem
541         implements SVGPathSegArcAbs,
542                    SVGPathSegArcRel {
543
544         public SVGPathSegArcItem(short type,String JavaDoc letter,
545                              float r1,float r2,float angle,
546                              boolean largeArcFlag, boolean sweepFlag,
547                              float x, float y ){
548             super(type,letter);
549             this.x = x;
550             this.y = y;
551             this.r1 = r1;
552             this.r2 = r2;
553             this.angle = angle;
554             this.largeArcFlag = largeArcFlag;
555             this.sweepFlag = sweepFlag;
556         }
557         
558         public SVGPathSegArcItem(SVGPathSeg pathSeg){
559             this.type = pathSeg.getPathSegType();
560             switch(type){
561             case SVGPathSeg.PATHSEG_ARC_ABS:
562                 letter = PATHSEG_ARC_ABS_LETTER;
563                 x = ((SVGPathSegArcAbs)pathSeg).getX();
564                 y = ((SVGPathSegArcAbs)pathSeg).getY();
565                 r1 = ((SVGPathSegArcAbs)pathSeg).getR1();
566                 r2 = ((SVGPathSegArcAbs)pathSeg).getR2();
567                 angle = ((SVGPathSegArcAbs)pathSeg).getAngle();
568                 largeArcFlag = ((SVGPathSegArcAbs)pathSeg).getLargeArcFlag();
569                 sweepFlag = ((SVGPathSegArcAbs)pathSeg).getSweepFlag();
570                 break;
571             case SVGPathSeg.PATHSEG_ARC_REL:
572                 letter = PATHSEG_ARC_REL_LETTER;
573                 x = ((SVGPathSegArcRel)pathSeg).getX();
574                 y = ((SVGPathSegArcRel)pathSeg).getY();
575                 r1 = ((SVGPathSegArcRel)pathSeg).getR1();
576                 r2 = ((SVGPathSegArcRel)pathSeg).getR2();
577                 angle = ((SVGPathSegArcRel)pathSeg).getAngle();
578                 largeArcFlag = ((SVGPathSegArcRel)pathSeg).getLargeArcFlag();
579                 sweepFlag = ((SVGPathSegArcRel)pathSeg).getSweepFlag();
580                 break;
581             default:
582             }
583         }
584
585         public float getX(){
586             return x;
587         }
588         public float getY(){
589             return y;
590         }
591
592         public void setX(float x){
593             this.x = x;
594             resetAttribute();
595         }
596         public void setY(float y){
597             this.y = y;
598             resetAttribute();
599         }
600
601         public float getR1(){
602             return r1;
603         }
604         public float getR2(){
605             return r2;
606         }
607
608         public void setR1(float r1){
609             this.r1 = r1;
610             resetAttribute();
611         }
612         public void setR2(float r2){
613             this.r2 = r2;
614             resetAttribute();
615         }
616
617         public float getAngle(){
618             return angle;
619         }
620
621         public void setAngle(float angle){
622             this.angle = angle;
623             resetAttribute();
624         }
625
626         public boolean getSweepFlag(){
627             return sweepFlag;
628         }
629
630         public void setSweepFlag(boolean sweepFlag){
631             this.sweepFlag = sweepFlag;
632             resetAttribute();
633         }
634
635         public boolean getLargeArcFlag(){
636             return largeArcFlag;
637         }
638
639         public void setLargeArcFlag(boolean largeArcFlag){
640             this.largeArcFlag = largeArcFlag;
641             resetAttribute();
642         }
643
644         protected String JavaDoc getStringValue(){
645             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
646             buf.append(letter);
647             buf.append(' ');
648             buf.append(Float.toString(r1));
649             buf.append(' ');
650             buf.append(Float.toString(r2));
651             buf.append(' ');
652             buf.append(Float.toString(angle));
653             buf.append(' ');
654             buf.append((largeArcFlag?"1":"0"));
655             buf.append(' ');
656             buf.append((sweepFlag?"1":"0"));
657             buf.append(' ');
658             buf.append(Float.toString(x));
659             buf.append(' ');
660             buf.append(Float.toString(y));
661             
662             return buf.toString();
663         }
664     }
665
666     public class SVGPathSegLinetoHorizontalItem
667         extends SVGPathSegItem
668         implements SVGPathSegLinetoHorizontalAbs,
669                    SVGPathSegLinetoHorizontalRel {
670
671         public SVGPathSegLinetoHorizontalItem(short type, String JavaDoc letter,
672                                               float value){
673             super(type,letter);
674             this.x = value;
675         }
676         public SVGPathSegLinetoHorizontalItem(SVGPathSeg pathSeg){
677             this.type = pathSeg.getPathSegType();
678             switch(type){
679             case SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_ABS:
680                 letter = PATHSEG_LINETO_HORIZONTAL_ABS_LETTER;
681                 x = ((SVGPathSegLinetoHorizontalAbs)pathSeg).getX();
682                 break;
683             case SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_REL:
684                 letter = PATHSEG_LINETO_HORIZONTAL_REL_LETTER;
685                 x = ((SVGPathSegLinetoHorizontalRel)pathSeg).getX();
686                 break;
687             default:
688             }
689         }
690
691         public float getX(){
692             return x;
693         }
694
695         public void setX(float x){
696             this.x = x;
697             resetAttribute();
698         }
699
700         protected String JavaDoc getStringValue(){
701             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
702             buf.append(letter);
703             buf.append(' ');
704             buf.append(Float.toString(x));
705
706             return buf.toString();
707         }
708     }
709
710     public class SVGPathSegLinetoVerticalItem
711         extends SVGPathSegItem
712     implements SVGPathSegLinetoVerticalAbs,
713                SVGPathSegLinetoVerticalRel {
714
715         public SVGPathSegLinetoVerticalItem(short type, String JavaDoc letter,
716                                           float value){
717             super(type,letter);
718             this.y = value;
719         }
720         
721         public SVGPathSegLinetoVerticalItem(SVGPathSeg pathSeg){
722             this.type = pathSeg.getPathSegType();
723             switch(type){
724             case SVGPathSeg.PATHSEG_LINETO_VERTICAL_ABS:
725                 letter = PATHSEG_LINETO_VERTICAL_ABS_LETTER;
726                 y = ((SVGPathSegLinetoVerticalAbs)pathSeg).getY();
727                 break;
728             case SVGPathSeg.PATHSEG_LINETO_VERTICAL_REL:
729                 letter = PATHSEG_LINETO_VERTICAL_REL_LETTER;
730                 y = ((SVGPathSegLinetoVerticalRel)pathSeg).getY();
731                 break;
732             default:
733             }
734         }
735
736         public float getY(){
737             return y;
738         }
739
740         public void setY(float y){
741             this.y = y;
742             resetAttribute();
743         }
744
745         protected String JavaDoc getStringValue(){
746             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
747             buf.append(letter);
748             buf.append(' ');
749             buf.append(Float.toString(y));
750
751             return buf.toString();
752         }
753     }
754
755     public class SVGPathSegCurvetoCubicSmoothItem extends SVGPathSegItem
756         implements SVGPathSegCurvetoCubicSmoothAbs,
757                    SVGPathSegCurvetoCubicSmoothRel {
758
759         public SVGPathSegCurvetoCubicSmoothItem(short type,String JavaDoc letter,
760                                           float x2,float y2,float x, float y ){
761             super(type,letter);
762             this.x = x;
763             this.y = y;
764             this.x2 = x2;
765             this.y2 = y2;
766         }
767
768         public SVGPathSegCurvetoCubicSmoothItem(SVGPathSeg pathSeg){
769             this.type = pathSeg.getPathSegType();
770             switch(type){
771             case SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_ABS:
772                 letter = PATHSEG_CURVETO_CUBIC_SMOOTH_ABS_LETTER;
773                 x = ((SVGPathSegCurvetoCubicSmoothAbs)pathSeg).getX();
774                 y = ((SVGPathSegCurvetoCubicSmoothAbs)pathSeg).getY();
775                 x2 = ((SVGPathSegCurvetoCubicSmoothAbs)pathSeg).getX2();
776                 y2 = ((SVGPathSegCurvetoCubicSmoothAbs)pathSeg).getY2();
777                 break;
778             case SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_REL:
779                 letter = PATHSEG_CURVETO_CUBIC_SMOOTH_REL_LETTER;
780                 x = ((SVGPathSegCurvetoCubicSmoothRel)pathSeg).getX();
781                 y = ((SVGPathSegCurvetoCubicSmoothRel)pathSeg).getY();
782                 x2 = ((SVGPathSegCurvetoCubicSmoothRel)pathSeg).getX2();
783                 y2 = ((SVGPathSegCurvetoCubicSmoothRel)pathSeg).getY2();
784                 break;
785             default:
786             }
787         }
788
789         public float getX(){
790             return x;
791         }
792         public float getY(){
793             return y;
794         }
795
796         public void setX(float x){
797             this.x = x;
798             resetAttribute();
799         }
800         public void setY(float y){
801             this.y = y;
802             resetAttribute();
803         }
804
805         public float getX2(){
806             return x2;
807         }
808         public float getY2(){
809             return y2;
810         }
811
812         public void setX2(float x2){
813             this.x2 = x2;
814             resetAttribute();
815         }
816         public void setY2(float y2){
817             this.y2 = y2;
818             resetAttribute();
819         }
820
821         protected String JavaDoc getStringValue(){
822             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
823             buf.append(letter);
824             buf.append(' ');
825             buf.append(Float.toString(x2));
826             buf.append(' ');
827             buf.append(Float.toString(y2));
828             buf.append(' ');
829             buf.append(Float.toString(x));
830             buf.append(' ');
831             buf.append(Float.toString(y));
832             
833             return buf.toString();
834         }
835     }
836
837     public class SVGPathSegCurvetoQuadraticSmoothItem extends SVGPathSegItem
838         implements SVGPathSegCurvetoQuadraticSmoothAbs ,
839                    SVGPathSegCurvetoQuadraticSmoothRel {
840
841         public SVGPathSegCurvetoQuadraticSmoothItem(short type, String JavaDoc letter,
842                                                 float x, float y){
843             super(type,letter);
844             this.x = x;
845             this.y = y;
846         }
847
848         public SVGPathSegCurvetoQuadraticSmoothItem(SVGPathSeg pathSeg){
849             this.type = pathSeg.getPathSegType();
850             switch(type){
851             case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS:
852                 letter = PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS_LETTER;
853                 x = ((SVGPathSegCurvetoQuadraticSmoothAbs)pathSeg).getX();
854                 y = ((SVGPathSegCurvetoQuadraticSmoothAbs)pathSeg).getY();
855                 break;
856             case SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL:
857                 letter = PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL_LETTER;
858                 x = ((SVGPathSegCurvetoQuadraticSmoothRel)pathSeg).getX();
859                 y = ((SVGPathSegCurvetoQuadraticSmoothRel)pathSeg).getY();
860                 break;
861             default:
862             }
863         }
864
865         public float getX(){
866             return x;
867         }
868         public float getY(){
869             return y;
870         }
871
872         public void setX(float x){
873             this.x = x;
874             resetAttribute();
875         }
876         public void setY(float y){
877             this.y = y;
878             resetAttribute();
879         }
880
881         protected String JavaDoc getStringValue(){
882             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
883             buf.append(letter);
884             buf.append(' ');
885             buf.append(Float.toString(x));
886             buf.append(' ');
887             buf.append(Float.toString(y));
888             
889             return buf.toString();
890         }
891     }
892
893     protected class PathSegListBuilder extends DefaultPathHandler {
894
895         protected ListHandler listHandler;
896
897         public PathSegListBuilder(ListHandler listHandler){
898             this.listHandler = listHandler;
899         }
900         /**
901          * Implements {@link org.apache.batik.parser.PathHandler#startPath()}.
902          */

903         public void startPath() throws ParseException {
904             listHandler.startList();
905         }
906
907         /**
908          * Implements {@link org.apache.batik.parser.PathHandler#endPath()}.
909          */

910         public void endPath() throws ParseException {
911             listHandler.endList();
912         }
913         
914         /**
915          * Implements {@link org.apache.batik.parser.PathHandler#movetoRel(float,float)}.
916          */

917         public void movetoRel(float x, float y) throws ParseException {
918             listHandler.item(new SVGPathSegMovetoLinetoItem
919                 (SVGPathSeg.PATHSEG_MOVETO_REL,PATHSEG_MOVETO_REL_LETTER,
920                  x,y));
921         }
922
923         /**
924          * Implements {@link org.apache.batik.parser.PathHandler#movetoAbs(float,float)}.
925          */

926         public void movetoAbs(float x, float y) throws ParseException {
927             listHandler.item(new SVGPathSegMovetoLinetoItem
928                 (SVGPathSeg.PATHSEG_MOVETO_ABS,PATHSEG_MOVETO_ABS_LETTER,
929                  x,y));
930         }
931
932         /**
933          * Implements {@link org.apache.batik.parser.PathHandler#closePath()}.
934          */

935         public void closePath() throws ParseException {
936             listHandler.item(new SVGPathSegItem
937                 (SVGPathSeg.PATHSEG_CLOSEPATH,PATHSEG_CLOSEPATH_LETTER));
938             
939         }
940
941         /**
942          * Implements {@link org.apache.batik.parser.PathHandler#linetoRel(float,float)}.
943          */

944         public void linetoRel(float x, float y) throws ParseException {
945             listHandler.item(new SVGPathSegMovetoLinetoItem
946                 (SVGPathSeg.PATHSEG_LINETO_REL,PATHSEG_LINETO_REL_LETTER,
947                  x,y));
948         }
949
950         /**
951          * Implements {@link org.apache.batik.parser.PathHandler#linetoAbs(float,float)}.
952          */

953         public void linetoAbs(float x, float y) throws ParseException {
954             listHandler.item(new SVGPathSegMovetoLinetoItem
955                 (SVGPathSeg.PATHSEG_LINETO_ABS,PATHSEG_LINETO_ABS_LETTER,
956                  x,y));
957         }
958
959         /**
960          * Implements {@link org.apache.batik.parser.PathHandler#linetoHorizontalRel(float)}.
961          */

962         public void linetoHorizontalRel(float x) throws ParseException {
963             listHandler.item(new SVGPathSegLinetoHorizontalItem
964                 (SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_REL,PATHSEG_LINETO_HORIZONTAL_REL_LETTER,
965                  x));
966         }
967
968         /**
969          * Implements {@link org.apache.batik.parser.PathHandler#linetoHorizontalAbs(float)}.
970          */

971         public void linetoHorizontalAbs(float x) throws ParseException {
972             listHandler.item(new SVGPathSegLinetoHorizontalItem
973                 (SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_ABS,PATHSEG_LINETO_HORIZONTAL_ABS_LETTER,
974                  x));
975         }
976
977         /**
978          * Implements {@link org.apache.batik.parser.PathHandler#linetoVerticalRel(float)}.
979          */

980         public void linetoVerticalRel(float y) throws ParseException {
981             listHandler.item(new SVGPathSegLinetoVerticalItem
982                 (SVGPathSeg.PATHSEG_LINETO_VERTICAL_REL,PATHSEG_LINETO_VERTICAL_REL_LETTER,
983                  y));
984         }
985
986         /**
987          * Implements {@link org.apache.batik.parser.PathHandler#linetoVerticalAbs(float)}.
988          */

989         public void linetoVerticalAbs(float y) throws ParseException {
990             listHandler.item(new SVGPathSegLinetoVerticalItem
991                 (SVGPathSeg.PATHSEG_LINETO_VERTICAL_ABS,PATHSEG_LINETO_VERTICAL_ABS_LETTER,
992                  y));
993         }
994
995         /**
996          * Implements {@link
997          * org.apache.batik.parser.PathHandler#curvetoCubicRel(float,float,float,float,float,float)}.
998          */

999         public void curvetoCubicRel(float x1, float y1,
1000                                    float x2, float y2,
1001                                    float x, float y) throws ParseException {
1002            listHandler.item(new SVGPathSegCurvetoCubicItem
1003                (SVGPathSeg.PATHSEG_CURVETO_CUBIC_REL,PATHSEG_CURVETO_CUBIC_REL_LETTER,
1004                 x1,y1,x2,y2,x,y));
1005        }
1006
1007        /**
1008         * Implements {@link
1009         * org.apache.batik.parser.PathHandler#curvetoCubicAbs(float,float,float,float,float,float)}.
1010         */

1011        public void curvetoCubicAbs(float x1, float y1,
1012                                    float x2, float y2,
1013                                    float x, float y) throws ParseException {
1014            listHandler.item(new SVGPathSegCurvetoCubicItem
1015                (SVGPathSeg.PATHSEG_CURVETO_CUBIC_ABS,PATHSEG_CURVETO_CUBIC_ABS_LETTER,
1016                 x1,y1,x2,y2,x,y));
1017        }
1018
1019        /**
1020         * Implements {@link
1021         * org.apache.batik.parser.PathHandler#curvetoCubicSmoothRel(float,float,float,float)}.
1022         */

1023        public void curvetoCubicSmoothRel(float x2, float y2,
1024                                          float x, float y) throws ParseException {
1025            listHandler.item(new SVGPathSegCurvetoCubicSmoothItem
1026                (SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_REL,PATHSEG_CURVETO_CUBIC_SMOOTH_REL_LETTER,
1027                 x2,y2,x,y));
1028        }
1029
1030        /**
1031         * Implements {@link
1032         * org.apache.batik.parser.PathHandler#curvetoCubicSmoothAbs(float,float,float,float)}.
1033         */

1034        public void curvetoCubicSmoothAbs(float x2, float y2,
1035                                          float x, float y) throws ParseException {
1036            listHandler.item(new SVGPathSegCurvetoCubicSmoothItem
1037                (SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_ABS,PATHSEG_CURVETO_CUBIC_SMOOTH_ABS_LETTER,
1038                 x2,y2,x,y));
1039        }
1040
1041        /**
1042         * Implements {@link
1043         * org.apache.batik.parser.PathHandler#curvetoQuadraticRel(float,float,float,float)}.
1044         */

1045        public void curvetoQuadraticRel(float x1, float y1,
1046                                        float x, float y) throws ParseException {
1047            listHandler.item(new SVGPathSegCurvetoQuadraticItem
1048                (SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_REL,PATHSEG_CURVETO_QUADRATIC_REL_LETTER,
1049                 x1,y1,x,y));
1050        }
1051
1052        /**
1053         * Implements {@link
1054         * org.apache.batik.parser.PathHandler#curvetoQuadraticAbs(float,float,float,float)}.
1055         */

1056        public void curvetoQuadraticAbs(float x1, float y1,
1057                                        float x, float y) throws ParseException {
1058            listHandler.item(new SVGPathSegCurvetoQuadraticItem
1059                (SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_ABS,PATHSEG_CURVETO_QUADRATIC_ABS_LETTER,
1060                 x1,y1,x,y));
1061        }
1062
1063        /**
1064         * Implements {@link org.apache.batik.parser.PathHandler#curvetoQuadraticSmoothRel(float,float)}.
1065         */

1066        public void curvetoQuadraticSmoothRel(float x, float y)
1067            throws ParseException {
1068            listHandler.item(new SVGPathSegCurvetoQuadraticSmoothItem
1069                (SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL,PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL_LETTER,
1070                 x,y));
1071        }
1072
1073        /**
1074         * Implements {@link org.apache.batik.parser.PathHandler#curvetoQuadraticSmoothAbs(float,float)}.
1075         */

1076        public void curvetoQuadraticSmoothAbs(float x, float y)
1077            throws ParseException {
1078            listHandler.item(new SVGPathSegCurvetoQuadraticSmoothItem
1079                (SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS,PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS_LETTER,
1080                 x,y));
1081        }
1082
1083        /**
1084         * Implements {@link
1085         * org.apache.batik.parser.PathHandler#arcRel(float,float,float,boolean,boolean,float,float)}.
1086         */

1087        public void arcRel(float rx, float ry,
1088                           float xAxisRotation,
1089                           boolean largeArcFlag, boolean sweepFlag,
1090                           float x, float y) throws ParseException {
1091            listHandler.item(new SVGPathSegArcItem
1092                (SVGPathSeg.PATHSEG_ARC_REL,PATHSEG_ARC_REL_LETTER,
1093                 rx,ry,xAxisRotation,largeArcFlag,sweepFlag,x,y));
1094        }
1095        
1096        /**
1097         * Implements {@link
1098         * org.apache.batik.parser.PathHandler#arcAbs(float,float,float,boolean,boolean,float,float)}.
1099         */

1100        public void arcAbs(float rx, float ry,
1101                           float xAxisRotation,
1102                           boolean largeArcFlag, boolean sweepFlag,
1103                           float x, float y) throws ParseException {
1104            listHandler.item(new SVGPathSegArcItem
1105                (SVGPathSeg.PATHSEG_ARC_ABS,PATHSEG_ARC_ABS_LETTER,
1106                 rx,ry,xAxisRotation,largeArcFlag,sweepFlag,x,y));
1107        }
1108    }
1109}
1110
Popular Tags