Class curveTool

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

public class curveTool
extends java.lang.Object
implements ourTool

This is a class for the curve tool which is located at row 6 column 2 of the drawing icon. It allows us to use the mouse to draw a line into a curve shape and we can also drag the mouse and move it around, changing the curve. The curve can also be any color chosen from the bottom of the TerpPaint. Also we can specify the thickness of the curve. It should work with all operating systems and hardware. There are no variances and no security constraints.


Field Summary
private  java.awt.image.BufferedImage backupImage
          This is used to store the back up image that we want and then, we are going to modify this as we continue the drawing of the curve.
 int clicks
          This is used as a flag, showing which state are you at.
private  java.awt.image.BufferedImage curImage
          This is used to store the current Image that we have.
private  java.awt.Stroke curveStroke
          This is used as the line attributes for the Graphics2D.
private  boolean dragged
          This is a boolean used to indicate whether the mouse has been dragged or not.
private  int firstX
          This is used to store the x coordinate of the place where the mouse is clicked.
private  int firstY
          This is used to store the y coordinate of the place where the mouse is clicked.
private  java.awt.Graphics2D g2D
          This is a 2D graphic which is used to draw the line.
private  int lineEndX
          This is used to store the end of the line for the x coordinate.
private  int lineEndY
          This is used to store the end of the line for the y coordinate.
private  int secondX
          This is used as a backup for the integer firstX during state 2.
private  int secondY
          This is used as a backup for the integer firstY during state 2.
private  int startX
          This is used to store the starting location of the curve line for the x coordinate.
private  int startY
          This is used to store the starting location of the curve line for the y coordinate.
 
Constructor Summary
curveTool()
          Creates a curveTool and initializes the curveStroke to 1.
 
Method Summary
 void clickAction(java.awt.event.MouseEvent mevt, main_canvas theCanvas)
          Allows the user to click on the cavas using the curveTool.
 void deSelect(main_canvas theCanvas)
          Sets the width of the curved line and will draw the the curved line if the state is not state 1.
 void dragAction(java.awt.event.MouseEvent mevt, main_canvas theCanvas)
          Allows the user to drag the mouse using the curveTool.
 void drawCurve(java.awt.event.MouseEvent mevt, java.awt.Graphics2D g2D, main_canvas theCanvas)
          Draws a curve once the mouse has been clicked more than once.
 void drawLine(java.awt.event.MouseEvent mevt, java.awt.Graphics2D g2D, main_canvas theCanvas)
          Draws one straight line once the user clicks on the canvas.
 int getClicks()
          Returns the number of clicks, between 1 and 3.
 java.awt.Stroke getCurveStroke()
          Returns the curveStroke of the current curveTool.
 boolean getDragged()
          This function returns the current state of the flag dragged.
 int getfirstX()
          This function returns the value for firstX.
 int getfirstY()
          This function returns the value for firstY.
 java.awt.Color getG2dColor()
          Returns the Color of the Graphics2D, g2d.
 int getSecondX()
          This function returns the value for secondX.
 int getSecondY()
          This function returns the value for secondY.
 int getStartX()
          This function returns the value for startX.
 int getStartY()
          This function returns the value for startY.
 void mouseReleaseAction(java.awt.event.MouseEvent mevt, main_canvas theCanvas)
          Allows the user to release the mouse using curveTool.
 void setClicks(int i)
          Sets the number of clicks, between 1 and 3.
 void setCurveStroke(int size)
          Sets the width of the curveStroke as specified by the int, size, passed in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

startX

private int startX
This is used to store the starting location of the curve line for the x coordinate.


startY

private int startY
This is used to store the starting location of the curve line for the y coordinate.


dragged

private boolean dragged
This is a boolean used to indicate whether the mouse has been dragged or not. It will return true if it has been dragged and false otherwise.


curImage

private java.awt.image.BufferedImage curImage
This is used to store the current Image that we have. We are going to have a back up image so we don't destroy the current image. We are just modifying the back up image.


backupImage

private java.awt.image.BufferedImage backupImage
This is used to store the back up image that we want and then, we are going to modify this as we continue the drawing of the curve.


curveStroke

private java.awt.Stroke curveStroke
This is used as the line attributes for the Graphics2D. It is used to describe the width of the pen.


firstX

private int firstX
This is used to store the x coordinate of the place where the mouse is clicked. It is used when a curved line is going to be drawn.


firstY

private int firstY
This is used to store the y coordinate of the place where the mouse is clicked. It is used when a curved line is going to be drawn.


secondX

private int secondX
This is used as a backup for the integer firstX during state 2. During state 3, it will store as an x coordinate of the place where the mouse is clicked.


secondY

private int secondY
This is used as a backup for the integer firstY during state 2. During state 3, it will store as an y coordinate of the place where the mouse is clicked.


lineEndX

private int lineEndX
This is used to store the end of the line for the x coordinate.


lineEndY

private int lineEndY
This is used to store the end of the line for the y coordinate.


clicks

public int clicks
This is used as a flag, showing which state are you at. The state are that you have already drawn a line, you already make a line into a curve or you have nothing at the beginning.


g2D

private java.awt.Graphics2D g2D
This is a 2D graphic which is used to draw the line.

Constructor Detail

curveTool

public curveTool()
Creates a curveTool and initializes the curveStroke to 1. 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 cavas using the curveTool. According to the state in which it is in, for state 1, it wants to begin to draw a new line. For state 2, a line is already drawn and so, a curve is going to be drawn from the existing line when a mouse is clicked. For state 3, it will change the angle of the curve. And after that, the curved line cannot be moved anymore. A new line will be created when the mouse is clicked and dragged.

Specified by:
clickAction in interface ourTool
Parameters:
mevt - a MouseEvent object which is carried out when the mouse is clicked. It will give a new x and y coordinate and with the start and end coordinate, this will create a new curved line.
theCanvas - a main_canvas object which is the area where the graphic is drawn.

getStartY

public int getStartY()
This function returns the value for startY.

Returns:
int representing startY

getStartX

public int getStartX()
This function returns the value for startX.

Returns:
int representing startX

getfirstX

public int getfirstX()
This function returns the value for firstX.

Returns:
int representing firstX

getfirstY

public int getfirstY()
This function returns the value for firstY.

Returns:
int representing firstY

getSecondX

public int getSecondX()
This function returns the value for secondX.

Returns:
int representing secondX

getSecondY

public int getSecondY()
This function returns the value for secondY.

Returns:
int representing secondY

getDragged

public boolean getDragged()
This function returns the current state of the flag dragged. If the mouse was clicked on and dragged, then it returns true. Otherwise, returns false.

Returns:
boolean

dragAction

public void dragAction(java.awt.event.MouseEvent mevt,
                       main_canvas theCanvas)
Allows the user to drag the mouse using the curveTool. According to the state you are in, for state 1, when the mouse a dragged, it will draw a straight line. For state 2, the line will be curved and the curved line will be moving around. For state 3, the curved line will move little bit from the existing shape. And after that, the curved line cannot be moved anymore. A new line will be created when the mouse is clicked and dragged.

Specified by:
dragAction in interface ourTool
Parameters:
mevt - a MouseEvent object which is carried out when the mouse is dragged. It will give a new x and y coordinate and with the start and end coordinate, this will create a new curved line. Note: this action can only be invoked once the user clicks on the cavas, and clickAction is called.
theCanvas - a main_canvas object which is the area where the graphic is drawn.

mouseReleaseAction

public void mouseReleaseAction(java.awt.event.MouseEvent mevt,
                               main_canvas theCanvas)
Allows the user to release the mouse using curveTool. According to the state you are in, for state 1, the line is drawn. Then it turns from state 1 to state 2. In state 2, it draws the curve line and turns from state 2 to state 3. Then, in state 3, it also draws the curved line but then it turns from state 3 back to state 1. So, we cannot modify the existing curve line.

Specified by:
mouseReleaseAction in interface ourTool
Parameters:
mevt - a MouseEvent object which is carried out when the mouse is released. It will give a new x and y coordinate and with the start and end coordinate, this will create a new curved line. Note: this action can only be invoked once the user clicks on the cavas, and clickAction is called.
theCanvas - a main_canvas object which is the area where the graphic is drawn.

drawCurve

public void drawCurve(java.awt.event.MouseEvent mevt,
                      java.awt.Graphics2D g2D,
                      main_canvas theCanvas)
Draws a curve once the mouse has been clicked more than once. Also, it will change the color you have stored in your left mouse button if you click the left button and it will change the color you have stored in your right mouse button if you click on your right button. It sets the width of the line and then, it starts to draw the curved line.

Parameters:
mevt - a MouseEvent object which is used to determine which mouse button is clicked.
g2D - a Graphic object which is used to set the color and draw the line.
theCanvas - a main_canvas object which is the area where the graphic is drawn.

drawLine

public void drawLine(java.awt.event.MouseEvent mevt,
                     java.awt.Graphics2D g2D,
                     main_canvas theCanvas)
Draws one straight line once the user clicks on the canvas. Also, it will change the color you have stored in your left mouse button if you click the left button and it will change the color you have stored in your right mouse button if you click on your right button. It sets the width of the line and then, it starts to draw the straight line.

Parameters:
mevt - a MouseEvent object which is used to determine which mouse button is clicked.
g2D - a Graphic object which is used to set the color and draw the line.
theCanvas - a main_canvas object which is the area where the graphic is drawn.

setCurveStroke

public void setCurveStroke(int size)
Sets the width of the curveStroke as specified by the int, size, passed in.

Parameters:
size - an int value.
See Also:
getCurveStroke()

getCurveStroke

public java.awt.Stroke getCurveStroke()
Returns the curveStroke of the current curveTool.

Returns:
Stroke which was set by size passed in
See Also:
setCurveStroke(int)

deSelect

public void deSelect(main_canvas theCanvas)
Sets the width of the curved line and will draw the the curved line if the state is not state 1. Then, it will set the state to state 1 again after it draws.

Parameters:
theCanvas - a main_canvas object which is the area where the graphic is drawn.

setClicks

public void setClicks(int i)
Sets the number of clicks, between 1 and 3.

Parameters:
i - an integer that represents the number of clicks
See Also:
getClicks()

getClicks

public int getClicks()
Returns the number of clicks, between 1 and 3.

Returns:
int representing clicks
See Also:
setClicks(int)

getG2dColor

public java.awt.Color getG2dColor()
Returns the Color of the Graphics2D, g2d.

Returns:
Color representing the g2d