edu.rit.draw.item
Class DrawingItem

java.lang.Object
  extended by edu.rit.draw.item.DrawingItem
All Implemented Interfaces:
Externalizable, Serializable
Direct Known Subclasses:
Group, Image, OutlinedItem, Text

public abstract class DrawingItem
extends Object
implements Externalizable

Class DrawingItem is the abstract base class for each item on a Drawing. Subclasses provide different kinds of drawing items, such as text, lines, and shapes.

Each drawing item is contained within a rectangular bounding box. Class DrawingItem's methods return the location and dimensions of the bounding box.

See Also:
Serialized Form

Constructor Summary
DrawingItem()
          Construct a new drawing item.
DrawingItem(DrawingItem theItem)
          Construct a new drawing item that is the same as the given drawing item.
 
Method Summary
 DrawingItem add()
          Add this drawing item to the end of the default drawing's sequence of drawing items.
 DrawingItem add(Drawing theDrawing)
          Add this drawing item to the end of the given drawing's sequence of drawing items.
 DrawingItem addFirst()
          Add this drawing item to the beginning of the default drawing's sequence of drawing items.
 DrawingItem addFirst(Drawing theDrawing)
          Add this drawing item to the beginning of the given drawing's sequence of drawing items.
 Rectangle2D boundingBox()
          Returns the rectangular region this drawing item occupies.
 Point c()
          Returns the center point of this drawing item's bounding box.
 void draw(Graphics2D g2d)
          Draw this drawing item in the given graphics context.
 Point e()
          Returns the east middle point of this drawing item's bounding box.
abstract  double height()
          Returns the height of this drawing item's bounding box.
 Point n()
          Returns the north middle point of this drawing item's bounding box.
 Point ne()
          Returns the northeast corner point of this drawing item's bounding box.
abstract  Point nw()
          Returns the northwest corner point of this drawing item's bounding box.
 void readExternal(ObjectInput in)
          Read this drawing item from the given object input stream.
 Point s()
          Returns the south middle point of this drawing item's bounding box.
 Point se()
          Returns the southeast corner point of this drawing item's bounding box.
 Size size()
          Returns the size of this drawing item's bounding box.
 Point sw()
          Returns the southwest corner point of this drawing item's bounding box.
 Point w()
          Returns the west middle point of this drawing item's bounding box.
abstract  double width()
          Returns the width of this drawing item's bounding box.
 void writeExternal(ObjectOutput out)
          Write this drawing item to the given object output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DrawingItem

public DrawingItem()
Construct a new drawing item.


DrawingItem

public DrawingItem(DrawingItem theItem)
Construct a new drawing item that is the same as the given drawing item.

Parameters:
theItem - Drawing item.
Throws:
NullPointerException - (unchecked exception) Thrown if theItem is null.
Method Detail

size

public Size size()
Returns the size of this drawing item's bounding box.

Returns:
Size.

width

public abstract double width()
Returns the width of this drawing item's bounding box.

Returns:
Width.

height

public abstract double height()
Returns the height of this drawing item's bounding box.

Returns:
Height.

nw

public abstract Point nw()
Returns the northwest corner point of this drawing item's bounding box.

Returns:
Northwest corner point.

n

public Point n()
Returns the north middle point of this drawing item's bounding box.

Returns:
North middle point.

ne

public Point ne()
Returns the northeast corner point of this drawing item's bounding box.

Returns:
Northeast corner point.

w

public Point w()
Returns the west middle point of this drawing item's bounding box.

Returns:
West middle point.

c

public Point c()
Returns the center point of this drawing item's bounding box.

Returns:
Center point.

e

public Point e()
Returns the east middle point of this drawing item's bounding box.

Returns:
East middle point.

sw

public Point sw()
Returns the southwest corner point of this drawing item's bounding box.

Returns:
Southwest corner point.

s

public Point s()
Returns the south middle point of this drawing item's bounding box.

Returns:
South middle point.

se

public Point se()
Returns the southeast corner point of this drawing item's bounding box.

Returns:
Southeast corner point.

add

public DrawingItem add()
Add this drawing item to the end of the default drawing's sequence of drawing items.

Returns:
This drawing item.
Throws:
NullPointerException - (unchecked exception) Thrown if there is no default drawing.
See Also:
Drawing.defaultDrawing()

add

public DrawingItem add(Drawing theDrawing)
Add this drawing item to the end of the given drawing's sequence of drawing items.

Parameters:
theDrawing - Drawing.
Returns:
This drawing item.
Throws:
NullPointerException - (unchecked exception) Thrown if theDrawing is null.

addFirst

public DrawingItem addFirst()
Add this drawing item to the beginning of the default drawing's sequence of drawing items.

Returns:
This drawing item.
Throws:
NullPointerException - (unchecked exception) Thrown if there is no default drawing.
See Also:
Drawing.defaultDrawing()

addFirst

public DrawingItem addFirst(Drawing theDrawing)
Add this drawing item to the beginning of the given drawing's sequence of drawing items.

Parameters:
theDrawing - Drawing.
Returns:
This drawing item.
Throws:
NullPointerException - (unchecked exception) Thrown if theDrawing is null.

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Write this drawing item to the given object output stream.

Specified by:
writeExternal in interface Externalizable
Parameters:
out - Object output stream.
Throws:
IOException - Thrown if an I/O error occurred.

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Read this drawing item from the given object input stream.

Specified by:
readExternal in interface Externalizable
Parameters:
in - Object input stream.
Throws:
IOException - Thrown if an I/O error occurred.
ClassNotFoundException - Thrown if any class needed to deserialize this drawing item cannot be found.

draw

public void draw(Graphics2D g2d)
Draw this drawing item in the given graphics context. This method is allowed to change the graphics context's paint, stroke, and transform, and it doesn't have to change them back.

Parameters:
g2d - 2-D graphics context.

boundingBox

public Rectangle2D boundingBox()
Returns the rectangular region this drawing item occupies.

Returns:
Bounding box.


Copyright © 2005-2012 by Alan Kaminsky. All rights reserved. Send comments to ark­@­cs.rit.edu.