Javadoc: Layers Class
- java.lang.Object
-
- Layers
-
public class Layers extends java.lang.Object
This Layers class controls how the layers are created and deleted, and allows the user to move to a different layer.
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 boolean
changeLayer
Variables used as "switches" during program execution.private int
cLayerNum
Index of imageArray allows access to the current layer and is used to make a graphical context for that layer.boolean
deleteLayer
Variables used as "switches" during program execution.private java.util.ArrayList<java.awt.image.BufferedImage>
imageArray
An ArrayList stores BufferedImages of each layer.(package private) PaintApp
paintLab
A PaintApp object has only one instance and allows this class to access its non-static methods and fields.
-
Constructor Summary
Constructors Constructor and Description Layers(PaintApp pLab)
A Layers object is constructed that controls the creation and deletion of layers, and what happens when the user wants to move to a different layer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description void
deleteLayer()
When the user has decided to delete a layer, the method checks that the user-requested layer is not the only layer left.int
getcLayerNum()
Returns the current index of imageArrayjava.util.ArrayList<java.awt.image.BufferedImage>
getImageArray()
Returns the ArrayList of BufferedImages, which store the layersvoid
newLayer()
This method creates a new layer after the current layer by adding a new BufferedImage after the index cLayerNum to the imageArray.void
nextLayer()
When the user switches to the next layer, the method first checks whether the new index exists in the the imageArray.void
previousLayer()
When the user switches to the previous layer, the method first checks whether the new index exists in the the imageArray.void
setcLayerNum(int cNum)
This method updates the current index of imageArray.
-
-
-
Field Detail
-
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 Layer's methods into PaintApp, because those methods belong in its own separate category. So, this Layers class must be able to access and change the graphical output of PaintApp such as the PaintApp methods like repaint().
-
imageArray
private java.util.ArrayList<java.awt.image.BufferedImage> imageArray
An ArrayList stores BufferedImages of each layer.
-
cLayerNum
private int cLayerNum
Index of imageArray allows access to the current layer and is used to make a graphical context for that layer.
-
deleteLayer
public boolean deleteLayer
Variables used as "switches" during program execution.
-
changeLayer
public boolean changeLayer
Variables used as "switches" during program execution.
-
-
Constructor Detail
-
Layers
public Layers(PaintApp pLab)
A Layers object is constructed that controls the creation and deletion of layers, and what happens when the user wants to move to a different layer.- Parameters:
pLab
- The driver class, PaintApp, passes itself to the Menu() constructor to ensure that its Menu object has sufficient access to its methods and variables.
-
-
Method Detail
-
newLayer
public void newLayer()
This method creates a new layer after the current layer by adding a new BufferedImage after the index cLayerNum to the imageArray.
-
previousLayer
public void previousLayer()
When the user switches to the previous layer, the method first checks whether the new index exists in the the imageArray. If a previous layer does not exist, a notification pops up that erases some of the graphics. repaint() is called to paint the current layer's graphics on top and ensure that the graphics do not accidentally disappear.
-
nextLayer
public void nextLayer()
When the user switches to the next layer, the method first checks whether the new index exists in the the imageArray. If the next layer does not exist, a notification pops up the erases some of the graphics. repaint() is called to paint the current layer's graphics on top and ensure that the graphics do not accidentally disappear.
-
deleteLayer
public void deleteLayer()
When the user has decided to delete a layer, the method checks that the user-requested layer is not the only layer left. Next, the layer is set to a blank BufferedImage. When paint() is called, the canvas is cleared with this blank image before the other layers are drawn on top.
-
getImageArray
public java.util.ArrayList<java.awt.image.BufferedImage> getImageArray()
Returns the ArrayList of BufferedImages, which store the layers- Returns:
- imageArray
-
getcLayerNum
public int getcLayerNum()
Returns the current index of imageArray- Returns:
- cLayerNum
-
setcLayerNum
public void setcLayerNum(int cNum)
This method updates the current index of imageArray.- Parameters:
cNum
- cLayerNum is set to the parameter passed to setcLayerNum.
-
-