edu.rit.draw.item
Class DrawingItem
- java.lang.Object
-
- edu.rit.draw.item.DrawingItem
-
- All Implemented Interfaces:
- java.io.Externalizable, java.io.Serializable
- Direct Known Subclasses:
- Group, Image, OutlinedItem, Text
public abstract class DrawingItem extends java.lang.Object implements java.io.ExternalizableClass 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
Constructors Constructor and Description 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
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description DrawingItemadd()Add this drawing item to the end of the default drawing's sequence of drawing items.DrawingItemadd(Drawing theDrawing)Add this drawing item to the end of the given drawing's sequence of drawing items.DrawingItemaddFirst()Add this drawing item to the beginning of the default drawing's sequence of drawing items.DrawingItemaddFirst(Drawing theDrawing)Add this drawing item to the beginning of the given drawing's sequence of drawing items.java.awt.geom.Rectangle2DboundingBox()Returns the rectangular region this drawing item occupies.Pointc()Returns the center point of this drawing item's bounding box.voiddraw(java.awt.Graphics2D g2d)Draw this drawing item in the given graphics context.Pointe()Returns the east middle point of this drawing item's bounding box.abstract doubleheight()Returns the height of this drawing item's bounding box.Pointn()Returns the north middle point of this drawing item's bounding box.Pointne()Returns the northeast corner point of this drawing item's bounding box.abstract Pointnw()Returns the northwest corner point of this drawing item's bounding box.voidreadExternal(java.io.ObjectInput in)Read this drawing item from the given object input stream.Points()Returns the south middle point of this drawing item's bounding box.Pointse()Returns the southeast corner point of this drawing item's bounding box.Sizesize()Returns the size of this drawing item's bounding box.Pointsw()Returns the southwest corner point of this drawing item's bounding box.Pointw()Returns the west middle point of this drawing item's bounding box.abstract doublewidth()Returns the width of this drawing item's bounding box.voidwriteExternal(java.io.ObjectOutput out)Write this drawing item to the given object output stream.
-
-
-
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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.NullPointerException- (unchecked exception) Thrown if theDrawing is null.
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOExceptionWrite this drawing item to the given object output stream.- Specified by:
writeExternalin interfacejava.io.Externalizable- Parameters:
out- Object output stream.- Throws:
java.io.IOException- Thrown if an I/O error occurred.
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionRead this drawing item from the given object input stream.- Specified by:
readExternalin interfacejava.io.Externalizable- Parameters:
in- Object input stream.- Throws:
java.io.IOException- Thrown if an I/O error occurred.java.lang.ClassNotFoundException- Thrown if any class needed to deserialize this drawing item cannot be found.
-
draw
public void draw(java.awt.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 java.awt.geom.Rectangle2D boundingBox()
Returns the rectangular region this drawing item occupies.- Returns:
- Bounding box.
-
-
DMelt 3.0 © DataMelt by jWork.ORG