Class magicSelectTool

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

public class magicSelectTool
extends java.lang.Object
implements ourTool

This magicSelectTool uses the ourTool interface. It magicSelects a region of connected color. It should work with all operating systems and hardware. There are no variances and no security constraints. uses its own inner class coords22.


Field Summary
(package private)  java.awt.image.BufferedImage backupImage
          Holds the backupImage, magicSelectedImage, pastedImage.
(package private)  coords2 cur
          The coordinates that is used to move around in the coord array of pixels and keep track which of the coords2 is not colored.
(package private)  java.awt.image.BufferedImage curImage
          Holds the current image.
 java.awt.Polygon cursorPolygon
          magicSelected free-hand area, closed polygon.
 int curX
          x coordinate of current mouse position.
 int curY
          y coordinate of current mouse position.
 boolean dragged
          Used as a flag to determine if the mouse was dragged.
 boolean drawOpaque
          Sets drawOpaque to true.
(package private) static int eastBound
          The column number of pixels.
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.
(package private) static int index
          The current position in the array.
 boolean magicSelected
          Used as a flag to determine if it was magicSelected.
(package private)  java.awt.image.BufferedImage magicSelectedImage
          Holds the backupImage, magicSelectedImage, pastedImage.
 java.awt.BasicStroke magicSelectStroke
          Holds the stroke that is magicSelected.
 java.awt.BasicStroke magicSelectStrokeW
          Holds the stroke that is magicSelected in white.
 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.
 int onCanvasFlag
          Determines if it is on the canvas.
 boolean pasted
          Used as a flag to determine if it was pasted.
(package private)  java.awt.image.BufferedImage pastedImage
          Holds the backupImage, magicSelectedImage, pastedImage.
private  int pasteX
          Holds the pasted X.
private  int pasteY
          Holds the pasted Y.
(package private)  coords2[] pixels
          A coordinate array of the pixels used to keep track which part of the BufferedImage curImage is not colored.
(package private) static int select
          The new color to select the pixel with the colors wanted.
(package private) static int size
          The current size of the array.
(package private) static int southBound
          The row number of pixels.
private  int startX
          x coord of initial click.
private  int startY
          y coord of initial click.
 
Constructor Summary
magicSelectTool()
          Creates a magicSelectTool and sets the Stroke.
 
Method Summary
 void clear(main_canvas theCanvas)
          Clears the magicSelected 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 magicSelecting, as specified by the coordinates passed in by MouseEvent.
 void cutBackground(java.awt.image.BufferedImage cuttingImg, java.awt.Color rightColor)
          RightColor is painted over magicSelected 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 magicSelect more according to the movement of the mouse.
 java.awt.image.BufferedImage getCopyImage(main_canvas theCanvas)
          Copies the magicSelected portion of the canvas, but does not alter canvas.
 java.awt.image.BufferedImage getCutImage(main_canvas theCanvas)
          Cuts magicSelected 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 magicSelected.
 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 magicSelected.
 void mouseReleaseAction(java.awt.event.MouseEvent mevt, main_canvas theCanvas)
          Allows the user to release the mouse and therefore stop magicSelecting.
 void myDrawImage(java.awt.Color rightColor)
          To paste an image into the magicSelected 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 magicSelected area to be cut.
 void selectIt()
          selectIt does the coloring.
 void setCursorPolygon()
          setCursorPolygon determines the boundary of all the pixels.
 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

public int curX
x coordinate of current mouse position.


curY

public int curY
y coordinate of current mouse position.


dragged

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


moved

public 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, magicSelectedImage, pastedImage.


magicSelectedImage

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


pastedImage

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


g2D

java.awt.Graphics2D g2D
Holds the Graphics2D.


magicSelected

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


pasted

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


moving

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


magicSelectStroke

public java.awt.BasicStroke magicSelectStroke
Holds the stroke that is magicSelected.


magicSelectStrokeW

public java.awt.BasicStroke magicSelectStrokeW
Holds the stroke that is magicSelected in white.


pasteX

private int pasteX
Holds the pasted X.


pasteY

private int pasteY
Holds the pasted Y.


cursorPolygon

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


drawOpaque

public boolean drawOpaque
Sets drawOpaque to true.


onCanvasFlag

public int onCanvasFlag
Determines if it is on the canvas.


select

static int select
The new color to select the pixel with the colors wanted.


index

static int index
The current position in the array.


size

static int size
The current size of the array.


eastBound

static int eastBound
The column number of pixels. Negative value is not allowed.


southBound

static int southBound
The row number of pixels. Negative value is not allowed.


pixels

coords2[] pixels
A coordinate array of the pixels used to keep track which part of the BufferedImage curImage is not colored.


cur

coords2 cur
The coordinates that is used to move around in the coord array of pixels and keep track which of the coords2 is not colored.

Constructor Detail

magicSelectTool

public magicSelectTool()
Creates a magicSelectTool 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 magicSelecting, as specified by the coordinates passed in by MouseEvent. Sets the flag magicSelected 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 magicSelect 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

setCursorPolygon

public void setCursorPolygon()
setCursorPolygon determines the boundary of all the pixels.


selectIt

public void selectIt()
selectIt does the coloring. It checks South, North, East and West of the main canvas image. Then, if it is not colored, it will be colored. The function also runs until index (the total area of the bufferedImage) is -1, which means that the BufferedImage is colored.


mouseReleaseAction

public void mouseReleaseAction(java.awt.event.MouseEvent mevt,
                               main_canvas theCanvas)
Allows the user to release the mouse and therefore stop magicSelecting. Can only be performed if the mouse was clicked on the canvas and clickAction was called. The magicSelected 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 magicSelected portion of the canvas, but does not alter canvas. Can only be performed if a portion was pasted or magicSelected.

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

getCutImage

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

Parameters:
theCanvas - current main_canvas
Returns:
BufferedImage is the magicSelected 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 magicSelected to true.

Parameters:
theImage - BufferedImage - the portion of image magicSelected
theCanvas - current main_canvas
x - an int representing the 'X' paste location
y - an int representing the 'Y' paste location

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 magicSelected area on the main_canvas. Sets the flags magicSelected, moved, and pasted to false.

Parameters:
theCanvas - main_canvas

myDrawImage

public void myDrawImage(java.awt.Color rightColor)
To paste an image into the magicSelected 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 magicSelected area to be cut.

Parameters:
cuttingImg - BufferedImage of magicSelected 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 magicSelected area to be cut.

Parameters:
cuttingImg - BufferedImage of magicSelected 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 magicSelected.

Returns:
boolean representing the state of the flag magicSelected

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 magicSelected.

Returns:
boolean representing the state of the flag magicSelected