jdraw.jdraw_ui
Class CanvasWindow

java.lang.Object
  |
  +--mvp.View
        |
        +--jdraw.jdraw_ui.CanvasWindow
All Implemented Interfaces:
java.util.Observer

public class CanvasWindow
extends mvp.View

Class CanvasWindow is the companion View class for the Canvas Model. It consists of a simple JScrollPane.


Field Summary
protected  java.awt.Color backgroundColor
          Color object backgroundColor holds the value of this Canvas' background color.
protected  Canvas canvas
          A local reference to the companion Model object.
protected  CanvasPage canvasPage
          CanvasPage object canvasPage is the JPanel in this.window where the graphics are actually displayed.
protected  int currentControlObject
          An int which stores the index of the graphic whose control point is currently being reshaped.
protected  int currentControlPoint
          An int which stores the index of the control point which is currently being reshaped.
protected  java.awt.Point currentPoint
          Point object currentPoint is needed to hold the position of the mouse when a button is first clicked.
protected  GraphicObject graphicObject
          A GraphicObject instance where graphics are stored as they're being created.
protected  int graphicType
          int object graphicType holds the integer representation of the active Graphic Tool.
protected  JDraw jdraw
          A local reference to the top-level JDraw object.
protected  JDrawKeyListener keyListener
          The overall Key Listener.
protected  java.util.Vector redoBuffer
          A Vector to store Canvas objects for redo purposes.
protected  Tools tools
          A local reference to the upper-level Tools object.
protected  java.util.Vector undoBuffer
          A Vector to store Canvas objects for undo purposes.
protected  javax.swing.JScrollPane windowPane
          A JScrollPane in which to put our CanvasPage.
protected  float zoom
          A float value to store this window's current zoom factor.
 
Fields inherited from class mvp.View
editable, model, screen, shown, widget, window
 
Constructor Summary
CanvasWindow(mvp.Screen screen, Canvas canvas, Tools tools, JDrawKeyListener keyListener)
          Construct this with the given Screen, Canvas, and Tools components.
 
Method Summary
 void closeWindow()
           
 java.awt.Component compose()
          Compose this by creating a new window.
 void dragLeft(java.awt.event.MouseEvent e)
          Method leftDrag(MouseEvent) is called by CanvasMouseListener when appropriate.
 Canvas getCanvas()
          Method getCanvas() returns the current Canvas object in this.canvas.
 CanvasPage getCanvasPage()
           
 java.awt.Point getCurrentPoint()
          Method getCurrentPoint() returns the current Point object.
 GraphicObject getGraphicObject()
           
 int getGraphicType()
          Method getGraphicType() returns the current integer value in this.graphicType.
 JDraw getJDraw()
           
 boolean getNeedSave()
          Method getNeedSave() returns this.needSave.
 java.util.Vector getSelectedGraphics()
           
 mvp.Window getWindow()
           
 java.awt.Dimension getWindowSize()
           
 float getZoom()
           
 void leftPress(java.awt.event.MouseEvent e)
          Method leftPress(MouseEvent) is called by CanvasMouseListener when appropriate.
 void leftRelease(java.awt.event.MouseEvent e)
          Method leftRelease(MouseEvent) is called by CanvasMouseListener when appropriate.
 void middleDrag(java.awt.event.MouseEvent e)
          This method should be just like the move item ...
 void middlePress(java.awt.event.MouseEvent e)
          This method should be just like the move item ...
 void normalDrag(java.awt.event.MouseEvent e)
          Method normalDrag(MouseEvent) is called by CanvasMouseListener when appropriate.
 void passKeyEvent(java.awt.event.KeyEvent e)
           
 void redoLastUndo()
          Loads the last element of the redo buffer into this.canvas.
 void redrawPage()
          Calls the redraw method of this.canvasPage.
 void rightPress(java.awt.event.MouseEvent e)
          Method rightPress(MouseEvent) is called by CanvasMouseListener when appropriate.
 void saveCanvasState()
          Copies this.canvas into the undo buffer.
 void setAllSelected()
          Calls selectAll on this.canvas.
 void setJDraw(JDraw jDraw)
          Method setJDraw(JDraw) sets this.jdraw to the parameter JDraw object.
 void setNeedSave(boolean trueorfalse)
          Method setNeedSave(boolean) sets this.needSave to the boolean parameter.
 void setToHome()
          Method setToHome adjusts this.windowPane so that it's upper left corner is the upper left corner of the entire Canvas.
 void setWindow(int x)
          Offset a window given the number of current windows.
 void setWindowTitle(java.lang.String title)
          Method setWindowTitle(String) sets the current window's Title to the parameter String object.
 void setZoom(float zoom)
           
 void undoLastAction()
          Loads the last element of the undo buffer into this.canvas.
 
Methods inherited from class mvp.View
getModel, getWidget, hide, isEditable, isShown, run, setEditable, setModel, show, show, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

canvas

protected Canvas canvas
A local reference to the companion Model object.

jdraw

protected JDraw jdraw
A local reference to the top-level JDraw object.

tools

protected Tools tools
A local reference to the upper-level Tools object.

currentPoint

protected java.awt.Point currentPoint
Point object currentPoint is needed to hold the position of the mouse when a button is first clicked.

canvasPage

protected CanvasPage canvasPage
CanvasPage object canvasPage is the JPanel in this.window where the graphics are actually displayed. Its methods actually draw the Shapes onscreen.

graphicType

protected int graphicType
int object graphicType holds the integer representation of the active Graphic Tool.

backgroundColor

protected java.awt.Color backgroundColor
Color object backgroundColor holds the value of this Canvas' background color.

currentControlObject

protected int currentControlObject
An int which stores the index of the graphic whose control point is currently being reshaped. If there is no such graphic, this is set to -1.

currentControlPoint

protected int currentControlPoint
An int which stores the index of the control point which is currently being reshaped. If there is no such control point, this is set to -1.

windowPane

protected javax.swing.JScrollPane windowPane
A JScrollPane in which to put our CanvasPage.

graphicObject

protected GraphicObject graphicObject
A GraphicObject instance where graphics are stored as they're being created.

undoBuffer

protected java.util.Vector undoBuffer
A Vector to store Canvas objects for undo purposes.

redoBuffer

protected java.util.Vector redoBuffer
A Vector to store Canvas objects for redo purposes.

keyListener

protected JDrawKeyListener keyListener
The overall Key Listener.

zoom

protected float zoom
A float value to store this window's current zoom factor.
Constructor Detail

CanvasWindow

public CanvasWindow(mvp.Screen screen,
                    Canvas canvas,
                    Tools tools,
                    JDrawKeyListener keyListener)
Construct this with the given Screen, Canvas, and Tools components.
Parameters:
screen - - Screen object on which to write.
canvas - - Corresponding Model object.
tools - - Top-Level Tools object.
Method Detail

compose

public java.awt.Component compose()
Compose this by creating a new window. This window contains the viewable content of the companion Canvas object.
Overrides:
compose in class mvp.View
Returns:
widget - The viewable representation of this.

getWindow

public mvp.Window getWindow()
Overrides:
getWindow in class mvp.View

getCanvasPage

public CanvasPage getCanvasPage()

leftPress

public void leftPress(java.awt.event.MouseEvent e)
Method leftPress(MouseEvent) is called by CanvasMouseListener when appropriate. It determines what the active Graphics Tools is and as such what actions should occur.
Parameters:
e - - The MouseEvent object which has been passed from the window listener.

leftRelease

public void leftRelease(java.awt.event.MouseEvent e)
Method leftRelease(MouseEvent) is called by CanvasMouseListener when appropriate. It determines what the active Graphics Tool is and as such what actions should occur.
Parameters:
e - - The MouseEvent object which has been passed from the window listener.

dragLeft

public void dragLeft(java.awt.event.MouseEvent e)
Method leftDrag(MouseEvent) is called by CanvasMouseListener when appropriate. It determines what the active Graphics Tool is and as such what actions should occur.
Parameters:
e - - The MouseEvent object which has been passed from the window listener.

normalDrag

public void normalDrag(java.awt.event.MouseEvent e)
Method normalDrag(MouseEvent) is called by CanvasMouseListener when appropriate. It determines what the active Graphics Tool is and as such what actions should occur.
Parameters:
e - - The MouseEvent object which has been passed from the window listener.

rightPress

public void rightPress(java.awt.event.MouseEvent e)
Method rightPress(MouseEvent) is called by CanvasMouseListener when appropriate. It determines what the active Graphics Tool is and as such what actions should occur.
Parameters:
e - - The MouseEvent object which has been passed from the window listener.

middlePress

public void middlePress(java.awt.event.MouseEvent e)
This method should be just like the move item ... still working on it.

middleDrag

public void middleDrag(java.awt.event.MouseEvent e)
This method should be just like the move item ... still working on it.

saveCanvasState

public void saveCanvasState()
Copies this.canvas into the undo buffer.

undoLastAction

public void undoLastAction()
Loads the last element of the undo buffer into this.canvas.

redoLastUndo

public void redoLastUndo()
Loads the last element of the redo buffer into this.canvas.

setAllSelected

public void setAllSelected()
Calls selectAll on this.canvas.

getSelectedGraphics

public java.util.Vector getSelectedGraphics()

getGraphicType

public int getGraphicType()
Method getGraphicType() returns the current integer value in this.graphicType.

getGraphicObject

public GraphicObject getGraphicObject()

getCanvas

public Canvas getCanvas()
Method getCanvas() returns the current Canvas object in this.canvas.

getNeedSave

public boolean getNeedSave()
Method getNeedSave() returns this.needSave.

getCurrentPoint

public java.awt.Point getCurrentPoint()
Method getCurrentPoint() returns the current Point object.

setJDraw

public void setJDraw(JDraw jDraw)
Method setJDraw(JDraw) sets this.jdraw to the parameter JDraw object.

getJDraw

public JDraw getJDraw()

setNeedSave

public void setNeedSave(boolean trueorfalse)
Method setNeedSave(boolean) sets this.needSave to the boolean parameter.

setWindow

public void setWindow(int x)
Offset a window given the number of current windows. Used to keep layers from piling up on top of each other.

setWindowTitle

public void setWindowTitle(java.lang.String title)
Method setWindowTitle(String) sets the current window's Title to the parameter String object.

closeWindow

public void closeWindow()

redrawPage

public void redrawPage()
Calls the redraw method of this.canvasPage.

getWindowSize

public java.awt.Dimension getWindowSize()

passKeyEvent

public void passKeyEvent(java.awt.event.KeyEvent e)

setToHome

public void setToHome()
Method setToHome adjusts this.windowPane so that it's upper left corner is the upper left corner of the entire Canvas.

setZoom

public void setZoom(float zoom)
Parameters:
zoom - - The float value to be stored in this.zoom.

getZoom

public float getZoom()