001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032:
033: package com.vividsolutions.jump.workbench.ui.renderer.java2D;
034:
035: import java.awt.Shape;
036: import java.awt.geom.AffineTransform;
037: import java.awt.geom.PathIterator;
038: import java.util.Collection;
039: import java.util.Iterator;
040:
041: public class ShapeCollectionPathIterator implements PathIterator {
042: private Iterator shapeIterator;
043: private PathIterator currentPathIterator = new PathIterator() {
044: public int getWindingRule() {
045: throw new UnsupportedOperationException();
046: }
047:
048: public boolean isDone() {
049: return true;
050: }
051:
052: public void next() {
053: }
054:
055: public int currentSegment(float[] coords) {
056: throw new UnsupportedOperationException();
057: }
058:
059: public int currentSegment(double[] coords) {
060: throw new UnsupportedOperationException();
061: }
062: };
063:
064: private AffineTransform affineTransform;
065: private boolean done = false;
066:
067: public ShapeCollectionPathIterator(Collection shapes,
068: AffineTransform affineTransform) {
069: shapeIterator = shapes.iterator();
070: this .affineTransform = affineTransform;
071: next();
072: }
073:
074: public int getWindingRule() {
075: //WIND_NON_ZERO is more accurate than WIND_EVEN_ODD, and can be comparable
076: //in speed. (See http://www.geometryalgorithms.com/Archive/algorithm_0103/algorithm_0103.htm#Winding%20Number)
077: //[Jon Aquino]
078: //Nah, switch back to WIND_EVEN_ODD -- WIND_NON_ZERO requires that the
079: //shell and holes be oriented in a certain way. [Jon Aquino]
080: return PathIterator.WIND_EVEN_ODD;
081: }
082:
083: public boolean isDone() {
084: return done;
085: }
086:
087: public void next() {
088: currentPathIterator.next();
089:
090: if (currentPathIterator.isDone() && !shapeIterator.hasNext()) {
091: done = true;
092:
093: return;
094: }
095:
096: if (currentPathIterator.isDone()) {
097: currentPathIterator = ((Shape) shapeIterator.next())
098: .getPathIterator(affineTransform);
099: }
100: }
101:
102: public int currentSegment(float[] coords) {
103: return currentPathIterator.currentSegment(coords);
104: }
105:
106: public int currentSegment(double[] coords) {
107: return currentPathIterator.currentSegment(coords);
108: }
109: }
|