Class GeometryCollectionShape

  1 /*
  2  * Copyright (c) 2016 Vivid Solutions.
  3  *
  4  * All rights reserved. This program and the accompanying materials
  5  * are made available under the terms of the Eclipse Public License 2.0
  6  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
  7  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
  8  * and the Eclipse Distribution License is available at
  9  *
 10  * http://www.eclipse.org/org/documents/edl-v10.php.
 11  */
 12  
 13 package org.locationtech.jts.awt;
 14  
 15 import java.awt.Rectangle;
 16 import java.awt.Shape;
 17 import java.awt.geom.AffineTransform;
 18 import java.awt.geom.PathIterator;
 19 import java.awt.geom.Point2D;
 20 import java.awt.geom.Rectangle2D;
 21 import java.util.ArrayList;
 22 import java.util.Iterator;
 23  
 24 import org.locationtech.jts.geom.Geometry;
 25  
 26 /**
 27  * A {@link Shape} which contains a heterogeneous collection of other shapes
 28  * representing JTS {@link Geometry}s.
 29  * 
 30  * @author Martin Davis
 31  *
 32  */
 33 public class GeometryCollectionShape implements Shape {
 34     private ArrayList shapes = new ArrayList();
 35  
 36     public GeometryCollectionShape() {
 37     }
 38  
 39     public void add(Shape shape) {
 40         shapes.add(shape);
 41     }
 42  
 43     public Rectangle getBounds() {
 44         /**@todo Implement this java.awt.Shape method*/
 45         throw new java.lang.UnsupportedOperationException(
 46             "Method getBounds() not yet implemented.");
 47     }
 48  
 49     public Rectangle2D getBounds2D() {
 50         Rectangle2D rectangle = null;
 51  
 52         for (Iterator i = shapes.iterator(); i.hasNext();) {
 53             Shape shape = (Shape) i.next();
 54  
 55             if (rectangle == null) {
 56                 rectangle = shape.getBounds2D();
 57             } else {
 58                 rectangle.add(shape.getBounds2D());
 59             }
 60         }
 61  
 62         return rectangle;
 63     }
 64  
 65     public boolean contains(double x, double y) {
 66         /**@todo Implement this java.awt.Shape method*/
 67         throw new java.lang.UnsupportedOperationException(
 68             "Method contains() not yet implemented.");
 69     }
 70  
 71     public boolean contains(Point2D p) {
 72         /**@todo Implement this java.awt.Shape method*/
 73         throw new java.lang.UnsupportedOperationException(
 74             "Method contains() not yet implemented.");
 75     }
 76  
 77     public boolean intersects(double x, double y, double w, double h) {
 78         /**@todo Implement this java.awt.Shape method*/
 79         throw new java.lang.UnsupportedOperationException(
 80             "Method intersects() not yet implemented.");
 81     }
 82  
 83     public boolean intersects(Rectangle2D r) {
 84         /**@todo Implement this java.awt.Shape method*/
 85         throw new java.lang.UnsupportedOperationException(
 86             "Method intersects() not yet implemented.");
 87     }
 88  
 89     public boolean contains(double x, double y, double w, double h) {
 90         /**@todo Implement this java.awt.Shape method*/
 91         throw new java.lang.UnsupportedOperationException(
 92             "Method contains() not yet implemented.");
 93     }
 94  
 95     public boolean contains(Rectangle2D r) {
 96         /**@todo Implement this java.awt.Shape method*/
 97         throw new java.lang.UnsupportedOperationException(
 98             "Method contains() not yet implemented.");
 99     }
100  
101     public PathIterator getPathIterator(AffineTransform at) {
102         return new ShapeCollectionPathIterator(shapes, at);
103     }
104  
105     public PathIterator getPathIterator(AffineTransform at, double flatness) {
106         // since Geometry is linear, can simply delegate to the simple method
107         return getPathIterator(at);
108     }
109 }
110