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.Rectangle;
020: import java.awt.Shape;
021: import java.awt.geom.Point2D;
022: import java.awt.geom.Rectangle2D;
023:
024: import com.vividsolutions.jts.geom.Envelope;
025:
026: /**
027: * An abstract java awt shape that will allow a SimpleGeometry to be drawn using Graphics2D
028: *
029: * @author jeichar
030: * @since 2.1.x
031: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/shapefile-renderer/src/main/java/org/geotools/renderer/shape/AbstractShape.java $
032: */
033: public abstract class AbstractShape implements Shape {
034:
035: protected SimpleGeometry geom;
036:
037: /**
038: * @param geom
039: */
040: public AbstractShape(SimpleGeometry geom) {
041: this .geom = geom;
042: }
043:
044: /* (non-Javadoc)
045: * @see java.awt.Shape#getBounds()
046: */
047: public Rectangle getBounds() {
048: return new Rectangle((int) geom.bbox.getMinX(), (int) geom.bbox
049: .getMinY(), (int) geom.bbox.getWidth(), (int) geom.bbox
050: .getHeight());
051: }
052:
053: /* (non-Javadoc)
054: * @see java.awt.Shape#getBounds2D()
055: */
056: public Rectangle2D getBounds2D() {
057: return new Rectangle2D.Double(geom.bbox.getMinX(), geom.bbox
058: .getMinY(), geom.bbox.getWidth(), geom.bbox.getHeight());
059: }
060:
061: /* (non-Javadoc)
062: * @see java.awt.Shape#contains(double, double)
063: */
064: public boolean contains(double x, double y) {
065: return geom.bbox.contains(x, y);
066: }
067:
068: /* (non-Javadoc)
069: * @see java.awt.Shape#contains(java.awt.geom.Point2D)
070: */
071: public boolean contains(Point2D p) {
072: return geom.bbox.contains(p.getX(), p.getY());
073: }
074:
075: /* (non-Javadoc)
076: * @see java.awt.Shape#intersects(double, double, double, double)
077: */
078: public boolean intersects(double x, double y, double w, double h) {
079: return geom.bbox.intersects(new Envelope(x, x + w, y, y + h));
080: }
081:
082: /* (non-Javadoc)
083: * @see java.awt.Shape#intersects(java.awt.geom.Rectangle2D)
084: */
085: public boolean intersects(Rectangle2D r) {
086: return geom.bbox.intersects(new Envelope(r.getMinX(), r
087: .getMaxX(), r.getMinY(), r.getMaxY()));
088: }
089:
090: /* (non-Javadoc)
091: * @see java.awt.Shape#contains(double, double, double, double)
092: */
093: public boolean contains(double x, double y, double w, double h) {
094: return geom.bbox.contains(new Envelope(x, x + w, y, y + h));
095: }
096:
097: /* (non-Javadoc)
098: * @see java.awt.Shape#contains(java.awt.geom.Rectangle2D)
099: */
100: public boolean contains(Rectangle2D r) {
101: return geom.bbox.contains(new Envelope(r.getMinX(),
102: r.getMaxX(), r.getMinY(), r.getMaxY()));
103: }
104:
105: }
|