Class roundedRectTool

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

public class roundedRectTool
extends java.lang.Object
implements ourTool

roundedRectTool implements the interface ourTool. The tool is used to draw rounded rectangles, filled or unfilled. The mouse dragging determines the dimensions of the rounded rectangle to be drawn, when the mouse button is released. Possibility of using right or left button to draw rectangles. The rounded edge is an unadjustable 10. It should work with all operating systems and hardware. There are no variances and no security constraints.


Field Summary
(package private)  int arc_height
          Holds the height of the arc, default set to 10.
(package private)  int arc_length
          Holds the length of the arc, default set to 10.
private  java.awt.image.BufferedImage backupImage
          Holds the current image and the saved backup image.
private  java.awt.image.BufferedImage curImage
          Holds the current image and the saved backup image.
private  boolean dragged
          Used as a flag detecting if the mouse was dragged.
private  int fillType
          Holds the fill type ranging from 1-3.
(package private)  int prevX
          Integer representing the previous x coordinate.
(package private)  int prevY
          Integer representing the previous y coordinate.
private  int startX
          Holds the starting x value.
private  int startY
          Holds the starting y value.
 
Constructor Summary
roundedRectTool()
           
 
Method Summary
 void clickAction(java.awt.event.MouseEvent mevt, main_canvas theCanvas)
          This function initializes the starting point for a corner of the rounded rectangle to be drawn.
 void dragAction(java.awt.event.MouseEvent mevt, main_canvas theCanvas)
          Uses the dragging mouse position as the opposite corner of the rectangle, and repaints the rectangle to be painted as the mouse moves.
 void drawRoundRect(int x, int y, int width, int height, java.awt.event.MouseEvent mevt, java.awt.Graphics2D g2D, main_canvas theCanvas)
          Updates the current display of canvas.
 boolean getDragged()
          This function returns the state of the flag, dragged.
 int getFillType()
          This function returns the fill type value (1-3).
 void mouseReleaseAction(java.awt.event.MouseEvent mevt, main_canvas theCanvas)
          This fuction draws the rounded rectangle onto the canvas upon release of the mouse button.
 void setFillType(int theFillType)
          This funtion determines if the rounded rectangle is shaded or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

startX

private int startX
Holds the starting x value.


startY

private int startY
Holds the starting y value.


dragged

private boolean dragged
Used as a flag detecting if the mouse was dragged.


fillType

private int fillType
Holds the fill type ranging from 1-3.


arc_length

final int arc_length
Holds the length of the arc, default set to 10.

See Also:
Constant Field Values

arc_height

final int arc_height
Holds the height of the arc, default set to 10.

See Also:
Constant Field Values

curImage

private java.awt.image.BufferedImage curImage
Holds the current image and the saved backup image.


backupImage

private java.awt.image.BufferedImage backupImage
Holds the current image and the saved backup image.


prevX

int prevX
Integer representing the previous x coordinate.


prevY

int prevY
Integer representing the previous y coordinate.

Constructor Detail

roundedRectTool

public roundedRectTool()
Method Detail

clickAction

public void clickAction(java.awt.event.MouseEvent mevt,
                        main_canvas theCanvas)
This function initializes the starting point for a corner of the rounded rectangle to be drawn.

Specified by:
clickAction in interface ourTool
Parameters:
mevt - MouseEvent of initial click, left or right button
theCanvas - the current main_canvas

dragAction

public void dragAction(java.awt.event.MouseEvent mevt,
                       main_canvas theCanvas)
Uses the dragging mouse position as the opposite corner of the rectangle, and repaints the rectangle to be painted as the mouse moves.

Specified by:
dragAction in interface ourTool
Parameters:
mevt - MouseEvent of mouse dragging
theCanvas - the current main_canvas

mouseReleaseAction

public void mouseReleaseAction(java.awt.event.MouseEvent mevt,
                               main_canvas theCanvas)
This fuction draws the rounded rectangle onto the canvas upon release of the mouse button.

Specified by:
mouseReleaseAction in interface ourTool
Parameters:
mevt - MouseEvent of releasing the button.
theCanvas - the current main_canvas

setFillType

public void setFillType(int theFillType)
This funtion determines if the rounded rectangle is shaded or not.

Parameters:
theFillType - 1: outline of left_color, 2: filled of right_color, 3: filled of left_color
See Also:
getFillType()

getFillType

public int getFillType()
This function returns the fill type value (1-3).

Returns:
int corresponding to the fill type
See Also:
setFillType(int)

drawRoundRect

public void drawRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          java.awt.event.MouseEvent mevt,
                          java.awt.Graphics2D g2D,
                          main_canvas theCanvas)
Updates the current display of canvas.

Parameters:
x - the x-on-canvas coordinate of initial click
y - the y-on-canvas coordinate of initial click
width - the abs val of difference between the x and x of the current mouse position
height - the abs val of difference between the y and y of the current mouse position
mevt - MouseEvent
g2D - Graphics2D of displayed canvas
theCanvas - current main_canvas

getDragged

public boolean getDragged()
This function returns the state of the flag, dragged.

Returns:
boolean representing dragged