KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > parser > PointsParser


1 /*
2
3    Copyright 2000-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.parser;
19
20 import java.io.IOException JavaDoc;
21
22 /**
23  * This class implements an event-based parser for the SVG points
24  * attribute values (used with polyline and polygon elements).
25  *
26  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
27  * @version $Id: PointsParser.java,v 1.9 2004/08/18 07:14:47 vhardy Exp $
28  */

29 public class PointsParser extends NumberParser {
30
31     /**
32      * The points handler used to report parse events.
33      */

34     protected PointsHandler pointsHandler;
35
36     /**
37      * Whether the last character was a 'e' or 'E'.
38      */

39     protected boolean eRead;
40
41     /**
42      * Creates a new PointsParser.
43      */

44     public PointsParser() {
45     pointsHandler = DefaultPointsHandler.INSTANCE;
46     }
47
48     /**
49      * Allows an application to register a points handler.
50      *
51      * <p>If the application does not register a handler, all
52      * events reported by the parser will be silently ignored.
53      *
54      * <p>Applications may register a new or different handler in the
55      * middle of a parse, and the parser must begin using the new
56      * handler immediately.</p>
57      * @param handler The transform list handler.
58      */

59     public void setPointsHandler(PointsHandler handler) {
60     pointsHandler = handler;
61     }
62
63     /**
64      * Returns the points handler in use.
65      */

66     public PointsHandler getPointsHandler() {
67     return pointsHandler;
68     }
69
70     /**
71      * Parses the current stream.
72      */

73     protected void doParse() throws ParseException, IOException JavaDoc {
74         pointsHandler.startPoints();
75
76         current = reader.read();
77         skipSpaces();
78
79         loop: for (;;) {
80             if (current == -1) {
81                 break loop;
82             }
83             float x = parseFloat();
84             skipCommaSpaces();
85             float y = parseFloat();
86             
87             pointsHandler.point(x, y);
88             skipCommaSpaces();
89         }
90
91         pointsHandler.endPoints();
92     }
93 }
94
Popular Tags