Class DrawPadDoc

java.lang.Object
  |
  +--DrawPadDoc

public class DrawPadDoc
extends java.lang.Object

CLASS: DrawPadDoc
PURPOSE: This class keep track of all the shapes and provide methods to manipulate them
IMPORT: java.awt.Graphics, java.util.Vector, java.awt.Color, DrawableShape, Point
EXPORT: New Class|DrawPadDoc
New Method|DrawPadDoc, addShape, copySelectedShape, deleteSelectedShape, drawAllShapes, getSelectedShapeColor, moveSelectedPointBox, moveSelectedShapeToBack, moveSelectedShapeToFront, moveShape, pasteShape, selectNextShape, selectPointBox, selectedPreviousShape, selectShape, setSelectedShapeColor, setShapeEndPoint, unSelectShape


Field Summary
private  boolean bSelectedPointBox
          A flag to indicate if we have selected a point box in the selected shape
private  DrawableShape copyShape
          A copied of a shape
private  DrawableShape selectedShape
          The shape that is being selected
private  java.util.Vector shapeList
          A vector list containing shapes
 
Constructor Summary
DrawPadDoc()
          
PRE: None
POST: Construct and initialize the DrawPadDoc Object
 
Method Summary
 void addShape(DrawableShape shape)
          
PRE: A valid DrawableShape object
POST: Add a shape to the list
 void copySelectedShape()
          
PRE: NoneBR> POST: If an shape was selected, this class will save a copy of it
 void deleteSelectedShape()
          
PRE: None
POST: Delete the selected shape from the list if there is one selected
 void drawAllShapes(java.awt.Graphics g)
          
PRE: A valid Graphics object
POST: Draw all the shape in the list.
 java.awt.Color getSelectedShapeColor()
          
PRE: None
POST: Return the color of the selectedShape color, if no shape is selected, it will return null
 void moveSelectedPointBox(int deltaX, int deltaY)
          
PRE: None
POST: Move the point box of the selected shape object
 void moveSelectedShapeToBack()
          
PRE: None
POST: Move the selected shape one object to the back.
 void moveSelectedShapeToFront()
          
PRE: None
POST: Move the selected shape one object to the front.
 void moveShape(int deltaX, int deltaY)
          
PRE: None
POST: Move the selected Shape of the input offsets
 boolean pasteShape()
          
PRE: NoneBR> POST: If there is a copied shape, will add it to the last in the list and place it to the top left corner and return true.
 boolean selectNextShape()
          
PRE: None
POST: Select the next shape in the list.
 boolean selectPointBox(Point pt)
          
PRE: None
POST: Check if the point in the pointbox of the selecetd shape.
 boolean selectPreviousShape()
          
PRE: None
POST: Select the previous shape in the list.
 boolean selectShape(Point p)
          
PRE: A valid point
POST: Go through the shape list from the top(LIFO) and do hit test on the shape.
 void setSelectedShapeColor(java.awt.Color color)
          
PRE: A valid Color object
POST: Set the selected Shape's color from the input color object only if there is a selected shape
 void setShapeEndPoint(Point p)
          
PRE: A valid Point object
POST: Set the endPoint of the select shape as the input, solely for Resizing
 void unSelectShape()
          
PRE: None
POST: Don't keep track of the selected object
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

shapeList

private java.util.Vector shapeList
A vector list containing shapes

selectedShape

private DrawableShape selectedShape
The shape that is being selected

copyShape

private DrawableShape copyShape
A copied of a shape

bSelectedPointBox

private boolean bSelectedPointBox
A flag to indicate if we have selected a point box in the selected shape
Constructor Detail

DrawPadDoc

public DrawPadDoc()

PRE: None
POST: Construct and initialize the DrawPadDoc Object
Method Detail

addShape

public void addShape(DrawableShape shape)

PRE: A valid DrawableShape object
POST: Add a shape to the list

drawAllShapes

public void drawAllShapes(java.awt.Graphics g)

PRE: A valid Graphics object
POST: Draw all the shape in the list. First one put in the list, first one get drawn first

selectShape

public boolean selectShape(Point p)

PRE: A valid point
POST: Go through the shape list from the top(LIFO) and do hit test on the shape. If a shape if found to be hit, the shape will be saved and return true. If no shape pass the hit test, return false

unSelectShape

public void unSelectShape()

PRE: None
POST: Don't keep track of the selected object

moveShape

public void moveShape(int deltaX,
                      int deltaY)

PRE: None
POST: Move the selected Shape of the input offsets

setShapeEndPoint

public void setShapeEndPoint(Point p)

PRE: A valid Point object
POST: Set the endPoint of the select shape as the input, solely for Resizing

deleteSelectedShape

public void deleteSelectedShape()

PRE: None
POST: Delete the selected shape from the list if there is one selected

selectPointBox

public boolean selectPointBox(Point pt)

PRE: None
POST: Check if the point in the pointbox of the selecetd shape. Will set a boolean flag accordingly

moveSelectedPointBox

public void moveSelectedPointBox(int deltaX,
                                 int deltaY)

PRE: None
POST: Move the point box of the selected shape object

moveSelectedShapeToFront

public void moveSelectedShapeToFront()

PRE: None
POST: Move the selected shape one object to the front. Stay in the front if it is the front most already.

moveSelectedShapeToBack

public void moveSelectedShapeToBack()

PRE: None
POST: Move the selected shape one object to the back. Stay in the back if it is the back most already.

selectNextShape

public boolean selectNextShape()

PRE: None
POST: Select the next shape in the list. Select the same shape if it is already the last in the list. If no selected shape before calling this method, it will choose the first one in the list (if a shape exist in the list)

selectPreviousShape

public boolean selectPreviousShape()

PRE: None
POST: Select the previous shape in the list. Select the same shape if it is already the first in the list. If no selected shape before calling this method, it will choose the last one in the list (if a shape exist in the list)

getSelectedShapeColor

public java.awt.Color getSelectedShapeColor()

PRE: None
POST: Return the color of the selectedShape color, if no shape is selected, it will return null

setSelectedShapeColor

public void setSelectedShapeColor(java.awt.Color color)

PRE: A valid Color object
POST: Set the selected Shape's color from the input color object only if there is a selected shape

copySelectedShape

public void copySelectedShape()

PRE: NoneBR> POST: If an shape was selected, this class will save a copy of it

pasteShape

public boolean pasteShape()

PRE: NoneBR> POST: If there is a copied shape, will add it to the last in the list and place it to the top left corner and return true. Return false otherwise