Javadoc: Tools Class
- java.lang.Object
-
- Tools
-
public class Tools extends java.lang.Object
The Tools class controls the style of the tools and how those tools paint onto the canvas.
Submitted to AP Computer Science 12: 2015-01-27
Last modified: 2015-04-04
Author: Samantha Yu
-
-
Field Summary
Fields Modifier and Type Field and Description (package private) java.awt.Graphics2D
cgBuffer
cgBuffer stands for "current graphics' buffer", a graphics context for drawing an off-screen image.(package private) java.awt.image.BufferedImage
cvMem
cvMem stands for "current virtual memory", the off-screen image that the current layer is painted upon.(package private) Layers
layersArray
A Layers object that controls the creation and deletion of layers, and what happens when the user wants to move to a different layer.(package private) Menu
menuBar
The click-able and visible menu bar that allows the user to decide on the color, size, tool and layer.(package private) PaintApp
paintLab
A PaintApp object has only one instance and allows this class to access its non-static methods and fields.private int
randX
The coordinates of the random circles in the spray tool.private int
randY
The coordinates of the random circles in the spray tool.
-
Constructor Summary
Constructors Constructor and Description Tools(PaintApp pLab, Menu menuB, Layers lArray)
When the Tools object is constructed, menuBar is initialized to the only menu, paintLab to the only paint window, and layersArray to the only layers array.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description private void
brush(int oldX, int oldY, int newX, int newY)
The brush tool with "missing" lines because its BasicStroke is CAP_BUTT and JOIN_MITER.private void
pencil(int oldX, int oldY, int newX, int newY)
The pencil tool with a rounded stroke draws a line from the old coordinates to the new coordinates.private void
spray(int newX, int newY)
The spray tool paints with several random circles around the current coordinates.void
useTool(int numTool, int oldX, int oldY, int newX, int newY)
Before drawing with a specific tool, useTool() first grabs the current layer and creates a graphics context for that layer to be used in double buffering.
-
-
-
Field Detail
-
cvMem
java.awt.image.BufferedImage cvMem
cvMem stands for "current virtual memory", the off-screen image that the current layer is painted upon.
-
cgBuffer
java.awt.Graphics2D cgBuffer
cgBuffer stands for "current graphics' buffer", a graphics context for drawing an off-screen image. All cgBuffer information is sent to cvMem which is later drawn with the drawImage().
-
paintLab
PaintApp paintLab
A PaintApp object has only one instance and allows this class to access its non-static methods and fields. I did not make PaintApp's fields static, because those fields refer to the one and same object, the paint program. I did not want to place the Tools' methods into PaintApp, because those methods belong in its own separate category. So, this Tools class must be able to access the dimensions of PaintApp such as the get methods like getAppWidth().
-
menuBar
Menu menuBar
The click-able and visible menu bar that allows the user to decide on the color, size, tool and layer.
-
layersArray
Layers layersArray
A Layers object that controls the creation and deletion of layers, and what happens when the user wants to move to a different layer.
-
randX
private int randX
The coordinates of the random circles in the spray tool.
-
randY
private int randY
The coordinates of the random circles in the spray tool.
-
-
Constructor Detail
-
Tools
public Tools(PaintApp pLab, Menu menuB, Layers lArray)
When the Tools object is constructed, menuBar is initialized to the only menu, paintLab to the only paint window, and layersArray to the only layers array.- Parameters:
pLab
- The driver class, PaintApp, passes itself to the Tools() constructor to ensure that its Tools object has sufficient access to its methods and variables.menuB
- The Menu class passes itself to the Tools() constructor to ensure that its Tools object has sufficient access to its methods and variables.lArray
- The Layers class passes itself to the Tools() constructor to ensure that its Tools object has sufficient access to its methods and variables.
-
-
Method Detail
-
pencil
private void pencil(int oldX, int oldY, int newX, int newY)
The pencil tool with a rounded stroke draws a line from the old coordinates to the new coordinates.- Parameters:
oldX
- Old coordinates of where the mouse has beenoldY
- Old coordinates of where the mouse has beennewX
- New coordinates of where the mouse isnewY
- New coordinates of where the mouse is
-
brush
private void brush(int oldX, int oldY, int newX, int newY)
The brush tool with "missing" lines because its BasicStroke is CAP_BUTT and JOIN_MITER.- Parameters:
oldX
- Old coordinates of where the mouse has beenoldY
- Old coordinates of where the mouse has beennewX
- New coordinates of where the mouse isnewY
- New coordinates of where the mouse is
-
spray
private void spray(int newX, int newY)
The spray tool paints with several random circles around the current coordinates.- Parameters:
newX
- New coordinates of where the mouse isnewY
- New coordinates of where the mouse is
-
useTool
public void useTool(int numTool, int oldX, int oldY, int newX, int newY)
Before drawing with a specific tool, useTool() first grabs the current layer and creates a graphics context for that layer to be used in double buffering. Depending on which tool is selected, pencil(), brush(), or spray() are called.- Parameters:
numTool
- Remembers which tool was selected by the useroldX
- Old coordinates of where the mouse has beenoldY
- Old coordinates of where the mouse has beennewX
- New coordinates of where the mouse isnewY
- New coordinates of where the mouse is
-
-