Class eraserTool

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

public class eraserTool
extends java.lang.Object
implements ourTool

This is a class for the eraser tool which is located at row 2 column 1 of the drawing icon. It allows the user to erase what has been drawn. It should work with all operating systems and hardware. There are no variances and no security constraints.


Field Summary
(package private)  java.awt.image.BufferedImage eraseImage
          Holds the BufferedImage that we use to create the graphic to do the erasing.
 int eraserSize
          Holds the size of the eraser.
(package private)  java.awt.Graphics2D g2D
          Holds the graphic that is actually used to erase.
(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
eraserTool()
          Creates an eraserTool and initializes its size to 6.
 
Method Summary
 void clickAction(java.awt.event.MouseEvent mevt, main_canvas theCanvas)
          Allows the user to click on the canvas using the eraserTool.
 void dragAction(java.awt.event.MouseEvent mevt, main_canvas theCanvas)
          Allows the user to drag the mouse using the eraserTool, and therefore, allows the user to erase until the mouse is released.
 java.awt.Shape getEraserShape(int x, int y)
          Returns the Shape of the eraserTool, as specified by the x and y values passed in.
 int getEraserSize()
          Returns the size of the eraser as an int.
 java.awt.Color getG2dColor()
          This function returns the color set to the private data member g2d.
 void mouseReleaseAction(java.awt.event.MouseEvent mevt, main_canvas theCanvas)
          Allows the user to release the mouse, and therefore stop the erasing process.
 void setEraserSize(int newSize)
          Sets the size of the eraser, as specified by the int parameter passed in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

g2D

java.awt.Graphics2D g2D
Holds the graphic that is actually used to erase.


eraseImage

java.awt.image.BufferedImage eraseImage
Holds the BufferedImage that we use to create the graphic to do the erasing.


eraserSize

public int eraserSize
Holds the size of the eraser. It is initialized to 6 at the constructor.


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

eraserTool

public eraserTool()
Creates an eraserTool and initializes its size to 6. 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 on the canvas using the eraserTool. It will get the BufferedImage from the canvas and prepare to draw a graphic onto it. It has 2 parameters. The MouseEvent holds the button that was clicked on (either left or right) and gets the coordinate of where the mouse is clicked. The second parameter is the main_canvas which is the area that can be erased.

Specified by:
clickAction in interface ourTool
Parameters:
mevt - A MouseEvent object for showing which button in the mouse is clicked and the coordinate of where the mouse is clicked.
theCanvas - A main_canvas object which is the area that we are going to erase.

dragAction

public void dragAction(java.awt.event.MouseEvent mevt,
                       main_canvas theCanvas)
Allows the user to drag the mouse using the eraserTool, and therefore, allows the user to erase until the mouse is released. It has 2 parameters. The first one is a MouseEvent and it is to check which button in the mouse is clicked and to get the coordinate of where the mouse is clicked. The second parameter is the canvas which is the area that we are going to erase.

Specified by:
dragAction in interface ourTool
Parameters:
mevt - A MouseEvent object for showing which button in the mouse is clicked and the coordinate of where the mouse is clicked.
theCanvas - A main_canvas object which is the area that we are going to erase.

mouseReleaseAction

public void mouseReleaseAction(java.awt.event.MouseEvent mevt,
                               main_canvas theCanvas)
Allows the user to release the mouse, and therefore stop the erasing process. It has 2 parameters. The first one is a MouseEvent and it is to check which button in the mouse is clicked and to get the coordinate of where the mouse is clicked. The second parameter is the canvas which is the area that we are going to erase.

Specified by:
mouseReleaseAction in interface ourTool
Parameters:
mevt - A MouseEvent object for showing which button in the mouse is clicked and the coordinate of where the mouse is clicked.
theCanvas - A main_canvas object which is the area that we are going to erase.

getG2dColor

public java.awt.Color getG2dColor()
This function returns the color set to the private data member g2d.

Returns:
Color representing g2d

getEraserShape

public java.awt.Shape getEraserShape(int x,
                                     int y)
Returns the Shape of the eraserTool, as specified by the x and y values passed in. It will return a Rectangle object which is the eraser. It has 2 int parameters which is for the coordinate of x and y.

Parameters:
x - for x coordinate.
y - for y coordinate.
Returns:
Returns a Rectangular object which is the eraser.

setEraserSize

public void setEraserSize(int newSize)
Sets the size of the eraser, as specified by the int parameter passed in.

Parameters:
newSize - int value.
See Also:
getEraserSize()

getEraserSize

public int getEraserSize()
Returns the size of the eraser as an int.

Returns:
int eraserSize
See Also:
setEraserSize(int)