edu.rit.draw.item
Class Polygon

java.lang.Object
  extended by edu.rit.draw.item.DrawingItem
      extended by edu.rit.draw.item.OutlinedItem
          extended by edu.rit.draw.item.FilledItem
              extended by edu.rit.draw.item.ShapeItem
                  extended by edu.rit.draw.item.Polygon
All Implemented Interfaces:
Externalizable, Serializable

public class Polygon
extends ShapeItem

Class Polygon provides a polygon DrawingItem whose boundary consists of one or more straight line segments. The polygon has an outline and a filled interior.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class edu.rit.draw.item.FilledItem
NORMAL_FILL
 
Fields inherited from class edu.rit.draw.item.OutlinedItem
NORMAL_OUTLINE
 
Constructor Summary
Polygon()
          Construct a new polygon.
Polygon(Polygon thePolygon)
          Construct a new polygon with the same points, outline, and fill paint as the given polygon.
 
Method Summary
 Polygon add()
          Add this polygon to the end of the default drawing's sequence of drawing items.
 Polygon add(Drawing theDrawing)
          Add this polygon to the end of the given drawing's sequence of drawing items.
 Polygon addFirst()
          Add this polygon to the beginning of the default drawing's sequence of drawing items.
 Polygon addFirst(Drawing theDrawing)
          Add this polygon to the beginning of the given drawing's sequence of drawing items.
 Polygon by(double dx, double dy)
          Add a line segment to this polygon.
 Polygon by(Size theSize)
          Add a line segment to this polygon.
 Polygon clear()
          Clear this polygon.
 Polygon fill(Fill theFill)
          Set this polygon's fill paint.
 Polygon hby(double dx)
          Add a horizontal line segment to this polygon.
 Polygon hby(Size theSize)
          Add a horizontal line segment to this polygon.
 double height()
          Returns the height of this polygon's bounding box.
 Polygon hto(double x)
          Add a horizontal line segment to this polygon.
 Polygon hto(Point thePoint)
          Add a horizontal line segment to this polygon.
 Point nw()
          Returns the northwest corner point of this polygon's bounding box.
 Polygon outline(Outline theOutline)
          Set this polygon's outline.
 void readExternal(ObjectInput in)
          Read this polygon from the given object input stream.
 Size size()
          Returns the size of this polygon's bounding box.
 Polygon to(double x, double y)
          Add a line segment to this polygon.
 Polygon to(Point thePoint)
          Add a line segment to this polygon.
 Polygon vby(double dy)
          Add a vertical line segment to this polygon.
 Polygon vby(Size theSize)
          Add a vertical line segment to this polygon.
 Polygon vto(double y)
          Add a vertical line segment to this polygon.
 Polygon vto(Point thePoint)
          Add a vertical line segment to this polygon.
 double width()
          Returns the width of this polygon's bounding box.
 void writeExternal(ObjectOutput out)
          Write this polygon to the given object output stream.
 
Methods inherited from class edu.rit.draw.item.ShapeItem
draw
 
Methods inherited from class edu.rit.draw.item.FilledItem
defaultFill, defaultFill, fill
 
Methods inherited from class edu.rit.draw.item.OutlinedItem
defaultOutline, defaultOutline, outline
 
Methods inherited from class edu.rit.draw.item.DrawingItem
boundingBox, c, e, n, ne, s, se, sw, w
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Polygon

public Polygon()
Construct a new polygon. The polygon has no points initially. The default outline and fill paint are used.


Polygon

public Polygon(Polygon thePolygon)
Construct a new polygon with the same points, outline, and fill paint as the given polygon.

Parameters:
thePolygon - Polygon.
Throws:
NullPointerException - (unchecked exception) Thrown if thePolygon is null.
Method Detail

size

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

Overrides:
size in class DrawingItem
Returns:
Size.

width

public double width()
Returns the width of this polygon's bounding box.

Specified by:
width in class DrawingItem
Returns:
Width.

height

public double height()
Returns the height of this polygon's bounding box.

Specified by:
height in class DrawingItem
Returns:
Height.

nw

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

Specified by:
nw in class DrawingItem
Returns:
Northwest corner point.

outline

public Polygon outline(Outline theOutline)
Set this polygon's outline.

Overrides:
outline in class ShapeItem
Parameters:
theOutline - Outline, or Outline.NONE.
Returns:
This polygon.

fill

public Polygon fill(Fill theFill)
Set this polygon's fill paint.

Overrides:
fill in class ShapeItem
Parameters:
theFill - Fill paint, or Fill.NONE.
Returns:
This polygon.

clear

public Polygon clear()
Clear this polygon. All of this polygon's line segments are removed.

Returns:
This polygon.

to

public Polygon to(double x,
                  double y)
Add a line segment to this polygon. The new endpoint is (x, y). If this polygon has no line segments, the to() method specifies this polygon's starting endpoint.

Parameters:
x - Endpoint's X coordinate.
y - Endpoint's Y coordinate.
Returns:
This polygon.

to

public Polygon to(Point thePoint)
Add a line segment to this polygon. The new endpoint is thePoint. If this polygon has no line segments, the to() method specifies this polygon's starting endpoint.

Parameters:
thePoint - Endpoint.
Returns:
This polygon.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

hto

public Polygon hto(double x)
Add a horizontal line segment to this polygon. The new endpoint is (x, previous endpoint's Y coordinate).

Parameters:
x - Endpoint's X coordinate.
Returns:
This polygon.
Throws:
NullPointerException - (unchecked exception) Thrown if there is no previous endpoint.

hto

public Polygon hto(Point thePoint)
Add a horizontal line segment to this polygon. The new endpoint is (thePoint's X coordinate, previous endpoint's Y coordinate).

Parameters:
thePoint - Endpoint.
Returns:
This polygon.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null. Thrown if there is no previous endpoint.

vto

public Polygon vto(double y)
Add a vertical line segment to this polygon. The new endpoint is (previous endpoint's X coordinate, y).

Parameters:
y - Endpoint's Y coordinate.
Returns:
This polygon.
Throws:
NullPointerException - (unchecked exception) Thrown if there is no previous endpoint.

vto

public Polygon vto(Point thePoint)
Add a vertical line segment to this polygon. The new endpoint is (previous endpoint's X coordinate, thePoint's Y coordinate).

Parameters:
thePoint - Endpoint.
Returns:
This polygon.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null. Thrown if there is no previous endpoint.

by

public Polygon by(double dx,
                  double dy)
Add a line segment to this polygon. The new endpoint is (previous endpoint's X coordinate + dx, previous endpoint's Y coordinate + dy).

Parameters:
dx - X distance.
dy - Y distance.
Returns:
This polygon.
Throws:
NullPointerException - (unchecked exception) Thrown if there is no previous endpoint.

by

public Polygon by(Size theSize)
Add a line segment to this polygon. The new endpoint is (previous endpoint's X coordinate + theSize.width(), previous endpoint's Y coordinate + theSize.height()).

Parameters:
theSize - Distance.
Returns:
This polygon.
Throws:
NullPointerException - (unchecked exception) Thrown if theSize is null. Thrown if there is no previous endpoint.

hby

public Polygon hby(double dx)
Add a horizontal line segment to this polygon. The new endpoint is (previous endpoint's X coordinate + dx, previous endpoint's Y coordinate).

Parameters:
dx - X distance.
Returns:
This polygon.
Throws:
NullPointerException - (unchecked exception) Thrown if there is no previous endpoint.

hby

public Polygon hby(Size theSize)
Add a horizontal line segment to this polygon. The new endpoint is (previous endpoint's X coordinate + theSize.width(), previous endpoint's Y coordinate).

Parameters:
theSize - Distance.
Returns:
This polygon.
Throws:
NullPointerException - (unchecked exception) Thrown if theSize is null. Thrown if there is no previous endpoint.

vby

public Polygon vby(double dy)
Add a vertical line segment to this polygon. The new endpoint is (previous endpoint's X coordinate, previous endpoint's Y coordinate + dy).

Parameters:
dy - Y distance.
Returns:
This polygon.
Throws:
NullPointerException - (unchecked exception) Thrown if there is no previous endpoint.

vby

public Polygon vby(Size theSize)
Add a vertical line segment to this polygon. The new endpoint is (previous endpoint's X coordinate, previous endpoint's Y coordinate + theSize.height()).

Parameters:
theSize - Distance.
Returns:
This polygon.
Throws:
NullPointerException - (unchecked exception) Thrown if theSize is null. Thrown if there is no previous endpoint.

add

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

Overrides:
add in class ShapeItem
Returns:
This polygon.
Throws:
NullPointerException - (unchecked exception) Thrown if there is no default drawing.
See Also:
Drawing.defaultDrawing()

add

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

Overrides:
add in class ShapeItem
Parameters:
theDrawing - Drawing.
Returns:
This polygon.
Throws:
NullPointerException - (unchecked exception) Thrown if theDrawing is null.

addFirst

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

Overrides:
addFirst in class ShapeItem
Returns:
This polygon.
Throws:
NullPointerException - (unchecked exception) Thrown if there is no default drawing.
See Also:
Drawing.defaultDrawing()

addFirst

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

Overrides:
addFirst in class ShapeItem
Parameters:
theDrawing - Drawing.
Returns:
This polygon.
Throws:
NullPointerException - (unchecked exception) Thrown if theDrawing is null.

writeExternal

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

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

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


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