Class selectTool

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

public class selectTool
extends java.lang.Object
implements ourTool

This selectTool uses the ourTool interface. It selects a free-hand region. 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
          Holds the backupImage, selectedImage, pastedImage.
(package private)  java.awt.image.BufferedImage curImage
          Holds the current image.
 java.awt.Polygon cursorPolygon
          selected free-hand area, closed polygon.
private  int curX
          x coordinate of current mouse position.
private  int curY
          y coordinate of current mouse position.
private  boolean dragged
          Used as a flag to determine if the mouse was dragged.
 boolean drawOpaque
          Sets drawOpaque to true.
private  int endX
          x coord of release of click.
private  int endY
          y coord of release of click.
private  int fillType
          Used to set the fill type, ranging from 1-3.
(package private)  java.awt.Graphics2D g2D
          Holds the Graphics2D.
private  boolean moved
          Used as a flag to determine if the mouse was moved.
 boolean moving
          Used as a flag to determine if it was moving ======= private boolean pasted = false; /** Used as a flag to determine if it was moving.
 int onCanvasFlag
          Determines if it is on the canvas.
 boolean pasted
          Used as a flag to determine if it was pasted ======= private boolean selected = false; /** Used as a flag to determine if it was pasted.
(package private)  java.awt.image.BufferedImage pastedImage
          Holds the backupImage, selectedImage, pastedImage.
private  int pasteX
          Holds the pasted X.
private  int pasteY
          Holds the pasted Y.
 boolean selected
          Used as a flag to determine if it was selected.
(package private)  java.awt.image.BufferedImage selectedImage
          Holds the backupImage, selectedImage, pastedImage.
private  java.awt.BasicStroke selectStroke
          Holds the stroke that is selected ======= private boolean moving = false; /** Holds the stroke that is selected.
private  java.awt.BasicStroke selectStrokeW
          Holds the stroke that is selected.
private  int startX
          x coord of initial click.
private  int startY
          y coord of initial click.
 
Constructor Summary
selectTool()
          Creates a selectTool and sets the Stroke.
 
Method Summary
 void clear(main_canvas theCanvas)
          Clears the selected area on the main_canvas.
 void clickAction(java.awt.event.MouseEvent mevt, main_canvas theCanvas)
          Allows the user to click on the canvas, and begin selecting, as specified by the coordinates passed in by MouseEvent.
 void cutBackground(java.awt.image.BufferedImage cuttingImg, java.awt.Color rightColor)
          RightColor is painted over selected area to be cut.
 void deSelect(main_canvas theCanvas)
          Resets canvas to backup image and resets all data members and flags to false.
 void dragAction(java.awt.event.MouseEvent mevt, main_canvas theCanvas)
          Allows the user to drag the mouse and select more according to the movement of the mouse.
 java.awt.image.BufferedImage getCopyImage(main_canvas theCanvas)
          Copies the selected portion of the canvas, but does not alter canvas.
 java.awt.image.BufferedImage getCutImage(main_canvas theCanvas)
          Cuts selected portion of image from the canvas.
 boolean getDragged()
          Returns the current state of the flag dragged.
 java.awt.Color getG2dColor()
          Returns the Color of the g2d.
 boolean getOpaque()
          Returns true if it is set to opaque, false otherwise.
 boolean getPasted()
          Returns the current state of the flag pasted.
 boolean getSelected()
          Returns the current state of the flag selected.
 int getStartX()
          This function returns the current X-position of subimage selected.
 int getStartY()
          This function returns the current Y-position of subimage selected.
 boolean isSelected()
          Returns the current state of the flag selected.
 void mouseReleaseAction(java.awt.event.MouseEvent mevt, main_canvas theCanvas)
          Allows the user to release the mouse and therefore stop selecting.
 void myDrawImage(java.awt.Color rightColor)
          To paste an image into the selected rectangle but does not update canvas -- see setPastedImage 2 cases, if it is opaque or not.
 java.awt.image.BufferedImage pasteBackground(java.awt.image.BufferedImage cuttingImg, java.awt.Color rightColor)
          RightColor is painted over selected area to be cut.
 void setOpaque(boolean value)
          Sets the opaque value to the boolean passed in.
 void setPastedImage(java.awt.image.BufferedImage theImage, main_canvas theCanvas, int x, int y)
          Pastes image to canvas at appropriate x and y.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

startX

private int startX
x coord of initial click.


startY

private int startY
y coord of initial click.


endX

private int endX
x coord of release of click.


endY

private int endY
y coord of release of click.


curX

private int curX
x coordinate of current mouse position.


curY

private int curY
y coordinate of current mouse position.


dragged

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


moved

private boolean moved
Used as a flag to determine if the mouse was moved.


fillType

private int fillType
Used to set the fill type, ranging from 1-3.


curImage

java.awt.image.BufferedImage curImage
Holds the current image.


backupImage

java.awt.image.BufferedImage backupImage
Holds the backupImage, selectedImage, pastedImage.


selectedImage

java.awt.image.BufferedImage selectedImage
Holds the backupImage, selectedImage, pastedImage.


pastedImage

java.awt.image.BufferedImage pastedImage
Holds the backupImage, selectedImage, pastedImage.


g2D

java.awt.Graphics2D g2D
Holds the Graphics2D.


selected

public boolean selected
Used as a flag to determine if it was selected.


pasted

public boolean pasted
Used as a flag to determine if it was pasted ======= private boolean selected = false; /** Used as a flag to determine if it was pasted. >>>>>>> 1.5


moving

public boolean moving
Used as a flag to determine if it was moving ======= private boolean pasted = false; /** Used as a flag to determine if it was moving. >>>>>>> 1.5


selectStroke

private java.awt.BasicStroke selectStroke
Holds the stroke that is selected ======= private boolean moving = false; /** Holds the stroke that is selected. >>>>>>> 1.5


selectStrokeW

private java.awt.BasicStroke selectStrokeW
Holds the stroke that is selected.


pasteX

private int pasteX
Holds the pasted X.


pasteY

private int pasteY
Holds the pasted Y.


cursorPolygon

public java.awt.Polygon cursorPolygon
selected free-hand area, closed polygon.


drawOpaque

public boolean drawOpaque
Sets drawOpaque to true.


onCanvasFlag

public int onCanvasFlag
Determines if it is on the canvas.

Constructor Detail

selectTool

public selectTool()
Creates a selectTool and sets the Stroke. 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, and begin selecting, as specified by the coordinates passed in by MouseEvent. Sets the flag selected to true.

Specified by:
clickAction in interface ourTool
Parameters:
mevt - mouseEvent holds the coordinates where the mouse was clicked.
theCanvas - the current main_canvas, which holds the BufferedImage.

dragAction

public void dragAction(java.awt.event.MouseEvent mevt,
                       main_canvas theCanvas)
Allows the user to drag the mouse and select more according to the movement of the mouse. Can only be performed if the mouse was clicked on the canvas and clickAction was called. Sets the flag dragged to true.

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

mouseReleaseAction

public void mouseReleaseAction(java.awt.event.MouseEvent mevt,
                               main_canvas theCanvas)
Allows the user to release the mouse and therefore stop selecting. Can only be performed if the mouse was clicked on the canvas and clickAction was called. The selected region is determined by the coordinates of the MouseEvent. Sets the flag dragged to false.

Specified by:
mouseReleaseAction in interface ourTool
Parameters:
mevt - MouseEvent of release
theCanvas - current main_canvas

getCopyImage

public java.awt.image.BufferedImage getCopyImage(main_canvas theCanvas)
Copies the selected portion of the canvas, but does not alter canvas. Can only be performed if a portion was pasted or selected.

Parameters:
theCanvas - the current main_canvas
Returns:
BufferedImage of selected portion of the canvas

getCutImage

public java.awt.image.BufferedImage getCutImage(main_canvas theCanvas)
Cuts selected portion of image from the canvas. If a portion was pasted, it is retrieved, and all flags are set to false. If selected is true, then the image is drawn.

Parameters:
theCanvas - current main_canvas
Returns:
BufferedImage is the selected portion of image that is cut

setPastedImage

public void setPastedImage(java.awt.image.BufferedImage theImage,
                           main_canvas theCanvas,
                           int x,
                           int y)
Pastes image to canvas at appropriate x and y. It preserves opaqueness. It sets the flags pasted and selected to true.

Parameters:
theImage - BufferedImage - the portion of image selected
theCanvas - current main_canvas
x - an int representing the x coordinate
y - an int representing the y coordinate

deSelect

public void deSelect(main_canvas theCanvas)
Resets canvas to backup image and resets all data members and flags to false.

Parameters:
theCanvas - main_canvas

setOpaque

public void setOpaque(boolean value)
Sets the opaque value to the boolean passed in.

Parameters:
value - boolean
See Also:
getOpaque()

clear

public void clear(main_canvas theCanvas)
Clears the selected area on the main_canvas. Sets the flags selected, moved, and pasted to false.

Parameters:
theCanvas - main_canvas

myDrawImage

public void myDrawImage(java.awt.Color rightColor)
To paste an image into the selected rectangle but does not update canvas -- see setPastedImage 2 cases, if it is opaque or not.

Parameters:
rightColor - Color, the right-click color

cutBackground

public void cutBackground(java.awt.image.BufferedImage cuttingImg,
                          java.awt.Color rightColor)
RightColor is painted over selected area to be cut.

Parameters:
cuttingImg - BufferedImage of selected image
rightColor - Color that would be painted if right click draw.

pasteBackground

public java.awt.image.BufferedImage pasteBackground(java.awt.image.BufferedImage cuttingImg,
                                                    java.awt.Color rightColor)
RightColor is painted over selected area to be cut.

Parameters:
cuttingImg - BufferedImage of selected image
rightColor - Color that would be painted if right click draw.
Returns:
a BufferedImage object

getG2dColor

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

Returns:
Color representing that of g2D

getDragged

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

Returns:
boolean representing the flag dragged

getSelected

public boolean getSelected()
Returns the current state of the flag selected.

Returns:
boolean representing the state of the flag selected

getStartX

public int getStartX()
This function returns the current X-position of subimage selected.

Returns:
boolean representing the state of the flag selected

getStartY

public int getStartY()
This function returns the current Y-position of subimage selected.

Returns:
boolean representing the state of the flag selected

getPasted

public boolean getPasted()
Returns the current state of the flag pasted.

Returns:
boolean representing the flag pasted.

getOpaque

public boolean getOpaque()
Returns true if it is set to opaque, false otherwise.

Returns:
boolean representing opaque
See Also:
setOpaque(boolean)

isSelected

public boolean isSelected()
Returns the current state of the flag selected.

Returns:
boolean representing the state of the flag selected