fcmodeler.view.figures
Class LineShape

java.lang.Object
  |
  +--fcmodeler.view.figures.LineShape
All Implemented Interfaces:
java.awt.Shape

public class LineShape
extends java.lang.Object
implements java.awt.Shape

A Shape implementation that contains methods appropriate for lines. LineShape wraps another Shape object, and provides contains and intersects methods appropriate for arbitrary line shapes. These methods break up the line into straight pieces before testing. This is in contrast to the approach most other Shape implementations take, which assume that the shape is an enclosed region.

The wrapped Shape object provides the geometry of the line. LineShape simply intercepts method calls to the wrapped Shape. Clients will typically setup the Shape object, then provide it to LineShape and use the LineShape instance in place of the original Shape.

Since:
JDK1.3
Version:
$Revision: 1.2 $
Author:
Julie Dickerson , Zach Cox

Constructor Summary
LineShape(java.awt.Shape shape)
          Creates a new LineShape using the specified Shape.
LineShape(java.awt.Shape shape, float margin, double flatness)
          Creates a new LineShape using the specified Shape, margin, and flatness.
 
Method Summary
 boolean contains(double x, double y)
          Tests if the specified point is within the margin of this line.
 boolean contains(double x, double y, double w, double h)
          Tests if the specified rectangle intersects this LineShape.
 boolean contains(java.awt.geom.Point2D point)
          Tests if the specified point is within the margin of this line.
 boolean contains(java.awt.geom.Rectangle2D rectangle)
          Tests if the specified rectangle intersects this LineShape.
 java.awt.Rectangle getBounds()
          Returns an integer Rectangle that completely encloses the Shape.
 java.awt.geom.Rectangle2D getBounds2D()
          Returns a high precision and more accurate bounding box of the Shape than the getBounds method.
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform transform)
          Returns an iterator object that iterates along the Shape boundary and provides access to the geometry of the Shape outline.
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform transform, double flatness)
          Returns an iterator object that iterates along the Shape boundary and provides access to a flattened view of the Shape outline geometry.
 boolean intersects(double x, double y, double w, double h)
          Tests if this LineShape intersects the specified rectangle.
 boolean intersects(java.awt.geom.Rectangle2D rectangle)
          Tests if this LineShape intersects the specified rectangle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LineShape

public LineShape(java.awt.Shape shape)
Creates a new LineShape using the specified Shape. The margin is set to 5.0f and the flatness is set to 12.0d.
Parameters:
shape - the Shape providing the geomoetry for this LineShape.

LineShape

public LineShape(java.awt.Shape shape,
                 float margin,
                 double flatness)
Creates a new LineShape using the specified Shape, margin, and flatness.
Parameters:
shape - the Shape providing the geometry for this LineShape.
margin - the maximum distance away from this LineShape for point containment.
flatness - the flatness parameter provided to all getPathIterator(AffineTransform, double) calls.
Method Detail

contains

public boolean contains(double x,
                        double y)
Tests if the specified point is within the margin of this line.
Specified by:
contains in interface java.awt.Shape
Parameters:
x - the x-coordinate of the point.
y - the y-coordinate of the point.
Returns:
true if the specified point is within the margin of this line; false otherwise.

contains

public boolean contains(double x,
                        double y,
                        double w,
                        double h)
Tests if the specified rectangle intersects this LineShape. Calling this method is equivalent to calling the intersects(double, double, double, double) method.
Specified by:
contains in interface java.awt.Shape
Parameters:
x - the x-coordinate of the rectangle.
y - the y-coordinate of the rectangle
w - the width of the rectangle.
h - the height of the rectangle.
Returns:
true if the specified rectangle intersects this LineShape; false otherwise.

contains

public boolean contains(java.awt.geom.Point2D point)
Tests if the specified point is within the margin of this line.
Specified by:
contains in interface java.awt.Shape
Parameters:
point - the point to test.
Returns:
true if the specified point is within the margin of this line; false otherwise.

contains

public boolean contains(java.awt.geom.Rectangle2D rectangle)
Tests if the specified rectangle intersects this LineShape. Calling this method is equivalent to calling the intersects(Rectangle2D) method.
Specified by:
contains in interface java.awt.Shape
Parameters:
rectangle - the rectangle to test for intersection.
Returns:
true if the specified rectangle intersects this LineShape; false otherwise.

getBounds

public java.awt.Rectangle getBounds()
Returns an integer Rectangle that completely encloses the Shape.
Specified by:
getBounds in interface java.awt.Shape
Returns:
an integer Rectangle that completely encloses the Shape.

getBounds2D

public java.awt.geom.Rectangle2D getBounds2D()
Returns a high precision and more accurate bounding box of the Shape than the getBounds method.
Specified by:
getBounds2D in interface java.awt.Shape
Returns:
an instance of Rectangle2D that is a high-precision bounding box of the Shape.

getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform transform)
Returns an iterator object that iterates along the Shape boundary and provides access to the geometry of the Shape outline.
Specified by:
getPathIterator in interface java.awt.Shape
Parameters:
transform - an optional AffineTransform to be applied to the coordinates as they are returned in the iteration, or null if untransformed coordinates are desired.
Returns:
a new PathIterator object, which independently traverses the geometry of the Shape.

getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform transform,
                                                  double flatness)
Returns an iterator object that iterates along the Shape boundary and provides access to a flattened view of the Shape outline geometry.
Specified by:
getPathIterator in interface java.awt.Shape
Parameters:
transform - an optional AffineTransform to be applied to the coordinates as they are returned in the iteration, or null if untransformed coordinates are desired.
flatness - the maximum distance that the line segments used to approximate the curved segments are allowed to deviate from any point on the original curve.
Returns:
a new PathIterator that independently traverses the Shape geometry.

intersects

public boolean intersects(double x,
                          double y,
                          double w,
                          double h)
Tests if this LineShape intersects the specified rectangle. If the width and height of the rectangle are both less than 2.0, the rectangle is assumed to represent a single point, and the contains(double, double) method is called with the center point of the rectangle.
Specified by:
intersects in interface java.awt.Shape
Parameters:
x - the x-coordinate of the rectangle.
y - the y-coordinate of the rectangle.
w - the width of the rectangle.
h - the height of the rectangle.
Returns:
true if the specified rectangle intersects this LineShape; false otherwise.

intersects

public boolean intersects(java.awt.geom.Rectangle2D rectangle)
Tests if this LineShape intersects the specified rectangle. If the width and height of the rectangle are both less than 2.0, the rectangle is assumed to represent a single point, and the contains(double, double) method is called with the center point of the rectangle.
Specified by:
intersects in interface java.awt.Shape
Parameters:
rectangle - the rectangle to test for intersection.
Returns:
true if the specified rectangle intersects this LineShape; false otherwise.