cse115.graphics
Class Polygon

java.lang.Object
  extended by cse115.graphics.AbstractGraphic
      extended by cse115.graphics.AbstractColorableGraphic
          extended by cse115.graphics.Polygon
All Implemented Interfaces:
CenterLocatable, Colorable, ColorableGraphic, Graphic, Locatable, Rotatable, Sizeable
Direct Known Subclasses:
BouncingTriangle, Fish, Triangle

public class Polygon
extends AbstractColorableGraphic

A polygon is a Graphic that can form many shapes. To use, set the desired dimension of the polygon. Then add at least three points in order to correctly make a polygon. This will play connect the dots in the order that the points are added. Then connects the last point back to the first, forming a polygon.

Author:
Michael Kozelsky Created on: Jul 29, 2006 Polygon.java

Constructor Summary
Polygon()
          Creates a new instance of Polygon with no vertices
 
Method Summary
 void actualPaint(Graphics2D gs, Point location, Dimension dimension)
          This method uses the Graphics2D object to paint the Polygon onto the container.
 void addPoint(Point p)
          Add a point to the polygon
 Point getLocation()
          Returns the location of the polygon
 Shape getShape()
          Gets a java.awt.shape that represents this shape
 void move(Vector v)
          Moves the Polygon by some amount, specified by a vector
 void removePoint(Point p)
          removes the first occurrence of point p from the polygon
 void setDimension(Dimension d)
          Resizes the Polygon to a specific dimension.
 void setLocation(Point point)
          Sets the location of the polygon.
 
Methods inherited from class cse115.graphics.AbstractColorableGraphic
getColor, paint, setColor
 
Methods inherited from class cse115.graphics.AbstractGraphic
addMouseListener, addMouseMotionListener, contains, getBounds, getCenterLocation, getContainer, getDimension, getMouseListeners, getMouseMotionListeners, getRotation, intersects, rotate, setCenterLocation, setContainer, setRotation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface cse115.graphics.Graphic
addMouseListener, addMouseMotionListener, contains, getBounds, getMouseListeners, getMouseMotionListeners, intersects, setContainer
 
Methods inherited from interface cse115.graphics.Sizeable
getDimension
 
Methods inherited from interface cse115.graphics.CenterLocatable
getCenterLocation, setCenterLocation
 
Methods inherited from interface cse115.graphics.Rotatable
getRotation, rotate, setRotation
 

Constructor Detail

Polygon

public Polygon()
Creates a new instance of Polygon with no vertices

Method Detail

addPoint

public void addPoint(Point p)
Add a point to the polygon

Parameters:
p - the point to add

removePoint

public void removePoint(Point p)
removes the first occurrence of point p from the polygon

Parameters:
p - The Point to remove

actualPaint

public void actualPaint(Graphics2D gs,
                        Point location,
                        Dimension dimension)
This method uses the Graphics2D object to paint the Polygon onto the container. The location and dimension parameters are not used because the polygon knows it's location and dimension

Parameters:
gs - The Graphics2D object to do the painting
location - Does nothing
dimension - Does Nothing
See Also:
Graphic.actualPaint(java.awt.Graphics2D, java.awt.Point, java.awt.Dimension)

setLocation

public void setLocation(Point point)
Sets the location of the polygon. TODO: does this do the upper left hand corner of the bounding box?

Specified by:
setLocation in interface Locatable
Overrides:
setLocation in class AbstractGraphic
Parameters:
point - A java.awt.Point representing the new location of the Polygon
See Also:
Locatable.setLocation(java.awt.Point)

getLocation

public Point getLocation()
Returns the location of the polygon

Specified by:
getLocation in interface Locatable
Overrides:
getLocation in class AbstractGraphic
Returns:
A java.awt.Point representing the location of the polygon
See Also:
AbstractGraphic.getLocation()

move

public void move(Vector v)
Moves the Polygon by some amount, specified by a vector

Specified by:
move in interface Locatable
Overrides:
move in class AbstractGraphic
Parameters:
v - The vector representing the amount to move the Polygon
See Also:
Locatable.move(cse115.utilities.Vector)

setDimension

public void setDimension(Dimension d)
Resizes the Polygon to a specific dimension. Warning: still in beta testing and will probably not function as expected.

Specified by:
setDimension in interface Sizeable
Overrides:
setDimension in class AbstractGraphic
Parameters:
d - The dimension which the polygon should have
See Also:
Sizeable.setDimension(java.awt.Dimension)

getShape

public Shape getShape()
Gets a java.awt.shape that represents this shape

Returns:
a java.awt.Polygon that represents this polygon
See Also:
Graphic.getShape()