wheelsunh.users
Class Shape

java.lang.Object
  extended by wheelsunh.etc.AbstractGraphic
      extended by wheelsunh.users.AbstractShape
          extended by wheelsunh.users.Shape
All Implemented Interfaces:
Colorable, CustomGraphic, Locatable, Rotatable
Direct Known Subclasses:
Line, RectangularShape

public abstract class Shape
extends AbstractShape
implements Rotatable, Colorable, Locatable

Generic superclass for all Wheels graphics. Subclasses must pass an instance of java.awt.Shape to super to define the Shape's shape and define actualPaint to paint the shape.


Field Summary
protected  java.awt.Color _c
           
protected  DrawingPanel _dp
          The wheelsunh.etc.DrawingPanel in which the shape will be drawn.
protected  java.awt.Shape _shape
          The java.awt.Shape that defines the look of the shape
static java.awt.Color DEFAULT_COLOR
           
 
Fields inherited from class wheelsunh.users.AbstractShape
_rot
 
Constructor Summary
Shape(java.awt.Shape shape)
          Constructs a shape in the wheelsunh.users.Frame's DrawingPanel, with color DEFAULT_COLOR.
Shape(java.awt.Shape shape, DrawingPanel dp)
          Constructs a Shape with the passed-in shape in the specified DrawingPanel.
 
Method Summary
abstract  void actualPaint(java.awt.Graphics2D g)
          Subclasses must define this to do the actual painting of the shape.
 boolean contains(java.awt.Point p)
          Returns a boolean indicating whether or not the Shape contains the passed-in point.
 java.awt.Rectangle getBounds()
          Normal users do not need to worry about this! Returns a java.awt.Rectangle that bounds the shape.
 java.awt.Color getColor()
          Returns the shape's color.
abstract  java.awt.Point getLocation()
          Returns the object's location.
 int getRotation()
          Returns the Shape's current rotation in degrees.
abstract  int getXLocation()
          Returns the object's x location.
abstract  int getYLocation()
          Returns the object's y location.
 void hide()
          Hides the shape graphically.
 void paint(java.awt.Graphics2D g)
          This is the methid the DrawingPanel will call when the shape needs to display itself.
 void setColor(java.awt.Color c)
          Sets the color of the shape.
abstract  void setLocation(int x, int y)
          Set object's location to given coordinates.
abstract  void setLocation(java.awt.Point p)
          Set object's location to given point.
 void setRotation(int degrees)
          Set the rotation of the shape.
 void show()
          Displays the shape graphically.
 
Methods inherited from class wheelsunh.users.AbstractShape
boundsIntersects, center, distance, getCenter, getCenterX, getCenterY, getHeight, getIntersection, getWidth, intersects, intersects, setCenter
 
Methods inherited from class wheelsunh.etc.AbstractGraphic
mouseClicked, mouseDragged, mousePressed, mouseReleased
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_dp

protected DrawingPanel _dp
The wheelsunh.etc.DrawingPanel in which the shape will be drawn.


_shape

protected java.awt.Shape _shape
The java.awt.Shape that defines the look of the shape


_c

protected java.awt.Color _c

DEFAULT_COLOR

public static final java.awt.Color DEFAULT_COLOR
Constructor Detail

Shape

public Shape(java.awt.Shape shape)
Constructs a shape in the wheelsunh.users.Frame's DrawingPanel, with color DEFAULT_COLOR.

Parameters:
shape - the shape that describes our Shape

Shape

public Shape(java.awt.Shape shape,
             DrawingPanel dp)
Constructs a Shape with the passed-in shape in the specified DrawingPanel. Shape defaults to rotation of 0 and the same color as the DrawingPanel on which it is drawn.

Parameters:
shape - the shape that describes our Shape
dp - the wheelsunh.etc.DrawingPanel in which the shape will be drawn
Method Detail

hide

public void hide()
Hides the shape graphically. When this is done, the DrawingPanel no longer has a reference to the shape


show

public void show()
Displays the shape graphically. DrawingPanel gets a reference to shape when this is called. If the shape is already shown, the DrawingPanel will ignore the call to add it. (You don't have to worry about calling show on a shown shape.


paint

public void paint(java.awt.Graphics2D g)
This is the methid the DrawingPanel will call when the shape needs to display itself. Subclasses should not override this method, as it only sets the instance of java.awt.Graphics2D up to draw the shape at the proper rotation and calls actualPaint(g).

Specified by:
paint in interface CustomGraphic
Parameters:
g - the instance of java.awt.Graphics2D that should be used to paint the shape

actualPaint

public abstract void actualPaint(java.awt.Graphics2D g)
Subclasses must define this to do the actual painting of the shape. All calls to paint(java.awt.Graphics2D) will forward to this method.

Parameters:
g - the instance of java.awt.Graphics2D that should be used to paint the shape

setColor

public void setColor(java.awt.Color c)
Sets the color of the shape. (go figure)

Specified by:
setColor in interface Colorable

getColor

public java.awt.Color getColor()
Returns the shape's color.

Specified by:
getColor in interface Colorable

setRotation

public void setRotation(int degrees)
Set the rotation of the shape.

Specified by:
setRotation in interface Rotatable
Specified by:
setRotation in class AbstractShape
Parameters:
degrees - the magnitude of the rotation in degrees

getRotation

public int getRotation()
Returns the Shape's current rotation in degrees.

Specified by:
getRotation in interface Rotatable
Specified by:
getRotation in class AbstractShape

getBounds

public java.awt.Rectangle getBounds()
Normal users do not need to worry about this! Returns a java.awt.Rectangle that bounds the shape.

Specified by:
getBounds in class AbstractShape

contains

public boolean contains(java.awt.Point p)
Returns a boolean indicating whether or not the Shape contains the passed-in point.

Specified by:
contains in interface CustomGraphic
Parameters:
p - the point

setLocation

public abstract void setLocation(int x,
                                 int y)
Set object's location to given coordinates.

Specified by:
setLocation in interface Locatable
Overrides:
setLocation in class AbstractShape

setLocation

public abstract void setLocation(java.awt.Point p)
Set object's location to given point.

Specified by:
setLocation in interface Locatable
Specified by:
setLocation in class AbstractShape

getLocation

public abstract java.awt.Point getLocation()
Returns the object's location.

Specified by:
getLocation in interface Locatable
Specified by:
getLocation in class AbstractShape

getXLocation

public abstract int getXLocation()
Returns the object's x location.

Specified by:
getXLocation in interface Locatable
Specified by:
getXLocation in class AbstractShape

getYLocation

public abstract int getYLocation()
Returns the object's y location.

Specified by:
getYLocation in interface Locatable
Specified by:
getYLocation in class AbstractShape