Class DrawableShape

java.lang.Object
  |
  +--DrawableShape
Direct Known Subclasses:
Ellipse, Line, Polygon, Rectangle

public abstract class DrawableShape
extends java.lang.Object

CLASS: DrawableShape
PURPOSE: Serve as a super class for other shape, force the subclass to have method for drawing and editing.
IMPORT: java.awt.Graphics, java.awt.Color, java.util.Vector, Point
EXPORT: None, This is an abstract class with partial implementation. User should not instantiate this class. Some basic functions have already been implemented: addPoint, getColor, move, movePointBox, removeLastPoint, setColor, setEndPoint, setFill, setSelected, setStartPoint


Field Summary
protected  boolean bFill
          Flag to indicate the shape is to be filled or not
protected  boolean bSelected
          Flag to indicate if the shape has been selected
protected  java.awt.Color color
          Color for the shape
protected  java.util.Vector pointList
          Vector to keep track of the shapes point(s)
protected  Point xPointChange
          Reference Point object for resize change(X component)
protected  Point yPointChange
          Reference Point object for resize change(Y component)
 
Constructor Summary
DrawableShape()
           
 
Method Summary
 void addPoint(Point pt)
          
PRE: A valid Point object
POST: Add a new point to the point list.
abstract  DrawableShape copyClone()
          
PRE: None
POST: A new DrawableShape object is copy from the current instance and returned
 java.awt.Color getColor()
          
PRE: None
POST: Return the color of the shape
 int getLeastX()
          
PRE: None
POST: Return the least value for x in the point list
 int getLeastY()
          
PRE: None
POST: Return the least value for y in the point list
abstract  boolean hitTest(Point p)
          
PRE: A valid Point Object
POST: Check to see if the point hit the shape
abstract  boolean hitTestPointBox(Point p)
          
PRE: A valid Point object
POST: Return true if the point hit the Point Box
 void move(int deltaX, int deltaY)
          
PRE: None
POST: Move the shape offset by the input x and y
 void movePointBox(int deltaX, int deltaY)
          
PRE: None
POST: Resize the shape by offset the reference point(s) by the input x and y
abstract  void paint(java.awt.Graphics g)
          
PRE: A valid Graphics object to paint on
POST: Current object will be draw using the Graphics object
 void removeLastPoint()
          
PRE: None
POST: Remove the last point from the point list (if any)
 void setColor(java.awt.Color color)
          
PRE: A valid Color Object
POST: Set the color of the shape from the input
 void setEndPoint(Point p)
          
PRE: A valid Point Object
POST: Set the endPoint of the shape from the input
 void setFill(boolean b)
          
PRE: None
POST: Set the private variable bFill as the input
 void setSelected(boolean b)
          
PRE: None
POST: Set the shape flag to indicate whether it has been selected or not
 void setStartPoint(Point p)
          
PRE: A valid Point Object
POST: Set the startPoint of the shape from the input
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

xPointChange

protected Point xPointChange
Reference Point object for resize change(X component)

yPointChange

protected Point yPointChange
Reference Point object for resize change(Y component)

pointList

protected java.util.Vector pointList
Vector to keep track of the shapes point(s)

color

protected java.awt.Color color
Color for the shape

bFill

protected boolean bFill
Flag to indicate the shape is to be filled or not

bSelected

protected boolean bSelected
Flag to indicate if the shape has been selected
Constructor Detail

DrawableShape

public DrawableShape()
Method Detail

copyClone

public abstract DrawableShape copyClone()

PRE: None
POST: A new DrawableShape object is copy from the current instance and returned

paint

public abstract void paint(java.awt.Graphics g)

PRE: A valid Graphics object to paint on
POST: Current object will be draw using the Graphics object

hitTest

public abstract boolean hitTest(Point p)

PRE: A valid Point Object
POST: Check to see if the point hit the shape

hitTestPointBox

public abstract boolean hitTestPointBox(Point p)

PRE: A valid Point object
POST: Return true if the point hit the Point Box

setStartPoint

public void setStartPoint(Point p)

PRE: A valid Point Object
POST: Set the startPoint of the shape from the input

setEndPoint

public void setEndPoint(Point p)

PRE: A valid Point Object
POST: Set the endPoint of the shape from the input

setColor

public void setColor(java.awt.Color color)

PRE: A valid Color Object
POST: Set the color of the shape from the input

setFill

public void setFill(boolean b)

PRE: None
POST: Set the private variable bFill as the input

setSelected

public void setSelected(boolean b)

PRE: None
POST: Set the shape flag to indicate whether it has been selected or not

move

public void move(int deltaX,
                 int deltaY)

PRE: None
POST: Move the shape offset by the input x and y

addPoint

public void addPoint(Point pt)

PRE: A valid Point object
POST: Add a new point to the point list. Will create a new instance of the point

movePointBox

public void movePointBox(int deltaX,
                         int deltaY)

PRE: None
POST: Resize the shape by offset the reference point(s) by the input x and y

removeLastPoint

public void removeLastPoint()

PRE: None
POST: Remove the last point from the point list (if any)

getColor

public java.awt.Color getColor()

PRE: None
POST: Return the color of the shape

getLeastX

public int getLeastX()

PRE: None
POST: Return the least value for x in the point list

getLeastY

public int getLeastY()

PRE: None
POST: Return the least value for y in the point list