edu.rit.slides.items
Class LineItem

java.lang.Object
  extended by edu.rit.slides.items.SlideItem
      extended by edu.rit.slides.items.OutlinedItem
          extended by edu.rit.slides.items.LineItem
All Implemented Interfaces:
Externalizable, Serializable

public class LineItem
extends OutlinedItem
implements Externalizable

Class LineItem provides a slide item that consists of one or more straight line segments. The line item may have an Arrow at either or both ends. The line item has an outline but has no interior.

Class LineItem keeps track of the "last line item." The static LineItem.last() method returns a reference to the last created line item.

When a LineItem is created, the "last point" (returned by the Point.last() method) is set to the line item's ending point.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class edu.rit.slides.items.OutlinedItem
NORMAL_OUTLINE
 
Constructor Summary
LineItem()
          Construct a new empty line item.
LineItem(Collection theEndpoints)
          Construct a new line item with the line segment endpoints in the given collection.
LineItem(Collection theEndpoints, Arrow theStartArrow, Arrow theEndArrow)
          Construct a new line item with the line segment endpoints in the given collection.
LineItem(Collection theEndpoints, Outline theOutline)
          Construct a new line item with the line segment endpoints in the given collection.
LineItem(Collection theEndpoints, Outline theOutline, Arrow theStartArrow, Arrow theEndArrow)
          Construct a new line item with the line segment endpoints in the given collection.
LineItem(Point[] theEndpoints)
          Construct a new line item with the line segment endpoints in the given array.
LineItem(Point[] theEndpoints, Arrow theStartArrow, Arrow theEndArrow)
          Construct a new line item with the line segment endpoints in the given array.
LineItem(Point[] theEndpoints, Outline theOutline)
          Construct a new line item with the line segment endpoints in the given array.
LineItem(Point[] theEndpoints, Outline theOutline, Arrow theStartArrow, Arrow theEndArrow)
          Construct a new line item with the line segment endpoints in the given array.
LineItem(Point start, Point end)
          Construct a new line item with one line segment.
LineItem(Point start, Point end, Arrow theStartArrow, Arrow theEndArrow)
          Construct a new line item with one line segment.
LineItem(Point start, Point end, Outline theOutline)
          Construct a new line item with one line segment.
LineItem(Point start, Point end, Outline theOutline, Arrow theStartArrow, Arrow theEndArrow)
          Construct a new line item with one line segment.
 
Method Summary
 void draw(Graphics2D g2d)
          Draw this slide item in the given graphics context.
 Point end()
          Returns this line item's ending point.
static LineItem last()
          Returns the last line item created.
 void readExternal(ObjectInput in)
          Read this line item from the given object input stream.
 Point start()
          Returns this line item's starting point.
 void writeExternal(ObjectOutput out)
          Write this line item to the given object output stream.
 
Methods inherited from class edu.rit.slides.items.OutlinedItem
setDefaultOutline
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LineItem

public LineItem()
Construct a new empty line item.


LineItem

public LineItem(Point start,
                Point end)
Construct a new line item with one line segment. The default outline is used. The line item has no arrows.

Parameters:
start - Starting point.
end - Ending point.
Throws:
NullPointerException - (unchecked exception) Thrown if start is null or end is null. Thrown if the default outline is Outline.NONE (null).

LineItem

public LineItem(Point start,
                Point end,
                Arrow theStartArrow,
                Arrow theEndArrow)
Construct a new line item with one line segment. The default outline is used. The given arrows are used.

Parameters:
start - Starting point.
end - Ending point.
theStartArrow - Arrow at starting point, or Arrow.NONE.
theEndArrow - Arrow at ending point, or Arrow.NONE.
Throws:
NullPointerException - (unchecked exception) Thrown if start is null or end is null. Thrown if the default outline is Outline.NONE (null).

LineItem

public LineItem(Point start,
                Point end,
                Outline theOutline)
Construct a new line item with one line segment. The given outline is used. The line item has no arrows.

Parameters:
start - Starting point.
end - Ending point.
theOutline - Outline.
Throws:
NullPointerException - (unchecked exception) Thrown if start is null or end is null. Thrown if theOutline is Outline.NONE (null).

LineItem

public LineItem(Point start,
                Point end,
                Outline theOutline,
                Arrow theStartArrow,
                Arrow theEndArrow)
Construct a new line item with one line segment. The given outline is used. The given arrows are used.

Parameters:
start - Starting point.
end - Ending point.
theOutline - Outline.
theStartArrow - Arrow at starting point, or Arrow.NONE.
theEndArrow - Arrow at ending point, or Arrow.NONE.
Throws:
NullPointerException - (unchecked exception) Thrown if start is null or end is null. Thrown if theOutline is Outline.NONE (null).

LineItem

public LineItem(Collection theEndpoints)
Construct a new line item with the line segment endpoints in the given collection. The default outline is used. The line item has no arrows.

The line segment endpoints are obtained by iterating over theEndpoints. The order of the endpoints returned by the iterator is the order of the endpoints for this line item.

Parameters:
theEndpoints - Collection of line segment endpoints.
Throws:
NullPointerException - (unchecked exception) Thrown if theEndpoints or any item therein is null. Thrown if the default outline is Outline.NONE (null).
IllegalArgumentException - (unchecked exception) Thrown if theEndpoints has fewer than two items.
ClassCastException - (unchecked exception) Thrown if any item in theEndpoints is not of type Point.

LineItem

public LineItem(Collection theEndpoints,
                Arrow theStartArrow,
                Arrow theEndArrow)
Construct a new line item with the line segment endpoints in the given collection. The default outline is used. The given arrows are used.

The line segment endpoints are obtained by iterating over theEndpoints. The order of the endpoints returned by the iterator is the order of the endpoints for this line item.

Parameters:
theEndpoints - Collection of line segment endpoints.
theStartArrow - Arrow at starting point, or Arrow.NONE.
theEndArrow - Arrow at ending point, or Arrow.NONE.
Throws:
NullPointerException - (unchecked exception) Thrown if theEndpoints or any item therein is null. Thrown if the default outline is Outline.NONE (null).
IllegalArgumentException - (unchecked exception) Thrown if theEndpoints has fewer than two items.
ClassCastException - (unchecked exception) Thrown if any item in theEndpoints is not of type Point.

LineItem

public LineItem(Collection theEndpoints,
                Outline theOutline)
Construct a new line item with the line segment endpoints in the given collection. The given outline is used. The line item has no arrows.

The line segment endpoints are obtained by iterating over theEndpoints. The order of the endpoints returned by the iterator is the order of the endpoints for this line item.

Parameters:
theEndpoints - Collection of line segment endpoints.
theOutline - Outline.
Throws:
NullPointerException - (unchecked exception) Thrown if theEndpoints or any item therein is null. Thrown if theOutline is Outline.NONE (null).
IllegalArgumentException - (unchecked exception) Thrown if theEndpoints has fewer than two items.
ClassCastException - (unchecked exception) Thrown if any item in theEndpoints is not of type Point.

LineItem

public LineItem(Collection theEndpoints,
                Outline theOutline,
                Arrow theStartArrow,
                Arrow theEndArrow)
Construct a new line item with the line segment endpoints in the given collection. The given outline is used. The given arrows are used.

The line segment endpoints are obtained by iterating over theEndpoints. The order of the endpoints returned by the iterator is the order of the endpoints for this line item.

Parameters:
theEndpoints - Collection of line segment endpoints.
theOutline - Outline.
theStartArrow - Arrow at starting point, or Arrow.NONE.
theEndArrow - Arrow at ending point, or Arrow.NONE.
Throws:
NullPointerException - (unchecked exception) Thrown if theEndpoints or any item therein is null. Thrown if theOutline is Outline.NONE (null).
IllegalArgumentException - (unchecked exception) Thrown if theEndpoints has fewer than two items.
ClassCastException - (unchecked exception) Thrown if any item in theEndpoints is not of type Point.

LineItem

public LineItem(Point[] theEndpoints)
Construct a new line item with the line segment endpoints in the given array. The default outline is used. The line item has no arrows.

Parameters:
theEndpoints - Array of line segment endpoints.
Throws:
NullPointerException - (unchecked exception) Thrown if theEndpoints or any item therein is null. Thrown if the default outline is Outline.NONE (null).
IllegalArgumentException - (unchecked exception) Thrown if theEndpoints has fewer than two items.

LineItem

public LineItem(Point[] theEndpoints,
                Arrow theStartArrow,
                Arrow theEndArrow)
Construct a new line item with the line segment endpoints in the given array. The default outline is used. The given arrows are used.

Parameters:
theEndpoints - Array of line segment endpoints.
theStartArrow - Arrow at starting point, or Arrow.NONE.
theEndArrow - Arrow at ending point, or Arrow.NONE.
Throws:
NullPointerException - (unchecked exception) Thrown if theEndpoints or any item therein is null. Thrown if the default outline is Outline.NONE (null).
IllegalArgumentException - (unchecked exception) Thrown if theEndpoints has fewer than two items.

LineItem

public LineItem(Point[] theEndpoints,
                Outline theOutline)
Construct a new line item with the line segment endpoints in the given array. The given outline is used. The line item has no arrows.

Parameters:
theEndpoints - Array of line segment endpoints.
theOutline - Outline.
Throws:
NullPointerException - (unchecked exception) Thrown if theEndpoints or any item therein is null. Thrown if theOutline is Outline.NONE (null).
IllegalArgumentException - (unchecked exception) Thrown if theEndpoints has fewer than two items.

LineItem

public LineItem(Point[] theEndpoints,
                Outline theOutline,
                Arrow theStartArrow,
                Arrow theEndArrow)
Construct a new line item with the line segment endpoints in the given array. The given outline is used. The given arrows are used.

Parameters:
theEndpoints - Array of line segment endpoints.
theOutline - Outline.
theStartArrow - Arrow at starting point, or Arrow.NONE.
theEndArrow - Arrow at ending point, or Arrow.NONE.
Throws:
NullPointerException - (unchecked exception) Thrown if theEndpoints or any item therein is null. Thrown if theOutline is Outline.NONE (null).
IllegalArgumentException - (unchecked exception) Thrown if theEndpoints has fewer than two items.
Method Detail

last

public static LineItem last()
Returns the last line item created. If no line items have been created yet, null is returned.


start

public Point start()
Returns this line item's starting point.


end

public Point end()
Returns this line item's ending point.


draw

public void draw(Graphics2D g2d)
Draw this slide 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.

Specified by:
draw in class SlideItem
Parameters:
g2d - 2-D graphics context.

writeExternal

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

Specified by:
writeExternal in interface Externalizable
Overrides:
writeExternal in class OutlinedItem
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 line item from the given object input stream.

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


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