001: /*
002: * This file is part of the GeOxygene project source files.
003: *
004: * GeOxygene aims at providing an open framework which implements OGC/ISO specifications for
005: * the development and deployment of geographic (GIS) applications. It is a open source
006: * contribution of the COGIT laboratory at the Institut Géographique National (the French
007: * National Mapping Agency).
008: *
009: * See: http://oxygene-project.sourceforge.net
010: *
011: * Copyright (C) 2005 Institut Géographique National
012: *
013: * This library is free software; you can redistribute it and/or modify it under the terms
014: * of the GNU Lesser General Public License as published by the Free Software Foundation;
015: * either version 2.1 of the License, or any later version.
016: *
017: * This library is distributed in the hope that it will be useful, but WITHOUT ANY
018: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
019: * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
020: *
021: * You should have received a copy of the GNU Lesser General Public License along with
022: * this library (see file LICENSE if present); if not, write to the Free Software
023: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024: *
025: */
026:
027: /* Generated By:JavaCC: Do not edit this line. WktAwt.java */
028: package fr.ign.cogit.geoxygene.util.conversion;
029:
030: import java.awt.geom.Ellipse2D;
031: import java.awt.geom.GeneralPath;
032: import java.awt.geom.Point2D;
033: import java.io.ByteArrayInputStream;
034: import java.io.InputStream;
035: import java.util.StringTokenizer;
036:
037: public class WktAwt implements WktAwtConstants {
038: static class EndOfFile extends Exception {
039: }
040:
041: static class EmptyLine extends Exception {
042: }
043:
044: /*-----------------------------------------------------*/
045: /*- Create AwtShape from Wkt object(s) ----------------*/
046: /*-----------------------------------------------------*/
047:
048: public static AwtShape makeAwtShape(InputStream in)
049: throws ParseException {
050: WktAwt parser = new WktAwt(in);
051: AwtAggregate geom = new AwtAggregate();
052:
053: while (true) {
054: try {
055: geom.add(parser.parseOneLine());
056: } catch (EndOfFile e) {
057: break;
058: } catch (EmptyLine e) {
059: }
060: }
061: return geom;
062: }
063:
064: public static AwtShape makeAwtShape(String wkt)
065: throws ParseException {
066: InputStream in = new ByteArrayInputStream(wkt.getBytes());
067: return makeAwtShape(in);
068: }
069:
070: /*-----------------------------------------------------*/
071: /*- Main function for testing -------------------------*/
072: /*-----------------------------------------------------*/
073:
074: static Ellipse2D makeVisiblePoint(Point2D point) {
075: return new Ellipse2D.Double(point.getX() - 5, point.getY() - 5,
076: 10, 10);
077: }
078:
079: final public Point2D point() throws ParseException {
080: Token xy;
081: xy = jj_consume_token(POINT);
082: StringTokenizer tkz = new StringTokenizer(xy.image);
083: String xStr = tkz.nextToken();
084: String yStr = tkz.nextToken();
085: double x = Double.parseDouble(xStr);
086: double y = Double.parseDouble(yStr);
087: {
088: if (true)
089: return new Point2D.Double(x, y);
090: }
091: throw new Error("Missing return statement in function");
092: }
093:
094: final public Point2D pointText() throws ParseException {
095: Point2D p = new Point2D.Double(Double.NaN, Double.NaN);
096: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
097: case 9:
098: jj_consume_token(9);
099: p = point();
100: jj_consume_token(10);
101: break;
102: case 11:
103: jj_consume_token(11);
104: break;
105: default:
106: jj_la1[0] = jj_gen;
107: jj_consume_token(-1);
108: throw new ParseException();
109: }
110: {
111: if (true)
112: return p;
113: }
114: throw new Error("Missing return statement in function");
115: }
116:
117: final public GeneralPath linestringText() throws ParseException {
118: GeneralPath lineString = new GeneralPath();
119: Point2D p;
120: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
121: case 9:
122: jj_consume_token(9);
123: p = point();
124: lineString.moveTo((float) p.getX(), (float) p.getY());
125: label_1: while (true) {
126: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
127: case 12:
128: ;
129: break;
130: default:
131: jj_la1[1] = jj_gen;
132: break label_1;
133: }
134: jj_consume_token(12);
135: p = point();
136: lineString.lineTo((float) p.getX(), (float) p.getY());
137: }
138: jj_consume_token(10);
139: break;
140: case 11:
141: jj_consume_token(11);
142: break;
143: default:
144: jj_la1[2] = jj_gen;
145: jj_consume_token(-1);
146: throw new ParseException();
147: }
148: {
149: if (true)
150: return lineString;
151: }
152: throw new Error("Missing return statement in function");
153: }
154:
155: final public AwtShape polygonText() throws ParseException {
156: AwtSurface poly = new AwtSurface();
157: GeneralPath lineString;
158: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
159: case 9:
160: jj_consume_token(9);
161: lineString = linestringText();
162: lineString.closePath();
163: poly = new AwtSurface(lineString);
164: label_2: while (true) {
165: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
166: case 12:
167: ;
168: break;
169: default:
170: jj_la1[3] = jj_gen;
171: break label_2;
172: }
173: jj_consume_token(12);
174: lineString = linestringText();
175: lineString.closePath();
176: poly.addInterior(lineString);
177: }
178: jj_consume_token(10);
179: break;
180: case 11:
181: jj_consume_token(11);
182: break;
183: default:
184: jj_la1[4] = jj_gen;
185: jj_consume_token(-1);
186: throw new ParseException();
187: }
188: {
189: if (true)
190: return poly;
191: }
192: throw new Error("Missing return statement in function");
193: }
194:
195: final public AwtShape multipointText() throws ParseException {
196: GeneralPath multi = new GeneralPath();
197: Point2D p;
198: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
199: case 9:
200: jj_consume_token(9);
201: p = point();
202: multi.append(new GeneralPath(makeVisiblePoint(p)), false);
203: label_3: while (true) {
204: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
205: case 12:
206: ;
207: break;
208: default:
209: jj_la1[5] = jj_gen;
210: break label_3;
211: }
212: jj_consume_token(12);
213: p = point();
214: multi.append(new GeneralPath(makeVisiblePoint(p)),
215: false);
216: }
217: jj_consume_token(10);
218: break;
219: case 11:
220: jj_consume_token(11);
221: break;
222: default:
223: jj_la1[6] = jj_gen;
224: jj_consume_token(-1);
225: throw new ParseException();
226: }
227: {
228: if (true)
229: return new AwtSurface(multi);
230: }
231: throw new Error("Missing return statement in function");
232: }
233:
234: final public AwtShape multilinestringText() throws ParseException {
235: GeneralPath multi = new GeneralPath();
236: GeneralPath lineString;
237: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
238: case 9:
239: jj_consume_token(9);
240: lineString = linestringText();
241: multi.append(lineString, false);
242: label_4: while (true) {
243: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
244: case 12:
245: ;
246: break;
247: default:
248: jj_la1[7] = jj_gen;
249: break label_4;
250: }
251: jj_consume_token(12);
252: lineString = linestringText();
253: multi.append(lineString, false);
254: }
255: jj_consume_token(10);
256: break;
257: case 11:
258: jj_consume_token(11);
259: break;
260: default:
261: jj_la1[8] = jj_gen;
262: jj_consume_token(-1);
263: throw new ParseException();
264: }
265: {
266: if (true)
267: return new AwtOutline(multi);
268: }
269: throw new Error("Missing return statement in function");
270: }
271:
272: final public AwtShape multipolygonText() throws ParseException {
273: AwtAggregate multi = new AwtAggregate();
274: AwtShape poly;
275: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
276: case 9:
277: jj_consume_token(9);
278: poly = polygonText();
279: multi.add(poly);
280: label_5: while (true) {
281: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
282: case 12:
283: ;
284: break;
285: default:
286: jj_la1[9] = jj_gen;
287: break label_5;
288: }
289: jj_consume_token(12);
290: poly = polygonText();
291: multi.add(poly);
292: }
293: jj_consume_token(10);
294: break;
295: case 11:
296: jj_consume_token(11);
297: break;
298: default:
299: jj_la1[10] = jj_gen;
300: jj_consume_token(-1);
301: throw new ParseException();
302: }
303: {
304: if (true)
305: return multi;
306: }
307: throw new Error("Missing return statement in function");
308: }
309:
310: final public AwtShape geometrycollectionText()
311: throws ParseException {
312: AwtAggregate collec = new AwtAggregate();
313: AwtShape geom;
314: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
315: case 9:
316: jj_consume_token(9);
317: geom = geometryTaggedText();
318: collec.add(geom);
319: label_6: while (true) {
320: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
321: case 12:
322: ;
323: break;
324: default:
325: jj_la1[11] = jj_gen;
326: break label_6;
327: }
328: jj_consume_token(12);
329: geom = geometryTaggedText();
330: collec.add(geom);
331: }
332: jj_consume_token(10);
333: break;
334: case 11:
335: jj_consume_token(11);
336: break;
337: default:
338: jj_la1[12] = jj_gen;
339: jj_consume_token(-1);
340: throw new ParseException();
341: }
342: {
343: if (true)
344: return collec;
345: }
346: throw new Error("Missing return statement in function");
347: }
348:
349: final public AwtShape pointTaggedText() throws ParseException {
350: Point2D p;
351: jj_consume_token(13);
352: p = pointText();
353: {
354: if (true)
355: return new AwtSurface(makeVisiblePoint(p));
356: }
357: throw new Error("Missing return statement in function");
358: }
359:
360: final public AwtShape linestringTaggedText() throws ParseException {
361: GeneralPath lineString;
362: jj_consume_token(14);
363: lineString = linestringText();
364: {
365: if (true)
366: return new AwtOutline(lineString);
367: }
368: throw new Error("Missing return statement in function");
369: }
370:
371: final public AwtShape multipointTaggedText() throws ParseException {
372: AwtShape multi;
373: jj_consume_token(15);
374: multi = multipointText();
375: {
376: if (true)
377: return multi;
378: }
379: throw new Error("Missing return statement in function");
380: }
381:
382: final public AwtShape multilinestringTaggedText()
383: throws ParseException {
384: AwtShape multi;
385: jj_consume_token(16);
386: multi = multilinestringText();
387: {
388: if (true)
389: return multi;
390: }
391: throw new Error("Missing return statement in function");
392: }
393:
394: final public AwtShape polygonTaggedText() throws ParseException {
395: AwtShape poly;
396: jj_consume_token(17);
397: poly = polygonText();
398: {
399: if (true)
400: return poly;
401: }
402: throw new Error("Missing return statement in function");
403: }
404:
405: final public AwtShape multipolygonTaggedText()
406: throws ParseException {
407: AwtShape multi;
408: jj_consume_token(18);
409: multi = multipolygonText();
410: {
411: if (true)
412: return multi;
413: }
414: throw new Error("Missing return statement in function");
415: }
416:
417: final public AwtShape geometrycollectionTaggedText()
418: throws ParseException {
419: AwtShape collec;
420: jj_consume_token(19);
421: collec = geometrycollectionText();
422: {
423: if (true)
424: return collec;
425: }
426: throw new Error("Missing return statement in function");
427: }
428:
429: final public AwtShape geometryTaggedText() throws ParseException {
430: AwtShape geom;
431: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
432: case 13:
433: geom = pointTaggedText();
434: break;
435: case 14:
436: geom = linestringTaggedText();
437: break;
438: case 17:
439: geom = polygonTaggedText();
440: break;
441: case 15:
442: geom = multipointTaggedText();
443: break;
444: case 16:
445: geom = multilinestringTaggedText();
446: break;
447: case 18:
448: geom = multipolygonTaggedText();
449: break;
450: case 19:
451: geom = geometrycollectionTaggedText();
452: break;
453: default:
454: jj_la1[13] = jj_gen;
455: jj_consume_token(-1);
456: throw new ParseException();
457: }
458: {
459: if (true)
460: return geom;
461: }
462: throw new Error("Missing return statement in function");
463: }
464:
465: final public AwtShape parseOneLine() throws ParseException,
466: EmptyLine, EndOfFile {
467: AwtShape geom;
468: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
469: case 13:
470: case 14:
471: case 15:
472: case 16:
473: case 17:
474: case 18:
475: case 19:
476: geom = geometryTaggedText();
477: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
478: case 0:
479: jj_consume_token(0);
480: break;
481: case EOL:
482: jj_consume_token(EOL);
483: break;
484: default:
485: jj_la1[14] = jj_gen;
486: jj_consume_token(-1);
487: throw new ParseException();
488: }
489: {
490: if (true)
491: return geom;
492: }
493: break;
494: case EOL:
495: jj_consume_token(EOL);
496: {
497: if (true)
498: throw new EmptyLine();
499: }
500: {
501: if (true)
502: return null;
503: }
504: break;
505: case 0:
506: jj_consume_token(0);
507: {
508: if (true)
509: throw new EndOfFile();
510: }
511: {
512: if (true)
513: return null;
514: }
515: break;
516: default:
517: jj_la1[15] = jj_gen;
518: jj_consume_token(-1);
519: throw new ParseException();
520: }
521: throw new Error("Missing return statement in function");
522: }
523:
524: public WktAwtTokenManager token_source;
525: SimpleCharStream jj_input_stream;
526: public Token token, jj_nt;
527: private int jj_ntk;
528: private int jj_gen;
529: final private int[] jj_la1 = new int[16];
530: final private int[] jj_la1_0 = { 0xa00, 0x1000, 0xa00, 0x1000,
531: 0xa00, 0x1000, 0xa00, 0x1000, 0xa00, 0x1000, 0xa00, 0x1000,
532: 0xa00, 0xfe000, 0x41, 0xfe041, };
533:
534: public WktAwt(java.io.InputStream stream) {
535: jj_input_stream = new SimpleCharStream(stream, 1, 1);
536: token_source = new WktAwtTokenManager(jj_input_stream);
537: token = new Token();
538: jj_ntk = -1;
539: jj_gen = 0;
540: for (int i = 0; i < 16; i++)
541: jj_la1[i] = -1;
542: }
543:
544: public void ReInit(java.io.InputStream stream) {
545: jj_input_stream.ReInit(stream, 1, 1);
546: token_source.ReInit(jj_input_stream);
547: token = new Token();
548: jj_ntk = -1;
549: jj_gen = 0;
550: for (int i = 0; i < 16; i++)
551: jj_la1[i] = -1;
552: }
553:
554: public WktAwt(java.io.Reader stream) {
555: jj_input_stream = new SimpleCharStream(stream, 1, 1);
556: token_source = new WktAwtTokenManager(jj_input_stream);
557: token = new Token();
558: jj_ntk = -1;
559: jj_gen = 0;
560: for (int i = 0; i < 16; i++)
561: jj_la1[i] = -1;
562: }
563:
564: public void ReInit(java.io.Reader stream) {
565: jj_input_stream.ReInit(stream, 1, 1);
566: token_source.ReInit(jj_input_stream);
567: token = new Token();
568: jj_ntk = -1;
569: jj_gen = 0;
570: for (int i = 0; i < 16; i++)
571: jj_la1[i] = -1;
572: }
573:
574: public WktAwt(WktAwtTokenManager tm) {
575: token_source = tm;
576: token = new Token();
577: jj_ntk = -1;
578: jj_gen = 0;
579: for (int i = 0; i < 16; i++)
580: jj_la1[i] = -1;
581: }
582:
583: public void ReInit(WktAwtTokenManager tm) {
584: token_source = tm;
585: token = new Token();
586: jj_ntk = -1;
587: jj_gen = 0;
588: for (int i = 0; i < 16; i++)
589: jj_la1[i] = -1;
590: }
591:
592: final private Token jj_consume_token(int kind)
593: throws ParseException {
594: Token oldToken;
595: if ((oldToken = token).next != null)
596: token = token.next;
597: else
598: token = token.next = token_source.getNextToken();
599: jj_ntk = -1;
600: if (token.kind == kind) {
601: jj_gen++;
602: return token;
603: }
604: token = oldToken;
605: jj_kind = kind;
606: throw generateParseException();
607: }
608:
609: final public Token getNextToken() {
610: if (token.next != null)
611: token = token.next;
612: else
613: token = token.next = token_source.getNextToken();
614: jj_ntk = -1;
615: jj_gen++;
616: return token;
617: }
618:
619: final public Token getToken(int index) {
620: Token t = token;
621: for (int i = 0; i < index; i++) {
622: if (t.next != null)
623: t = t.next;
624: else
625: t = t.next = token_source.getNextToken();
626: }
627: return t;
628: }
629:
630: final private int jj_ntk() {
631: if ((jj_nt = token.next) == null)
632: return (jj_ntk = (token.next = token_source.getNextToken()).kind);
633: else
634: return (jj_ntk = jj_nt.kind);
635: }
636:
637: private java.util.Vector jj_expentries = new java.util.Vector();
638: private int[] jj_expentry;
639: private int jj_kind = -1;
640:
641: final public ParseException generateParseException() {
642: jj_expentries.removeAllElements();
643: boolean[] la1tokens = new boolean[20];
644: for (int i = 0; i < 20; i++) {
645: la1tokens[i] = false;
646: }
647: if (jj_kind >= 0) {
648: la1tokens[jj_kind] = true;
649: jj_kind = -1;
650: }
651: for (int i = 0; i < 16; i++) {
652: if (jj_la1[i] == jj_gen) {
653: for (int j = 0; j < 32; j++) {
654: if ((jj_la1_0[i] & (1 << j)) != 0) {
655: la1tokens[j] = true;
656: }
657: }
658: }
659: }
660: for (int i = 0; i < 20; i++) {
661: if (la1tokens[i]) {
662: jj_expentry = new int[1];
663: jj_expentry[0] = i;
664: jj_expentries.addElement(jj_expentry);
665: }
666: }
667: int[][] exptokseq = new int[jj_expentries.size()][];
668: for (int i = 0; i < jj_expentries.size(); i++) {
669: exptokseq[i] = (int[]) jj_expentries.elementAt(i);
670: }
671: return new ParseException(token, exptokseq, tokenImage);
672: }
673:
674: final public void enable_tracing() {
675: }
676:
677: final public void disable_tracing() {
678: }
679:
680: }
|