edu.mit.sketch.ddg
Class DrawnObject

java.lang.Object
  extended by edu.mit.sketch.ddg.DrawnObject
All Implemented Interfaces:
Transformable, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
DrawnArrow, DrawnEllipse, DrawnLine, DrawnOval, DrawnPolygon, DrawnQuadrilateral, DrawnTriangle

public class DrawnObject
extends java.lang.Object
implements java.lang.Cloneable, Transformable, java.io.Serializable

An concrete object drawn from an object description. Consists of the geometric primitives which can be drawn, and provides several methds for calculating and changing properties of these primitives. Stores a mapping between the geometric parts and the primitives in the object description.

Needed Improvements:
Need better implementation of bounding box. Maybe axis of least inertia. Maybe contour or convex hull finding.

DrawnObject.java Created: Sun Apr 28 16:44:00 2002

Author:
Olya Veselova
See Also:
Serialized Form

Constructor Summary
DrawnObject()
          Construct an empty drawn object
DrawnObject(GeometricObjectList geometricParts, PrimitiveList primitives)
          Construct an drawnObject from a given list of geometric parts and a list of corresponding primitives.
DrawnObject(GeometricObject geometricPart, Primitive primitive)
          Construct an drawnObject from a given list of geometric parts (one part) and a list of corresponding primitives (one primitive).
DrawnObject(java.util.HashMap primToGeomParts)
          Construct an drawnObject from a given mapping of primitives to geometric parts.
 
Method Summary
 double angle()
          Get the angle of the object.
 Rectangle axisParallelBoundingBox()
          Get the axis-parallel bounding box
 Rectangle boundingBox()
          Get the smallest possible bounding box of any orientation
 Point center()
          Returns the center of the object, which is defined as the center of the smallest bounding box.
 java.lang.Object clone()
          Clone the object (and the concrete geometric parts inside)
 GeometricObject geometricPartAt(int index)
          Return the geometric part corresponding to the primitive at the given index
 GeometricObject geometricPartAt(Primitive primitive)
          Return the geometric part corresponding to the given primitive
 GeometricObjectList geometricParts()
          Return the geometric parts comprising this object
 DrawnObject getObject(Primitive primitive)
          Finds the geometric object corresponding to the primitive and returns it as a DrawnObject with that geometric object in it.
 DrawnObject getObject(PrimitiveList primitives)
          Finds the geometric object corresponding to the given list of primitives and returns it as a DrawnObject with those geometric object in it.
 double height()
          Get the height of the object.
 double length()
          Get the length of the object.
 void paint(java.awt.Graphics g)
          Paint the object with the primitives labelled.
 Primitive primitiveAt(int index)
          Return the primitive corresponding to the part at the given index
 PrimitiveList primitives()
          Return the primitives comprising this object
 void remove(Primitive primitive)
          Removes the geometric part corresponding to the given primitive.
 void rotate(Point origin, double angle)
          Rotate the object by a given angle from the x-axis, clockwise, about the given center.
 void scale(Point origin, double horizontalFactor, double verticalFactor)
          Scale the object by a given factor horizontally and vertically.
 double thickness()
          Get the thickness of the object.
 void translate(Point translationVector)
          Translate the object by a given translation vector
 double width()
          Get the width of the object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DrawnObject

public DrawnObject()
Construct an empty drawn object


DrawnObject

public DrawnObject(GeometricObjectList geometricParts,
                   PrimitiveList primitives)
Construct an drawnObject from a given list of geometric parts and a list of corresponding primitives. The indices of the corresponding primitives and geometric parts in the list should be the same.


DrawnObject

public DrawnObject(java.util.HashMap primToGeomParts)
Construct an drawnObject from a given mapping of primitives to geometric parts.


DrawnObject

public DrawnObject(GeometricObject geometricPart,
                   Primitive primitive)
Construct an drawnObject from a given list of geometric parts (one part) and a list of corresponding primitives (one primitive). The indices of the corresponding primitives and geometric parts in the list should be the same.

Method Detail

geometricParts

public GeometricObjectList geometricParts()
Return the geometric parts comprising this object


primitives

public PrimitiveList primitives()
Return the primitives comprising this object


getObject

public DrawnObject getObject(Primitive primitive)
                      throws PrimitiveNotFoundException
Finds the geometric object corresponding to the primitive and returns it as a DrawnObject with that geometric object in it. Throws an exception if the primitive was not found.

Throws:
PrimitiveNotFoundException

getObject

public DrawnObject getObject(PrimitiveList primitives)
                      throws PrimitiveNotFoundException
Finds the geometric object corresponding to the given list of primitives and returns it as a DrawnObject with those geometric object in it. Throws an exception if the primitive was not found.

Throws:
PrimitiveNotFoundException

primitiveAt

public Primitive primitiveAt(int index)
                      throws java.lang.IndexOutOfBoundsException
Return the primitive corresponding to the part at the given index

Throws:
java.lang.IndexOutOfBoundsException

geometricPartAt

public GeometricObject geometricPartAt(int index)
                                throws java.lang.IndexOutOfBoundsException
Return the geometric part corresponding to the primitive at the given index

Throws:
java.lang.IndexOutOfBoundsException

geometricPartAt

public GeometricObject geometricPartAt(Primitive primitive)
                                throws PrimitiveNotFoundException
Return the geometric part corresponding to the given primitive

Throws:
PrimitiveNotFoundException

remove

public void remove(Primitive primitive)
            throws PrimitiveNotFoundException
Removes the geometric part corresponding to the given primitive.

Throws:
PrimitiveNotFoundException

paint

public void paint(java.awt.Graphics g)
Paint the object with the primitives labelled.


center

public Point center()
             throws ObjectEmptyException
Returns the center of the object, which is defined as the center of the smallest bounding box.

Throws:
ObjectEmptyException

axisParallelBoundingBox

public Rectangle axisParallelBoundingBox()
                                  throws ObjectEmptyException
Get the axis-parallel bounding box

Throws:
ObjectEmptyException

width

public double width()
             throws ObjectEmptyException
Get the width of the object. Defined by the width of the axis parallel bounding box.

Throws:
ObjectEmptyException

height

public double height()
              throws ObjectEmptyException
Get the height of the object. Defined by the height of the axis parallel bounding box.

Throws:
ObjectEmptyException

boundingBox

public Rectangle boundingBox()
                      throws ObjectEmptyException
Get the smallest possible bounding box of any orientation

Throws:
ObjectEmptyException

thickness

public double thickness()
                 throws ObjectEmptyException
Get the thickness of the object. Defined by the smaller of the dimensions of the any orientation bounding box.

Throws:
ObjectEmptyException

length

public double length()
              throws ObjectEmptyException
Get the length of the object. Defined by the larger of the dimensions of the any orientation bounding box.

Throws:
ObjectEmptyException

angle

public double angle()
             throws ObjectEmptyException
Get the angle of the object.

Throws:
ObjectEmptyException

translate

public void translate(Point translationVector)
Translate the object by a given translation vector

Specified by:
translate in interface Transformable

rotate

public void rotate(Point origin,
                   double angle)
Rotate the object by a given angle from the x-axis, clockwise, about the given center.

Specified by:
rotate in interface Transformable

scale

public void scale(Point origin,
                  double horizontalFactor,
                  double verticalFactor)
Scale the object by a given factor horizontally and vertically. The given origin does not change the position.

Specified by:
scale in interface Transformable

clone

public java.lang.Object clone()
Clone the object (and the concrete geometric parts inside)

Overrides:
clone in class java.lang.Object