jdraw.jdraw
Class Canvas

java.lang.Object
  |
  +--java.util.Observable
        |
        +--mvp.Model
              |
              +--jdraw.jdraw.Canvas
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class Canvas
extends mvp.Model
implements java.io.Serializable, java.lang.Cloneable

Class Canvas is the top-level Model class for the drawing canvas.

See Also:
Serialized Form

Field Summary
protected  java.lang.String filename
          Canvas objects also have a filename object.
protected  java.util.Vector graphics
          Canvas contains a vector of graphic objects.
protected  java.util.Vector groups
          A Vector which stores groups (Vectors) of indices.
protected  int id
          A local int value to store this Canvas' id.
protected  boolean needSave
          A boolean value indicating whether this file has been changed.
protected  java.util.Vector selectedGraphics
          A Vector which stores indices to GraphicObject's in Vector graphics.
 
Fields inherited from class mvp.Model
view
 
Constructor Summary
Canvas(mvp.View view, int thisID)
          Construct this with the given View component.
Canvas(mvp.View view, int thisID, java.lang.String filename)
           
Canvas(mvp.View view, int thisID, java.lang.String filename, java.util.Vector graphics, java.util.Vector groups)
          Second Constructor is for opening files ...
 
Method Summary
 void addGraphicObject(GraphicObject gObj)
          Adds the passed in GraphicObject to the Vector graphics.
 void addGraphicObject(java.util.Vector junkBundle)
          Adds the GraphicObject, defined by the Vector junkBundle to the Canvas.
 void bringSelectedToFront()
          Makes calls to bring each selected graphic towards the front.
 void bringToFront(int newFrontIndex)
          Rearranges the graphics list such that the item previously at index, newBackIndex is now first in the list.
 java.lang.Object clone()
           
 void decrementID()
          Decrease this.id by one.
 java.lang.String getFilename()
           
 GraphicObject getGraphic(int i)
          Returns the GraphicObject found in Vector graphics at index i.
 java.util.Vector getGraphics()
          Returns the Vector stored in graphics.
 java.util.Vector getGroups()
           
 int getID()
          Returns the int value in this.id.
 boolean getNeedSave()
           
 int getNumberOfGraphics()
           
 java.awt.Rectangle getSelectedBoundingRectangle()
          Returns the smallest Rectangle which contains all the shapes referenced in selectedGraphics.
 java.util.Vector getSelectedGraphics()
          Returns the Vector stored in selectedGraphics.
 java.util.Vector getSelectedShapes()
           
 java.util.Vector getTouchedGroup(java.awt.Point pt)
          Method getTouchedGroup(Point pt) returns the closest graphic (or the group with the closest graphic) to the point passed.
 void groupSelected()
          If the Vector in selectedGraphics does not equal one of the groups, then add a new group which contains everything in selectedGraphics.
 void rotateSelectedFromPoints(java.awt.Point a, java.awt.Point b)
           
 void selectAll()
          Selects all graphics in this Canvas.
 void sendSelectedToBack()
          Makes calls to send each selected graphic towards the back.
 void sendToBack(int newBackIndex)
          Rearranges the graphics list such that the item previously at index, newBackIndex is now last in the list.
 void setFilename(java.lang.String newFilename)
           
 void setNeedSave(boolean trueOrFalse)
           
 void setSelectedGraphics(java.util.Vector newSelected)
          Sets the passed in Vector to selectedGraphics.
 void ungroupSelected()
          If any Group Vector contains everything in selectedGraphics, then remove that group from groups.
 
Methods inherited from class mvp.Model
getView, setView
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

graphics

protected java.util.Vector graphics
Canvas contains a vector of graphic objects.

filename

protected java.lang.String filename
Canvas objects also have a filename object.

id

protected int id
A local int value to store this Canvas' id.

selectedGraphics

protected java.util.Vector selectedGraphics
A Vector which stores indices to GraphicObject's in Vector graphics.

groups

protected java.util.Vector groups
A Vector which stores groups (Vectors) of indices.

needSave

protected boolean needSave
A boolean value indicating whether this file has been changed.
Constructor Detail

Canvas

public Canvas(mvp.View view,
              int thisID)
Construct this with the given View component. Initialize the graphics Vector and set filename = null.
Parameters:
view - - The View object to be passed to the parent constructor.
thisID - - The int value to be used as this.id.

Canvas

public Canvas(mvp.View view,
              int thisID,
              java.lang.String filename)
Parameters:
view - - The View object to be passed to the parent constructor.
thisID - - The int value to be used as this.id.
filename - - The String to be set as this.filename.

Canvas

public Canvas(mvp.View view,
              int thisID,
              java.lang.String filename,
              java.util.Vector graphics,
              java.util.Vector groups)
Second Constructor is for opening files ... to maintain the filename we loaded from.
Parameters:
view - - The View object to be passed to the parent constructor.
thisID - - The int value to be used as this.id.
filename - - The String to be set as this.filename.
graphics - - A Vector of graphics to be placed in this.
groups - - A Vector of Vectors of Integers, defining group affiliations.
Method Detail

getGroups

public java.util.Vector getGroups()

getID

public int getID()
Returns the int value in this.id.
Returns:
- The int value stored in this.id.

getSelectedBoundingRectangle

public java.awt.Rectangle getSelectedBoundingRectangle()
Returns the smallest Rectangle which contains all the shapes referenced in selectedGraphics.
Returns:
- The smallest bounding Rectangle of selectedGraphics.

setSelectedGraphics

public void setSelectedGraphics(java.util.Vector newSelected)
Sets the passed in Vector to selectedGraphics.
Parameters:
newSelected - - The Vector to be set in selectedGraphics.

getSelectedGraphics

public java.util.Vector getSelectedGraphics()
Returns the Vector stored in selectedGraphics.
Returns:
- The Vector stored in selectedGraphics.

getNumberOfGraphics

public int getNumberOfGraphics()

getFilename

public java.lang.String getFilename()

setFilename

public void setFilename(java.lang.String newFilename)
Parameters:
newFilename - - String to be stored in this.filename.

setNeedSave

public void setNeedSave(boolean trueOrFalse)
Parameters:
trueOrFalse - - A boolean value indicating whether the file has been changed.

getNeedSave

public boolean getNeedSave()

getGraphics

public java.util.Vector getGraphics()
Returns the Vector stored in graphics.
Returns:
- The Vector stored in graphics.

getGraphic

public GraphicObject getGraphic(int i)
Returns the GraphicObject found in Vector graphics at index i.
Parameters:
i - - The int representing an index in graphics.
Returns:
- The GraphicObject stored in Vector graphics at index i.

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

getTouchedGroup

public java.util.Vector getTouchedGroup(java.awt.Point pt)
Method getTouchedGroup(Point pt) returns the closest graphic (or the group with the closest graphic) to the point passed. The closest graphic is said to be the last one which contains the point. The graphic(s) are returned in a Vector to allow for the ambiguity.
Parameters:
pt - - The Point object whose containment we want to determine.
Returns:
- A Vector holding the last GraphicObject that contains the point and all the GraphicObject in that last one's largest group (if it is in any groups).

groupSelected

public void groupSelected()
If the Vector in selectedGraphics does not equal one of the groups, then add a new group which contains everything in selectedGraphics.

ungroupSelected

public void ungroupSelected()
If any Group Vector contains everything in selectedGraphics, then remove that group from groups.

selectAll

public void selectAll()
Selects all graphics in this Canvas.

rotateSelectedFromPoints

public void rotateSelectedFromPoints(java.awt.Point a,
                                     java.awt.Point b)

getSelectedShapes

public java.util.Vector getSelectedShapes()

addGraphicObject

public void addGraphicObject(GraphicObject gObj)
Adds the passed in GraphicObject to the Vector graphics.
Parameters:
gObj - - The GraphicObject to be added to Vector graphics.

addGraphicObject

public void addGraphicObject(java.util.Vector junkBundle)
Adds the GraphicObject, defined by the Vector junkBundle to the Canvas.
Parameters:
junkBundle - - The Vector containing all the necessary information to rebuild the shape.

decrementID

public void decrementID()
Decrease this.id by one.

bringSelectedToFront

public void bringSelectedToFront()
Makes calls to bring each selected graphic towards the front.

sendSelectedToBack

public void sendSelectedToBack()
Makes calls to send each selected graphic towards the back.

bringToFront

public void bringToFront(int newFrontIndex)
Rearranges the graphics list such that the item previously at index, newBackIndex is now first in the list. Also changes references to this index in Selected Graphics and Groups lists.

sendToBack

public void sendToBack(int newBackIndex)
Rearranges the graphics list such that the item previously at index, newBackIndex is now last in the list. Also changes references to this index in Selected Graphics and Groups lists.