001: /*
002: * Geotools2 - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package org.geotools.renderer.shape;
018:
019: import java.awt.Shape;
020: import java.awt.geom.AffineTransform;
021: import java.awt.geom.PathIterator;
022:
023: /**
024: * A shape for drawing on a graphics2d
025: *
026: * @author jeichar
027: *
028: * @since 2.1.x
029: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/shapefile-renderer/src/main/java/org/geotools/renderer/shape/MultiLineShape.java $
030: */
031: public class MultiLineShape extends AbstractShape implements Shape {
032: public MultiLineShape(SimpleGeometry geom) {
033: super (geom);
034: }
035:
036: /*
037: * (non-Javadoc)
038: *
039: * @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform)
040: */
041: public PathIterator getPathIterator(final AffineTransform at) {
042: return new PathIterator() {
043: int currentPart = 0;
044: int currentIndex = 0;
045:
046: public int getWindingRule() {
047: return WIND_NON_ZERO;
048: }
049:
050: public boolean isDone() {
051: // TODO Auto-generated method stub
052: return currentPart == geom.coords.length;
053: }
054:
055: public void next() {
056: if (isDone()) {
057: return;
058: }
059:
060: if ((currentIndex + 1) >= geom.coords[currentPart].length) {
061: currentIndex = 0;
062: currentPart++;
063: } else {
064: currentIndex++;
065: }
066: }
067:
068: public int currentSegment(float[] coords) {
069: if (currentIndex == 0) {
070: coords[0] = (float) geom.coords[currentPart][currentIndex];
071: currentIndex++;
072: coords[1] = (float) geom.coords[currentPart][currentIndex];
073:
074: if (at != null) {
075: at.transform(coords, 0, coords, 0, 1);
076: }
077:
078: return SEG_MOVETO;
079: } else {
080: coords[0] = (float) geom.coords[currentPart][currentIndex];
081: currentIndex++;
082: coords[1] = (float) geom.coords[currentPart][currentIndex];
083:
084: if (at != null) {
085: at.transform(coords, 0, coords, 0, 1);
086: }
087:
088: return SEG_LINETO;
089: }
090: }
091:
092: public int currentSegment(double[] coords) {
093: if (currentIndex == 0) {
094: coords[0] = (float) geom.coords[currentPart][currentIndex];
095: currentIndex++;
096: coords[1] = (float) geom.coords[currentPart][currentIndex];
097:
098: if (at != null) {
099: at.transform(coords, 0, coords, 0, 1);
100: }
101:
102: return SEG_MOVETO;
103: } else {
104: coords[0] = (float) geom.coords[currentPart][currentIndex];
105: currentIndex++;
106: coords[1] = (float) geom.coords[currentPart][currentIndex];
107:
108: if (at != null) {
109: at.transform(coords, 0, coords, 0, 1);
110: }
111:
112: return SEG_LINETO;
113: }
114: }
115: };
116: }
117:
118: /*
119: * (non-Javadoc)
120: *
121: * @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform,
122: * double)
123: */
124: public PathIterator getPathIterator(AffineTransform at,
125: double flatness) {
126: return getPathIterator(at);
127: }
128: }
|