wheels.users
Class Shape

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

public abstract class Shape
extends AbstractGraphic
implements Rotatable, Colorable

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.

Author:
Sanders & van Dam. Object-Oriented Programming in Java.

Field Summary
protected  DrawingPanel _dp
          The wheels.etc.DrawingPanel in which the shape will be drawn.
protected  Shape _shape
          The java.awt.Shape that defines the look of the shape
static Color DEFAULT_COLOR
           
 
Constructor Summary
Shape(Shape shape)
          Constructs a shape in the wheels.users.Frame's DrawingPanel, with color DEFAULT_COLOR.
Shape(Shape shape, DrawingPanel dp)
          Constructs a Shape with the passed-in shape in the specified DrawingPanel.
 
Method Summary
abstract  void actualPaint(Graphics2D g)
          Subclasses must define this to do the actual painting of the shape.
 boolean contains(Point p)
          Returns a boolean indicating whether or not the Shape contains the passed-in point.
 Rectangle getBounds()
          Normal users do not need to worry about this! Returns a java.awt.Rectangle that bounds the shape.
 Color getColor()
          Returns the shape's color.
 int getRotation()
          Returns the Shape's current rotation in degrees.
 void hide()
          Hides the shape graphically.
 void paint(Graphics2D g)
          This is the methid the DrawingPanel will call when the shape needs to display itself.
 void setColor(Color c)
          Sets the color of the shape.
 void setRotation(int degrees)
          Set the rotation of the shape.
 void show()
          Displays the shape graphically.
 
Methods inherited from class wheels.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 wheels.etc.DrawingPanel in which the shape will be drawn.


_shape

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


DEFAULT_COLOR

public static final Color DEFAULT_COLOR
Constructor Detail

Shape

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

Parameters:
shape - the shape that describes our Shape

Shape

public Shape(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 wheels.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(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(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(Color c)
Sets the color of the shape. (go figure)

Specified by:
setColor in interface Colorable

getColor

public 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
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

getBounds

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


contains

public boolean contains(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