Class polygonTool

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

public class polygonTool
extends java.lang.Object
implements ourTool

A polygonTool implements the operations performed by a polygon. It holds the fields int lastX, lastY, curX, curY, Graphics2D polyG2D, BufferedImage polyImage, backupImage, boolean dragged, Polygon, curPolygon, private int fillType. The variable dragged is set to true only when the method dragAction is called and is set to false otherwise. The fillType is assigned as follows: 1=set the color of the border. 2=set the color of the border and the fill. otherwise only set the color of the fill. 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 backupImage
          a BufferedImage with width set to 200 and height set to 200.
(package private)  java.awt.Polygon curPolygon
          used within methods clickAction, mouseReleaseAction and deSelect.
(package private)  int curX
          used in clickAction and mouseReleaseAction.
(package private)  int curY
          used in clickAction and mouseReleaseAction.
 boolean dragged
          initialized to false, but set to true when dragAction is called.
private  int fillType
          Initialized to 1 as default.
(package private)  int lastX
          used in clickAction and mouseReleaseAction.
(package private)  int lastY
          used in clickAction and mouseReleaseAction.
(package private)  java.awt.Graphics2D polyG2D
          used to create a polygon.
(package private)  java.awt.image.BufferedImage polyImage
          a BufferedImage with width set to 200 and height set to 200.
 
Constructor Summary
polygonTool()
          Creates a polygonTool object.
 
Method Summary
 void clickAction(java.awt.event.MouseEvent evt, main_canvas theCanvas)
          allows the user to click on the canvas, using the polygonTool.
 void deSelect(main_canvas theCanvas)
          Allows for the deselecting of the polygon.
 void dragAction(java.awt.event.MouseEvent evt, main_canvas theCanvas)
          Allows the user to drag the mouse on the canvas, using the polygonTool.
 boolean getDragged()
          Returns the current state of the flag dragged.
 int getFillType()
          Returns the fill type, which should range from 1-3.
 java.awt.Color getG2dColor()
          Returns a Color corresponding to the private Graphics2D.
 void mouseReleaseAction(java.awt.event.MouseEvent evt, main_canvas theCanvas)
          Allows the user to release the mouse, and the method dragAction was called (and therefore dragged was set to true), it sets the curX and curY and adds a point to curPolygon with those coordinates.
 void setFillType(int theFillType)
          Sets fillType to the int passed in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lastX

int lastX
used in clickAction and mouseReleaseAction.


lastY

int lastY
used in clickAction and mouseReleaseAction.


curX

int curX
used in clickAction and mouseReleaseAction.


curY

int curY
used in clickAction and mouseReleaseAction.


polyG2D

java.awt.Graphics2D polyG2D
used to create a polygon.


polyImage

java.awt.image.BufferedImage polyImage
a BufferedImage with width set to 200 and height set to 200.


backupImage

java.awt.image.BufferedImage backupImage
a BufferedImage with width set to 200 and height set to 200.


dragged

public boolean dragged
initialized to false, but set to true when dragAction is called.


curPolygon

java.awt.Polygon curPolygon
used within methods clickAction, mouseReleaseAction and deSelect.


fillType

private int fillType
Initialized to 1 as default. The following reflects modifications made when changing fillType in setFillType: 1-set the color of the border. 2-set the color of the border and the fill. Otherwise set the color of the fill.

Constructor Detail

polygonTool

polygonTool()
Creates a polygonTool 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 evt,
                        main_canvas theCanvas)
allows the user to click on the canvas, using the polygonTool. If the evt's click count is less than 2 and dragAction has not been called, then lastX and lastY are set and these are used to addPoints within the curPolygon. The image of the polygon is backed up into backupImage. Otherwise, if the dragAction has been called, then curX and curY are set and that coordinate is added to curPolygon. If the leftMouseButton is clicked, then the color is set to the left color. Otherwise, it is set to the right color. If the fill type is 1, then the border is drawn. If the fill type is 2 and the leftMouseButton is used, then the border is set to the left color and the fill is set to the right color. Otherwise, the border is set to the right color and the fill is set to the left color. If the fill is not 1 or 2, then only the fill color is set.

Specified by:
clickAction in interface ourTool
Parameters:
evt - holds a MouseEvent to set the lastX and lastY fields.
theCanvas - holds a main_canvas

dragAction

public void dragAction(java.awt.event.MouseEvent evt,
                       main_canvas theCanvas)
Allows the user to drag the mouse on the canvas, using the polygonTool. It sets the field dragged to true. If the LeftMouseButton is used, it sets the color to the left color. Otherwise it is set to the right color.

Specified by:
dragAction in interface ourTool
Parameters:
evt - holds a MouseEvent to determine which side was clicked.
theCanvas - holds a main_canvas to set the colors.

mouseReleaseAction

public void mouseReleaseAction(java.awt.event.MouseEvent evt,
                               main_canvas theCanvas)
Allows the user to release the mouse, and the method dragAction was called (and therefore dragged was set to true), it sets the curX and curY and adds a point to curPolygon with those coordinates. If the leftMouseButton is used, it sets the color to the left. Otherwise, it sets the color to the right. It resets the fields lastX and lastY to those of curX and curY.

Specified by:
mouseReleaseAction in interface ourTool
Parameters:
evt - holds a MouseEvent to determine which side was clicked.
theCanvas - determines which side to color.

setFillType

public void setFillType(int theFillType)
Sets fillType to the int passed in.

Parameters:
theFillType - holds an integer corresponding to the values given above.
See Also:
getFillType()

getFillType

public int getFillType()
Returns the fill type, which should range from 1-3.

Returns:
an int
See Also:
setFillType(int)

deSelect

public void deSelect(main_canvas theCanvas)
Allows for the deselecting of the polygon. Can only deselect if the dragAction was called (and now dragged is set to true). Therefore: If the fillType is 1, then it draws the polygon with the border. If the fillType is 2, and the leftmouseButton is used, the border is used with the left color and the fill is used with the right color. Otherwise, the fill is used as the left color and the border as the right. If the fillType is not 1 or 2, then the fill color is set. Dragged is set to false.

Parameters:
theCanvas - holds a main_canvas used to set the colors.

getDragged

public boolean getDragged()
Returns the current state of the flag dragged.

Returns:
a boolean corresponding to the flag dragged

getG2dColor

public java.awt.Color getG2dColor()
Returns a Color corresponding to the private Graphics2D.

Returns:
Color corresponding to that of the Graphics2D