Class pencilTool

java.lang.Object
  extended by pencilTool
All Implemented Interfaces:
ourTool

public class pencilTool
extends java.lang.Object
implements ourTool

A pencilTool implements the operations performed by a pencil. It holds the fields int prevX and prevY, BufferedImage pencilImage and Graphics2D g2D. The variables prevX and prevY retain the values of x and y at the end of the methods clickAction and DragAction. It should work with all operating systems and hardware. There are no variances and no security constraints.


Field Summary
(package private)  java.awt.Graphics2D g2D
          holds a Graphics2D.
(package private)  java.awt.image.BufferedImage pencilImage
          holds a BufferedImage.
(package private)  int prevX
          used to initialize the start of the x and y values.
(package private)  int prevY
          used to initialize the start of the x and y values.
 
Constructor Summary
pencilTool()
          Creates a pencilTool object.
 
Method Summary
 void clickAction(java.awt.event.MouseEvent mevt, main_canvas theCanvas)
          Allows the user to click the mouse, using the pencilTool.
 void dragAction(java.awt.event.MouseEvent mevt, main_canvas theCanvas)
          Allows the user to drag the mouse, using the pencil tool once the mouse has been clicked.
 int getPrevX()
          Returns the value of the data member prevX.
 int getPrevY()
          Returns the value of the data member prevY.
 java.awt.Stroke getStroke()
          Returns the Stroke of g2d.
 void mouseReleaseAction(java.awt.event.MouseEvent mevt, main_canvas theCanvas)
          Allows the user to release the mouse, using the pencilTool, once the mouse has been clicked on and clickAction has been called.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pencilImage

java.awt.image.BufferedImage pencilImage
holds a BufferedImage.


g2D

java.awt.Graphics2D g2D
holds a Graphics2D.


prevX

int prevX
used to initialize the start of the x and y values.


prevY

int prevY
used to initialize the start of the x and y values.

Constructor Detail

pencilTool

public pencilTool()
Creates a pencilTool object. It takes in no parameters or null arguments. It does not return anything. There are no algorithms of any kind and no variances and OS dependencies. There should not be any exceptions or security constraints.

Method Detail

clickAction

public void clickAction(java.awt.event.MouseEvent mevt,
                        main_canvas theCanvas)
Allows the user to click the mouse, using the pencilTool. Sets pencilImage and the x and y values to those passed in by MouseEvent. If the LeftMouseButton is used, then a pixel is set to pencilImage with the specified RGB value of the left color. Otherwise, it is set with the right color. The prevX and prevY are initialized to the x and y values respectively.

Specified by:
clickAction in interface ourTool
Parameters:
mevt - holds a MouseEvent to call getX() and getY() to set the x and y values
theCanvas - holds a main_canvas to retrieve the mevt's x and y values.

getPrevX

public int getPrevX()
Returns the value of the data member prevX.

Returns:
int

getPrevY

public int getPrevY()
Returns the value of the data member prevY.

Returns:
int prevY

dragAction

public void dragAction(java.awt.event.MouseEvent mevt,
                       main_canvas theCanvas)
Allows the user to drag the mouse, using the pencil tool once the mouse has been clicked. If the leftMouseButton is used, the g2D's color is set to the left color, otherwise it is set to the right color. setStroke sets the the Stroke for the Graphic2D context and the Stroke object passed in is to be used to stroke a Shape during the rendering process. It resets the prevX and prevY to reflect the x and y values.

Specified by:
dragAction in interface ourTool
Parameters:
mevt - holds a MouseEvent to call getX() and getY() to set the x and y values.
theCanvas - holds a main_canvas to retrieve the mevt's x and y values and left and right colors.

mouseReleaseAction

public void mouseReleaseAction(java.awt.event.MouseEvent mevt,
                               main_canvas theCanvas)
Allows the user to release the mouse, using the pencilTool, once the mouse has been clicked on and clickAction has been called. If the leftMouseButton is used, the g2D's color is set to the left color, otherwise it is set to the right color. setStroke sets the the Stroke for the Graphic2D context and the Stroke object passed in is to be used to stroke a Shape during the rendering process. It resets the prevX and prevY to reflect the x and y values. NOTE: it seems to be a direct copy of the method dragAction except that the prevX and prevY values are not reset.

Specified by:
mouseReleaseAction in interface ourTool
Parameters:
mevt - mevt holds a MouseEvent to call getX() and getY() to set the x and y values.
theCanvas - holds a main_canvas to retrieve the mevt's x and y values and left and right colors.

getStroke

public java.awt.Stroke getStroke()
Returns the Stroke of g2d.

Returns:
Stroke