Class CanvasPanel

java.lang.Object
com.example.brickpaint.CanvasPanel

public class CanvasPanel extends Object
Manages all the drawing Sub-nodes for the overarching canvas, may have multiple instances to create multiple canvases
Author:
matde
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    javafx.scene.canvas.Canvas
    The main canvas that will be used for drawing ect.
    final String
    The Name of the Panel
    javafx.scene.layout.AnchorPane
    Top level pane of the actual canvas objects and their corresponding stack pane
    final javafx.scene.SnapshotParameters
     
    javafx.scene.layout.StackPane
    The root Node that all the canvas components are created under
    javafx.scene.control.ScrollPane
    The viewport (ScrollPane) that the entire canvas panel will reside within
    javafx.scene.canvas.Canvas
    A dummy canvas used to draw objects with a live preview before they are drawn on the real canvas
    Manages Undo and Redo operations on this canvas
  • Constructor Summary

    Constructors
    Constructor
    Description
    CanvasPanel(javafx.scene.control.TabPane tPane, String name, BrickKeys keys, BrickPaintController controllerIn)
    Default Constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears the canvas panel
    javafx.scene.image.Image
    Helper method which returns the canvas as an image
    void
    FloodFill(double x, double y)
    Preforms a flood/bucket fill operation on the canvas at the specified point
    void
    mirror(boolean horizontal)
    Will mirror the entire canvas vertically or horizontally based on the boolean input
    void
    onScroll(javafx.scene.input.ScrollEvent event)
    Handles zooming/scaling the canvasPanel with the AnimatedZoomOperator class
    void
    rotate(boolean right)
    Will rotate the entire canvas right or left 90 degrees based on the boolean input
    void
    Writes the currently selected image to the system clipboard
    void
    Resizes the canvas to the selected image
    void
    Writes the currently selected image to the system clipboard and removes that area from the canvas
    void
    selectionMirror(boolean horizontal)
    Will mirror the selection vertically or horizontally based on the boolean input
    void
    Draws the currently selected image to the canvas at the mouse position or top left of the canvas
    void
    selectionRotate(boolean right)
    Will rotate the selection right or left 90 degrees based on the boolean input
    void
    setSizeX(double x)
    Sets the width of all necessary nodes in the canvas panel
    void
    setSizeY(double y)
    Sets the height of all necessary nodes in the canvas panel
    void
    Setup(BrickKeys keys, String name)
    Configures all the settings of this Canvas Panel, should be called immediately after instantiation
    void
    Updates the size number of the current canvas in the toolbar

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • Name

      public final String Name
      The Name of the Panel
    • parameters

      public final javafx.scene.SnapshotParameters parameters
    • root

      public javafx.scene.layout.StackPane root
      The root Node that all the canvas components are created under
    • canvas

      public javafx.scene.canvas.Canvas canvas
      The main canvas that will be used for drawing ect.
    • scrollPane

      public javafx.scene.control.ScrollPane scrollPane
      The viewport (ScrollPane) that the entire canvas panel will reside within
    • sketchCanvas

      public javafx.scene.canvas.Canvas sketchCanvas
      A dummy canvas used to draw objects with a live preview before they are drawn on the real canvas
    • pane

      public javafx.scene.layout.AnchorPane pane
      Top level pane of the actual canvas objects and their corresponding stack pane
    • undoManager

      public UndoManager undoManager
      Manages Undo and Redo operations on this canvas
  • Constructor Details

    • CanvasPanel

      public CanvasPanel(javafx.scene.control.TabPane tPane, String name, BrickKeys keys, BrickPaintController controllerIn)
      Default Constructor
      Parameters:
      tPane - The parent of this class
      name - The Name of the Canvas Panel
      keys - The instance of BrickKeys used for key binds
      controllerIn - The controller class for this canvas
  • Method Details

    • Setup

      public void Setup(BrickKeys keys, String name)
      Configures all the settings of this Canvas Panel, should be called immediately after instantiation
      Parameters:
      keys - The instance of BrickKeys that this class should use
      name - The name of the CanvasPanel
    • UpdateSize

      public void UpdateSize()
      Updates the size number of the current canvas in the toolbar
    • fetchImage

      public javafx.scene.image.Image fetchImage()
      Helper method which returns the canvas as an image
      Returns:
      Image of canvas
    • setSizeX

      public void setSizeX(double x)
      Sets the width of all necessary nodes in the canvas panel
      Parameters:
      x - new width
    • setSizeY

      public void setSizeY(double y)
      Sets the height of all necessary nodes in the canvas panel
      Parameters:
      y - new height
    • FloodFill

      public void FloodFill(double x, double y)
      Preforms a flood/bucket fill operation on the canvas at the specified point
      Parameters:
      x - The x position of the point to start the flood fill
      y - The y position of the point to start the flood fill
    • selectionCopy

      public void selectionCopy()
      Writes the currently selected image to the system clipboard
    • selectionCut

      public void selectionCut()
      Writes the currently selected image to the system clipboard and removes that area from the canvas
    • selectionPaste

      public void selectionPaste()
      Draws the currently selected image to the canvas at the mouse position or top left of the canvas
    • selectionCrop

      public void selectionCrop()
      Resizes the canvas to the selected image
    • selectionMirror

      public void selectionMirror(boolean horizontal)
      Will mirror the selection vertically or horizontally based on the boolean input
      Parameters:
      horizontal - Mirrors horizontally if true else will mirror vertically
    • mirror

      public void mirror(boolean horizontal)
      Will mirror the entire canvas vertically or horizontally based on the boolean input
      Parameters:
      horizontal - Mirrors horizontally if true else will mirror vertically
    • selectionRotate

      public void selectionRotate(boolean right)
      Will rotate the selection right or left 90 degrees based on the boolean input
      Parameters:
      right - Rotates right if true else rotates left
    • rotate

      public void rotate(boolean right)
      Will rotate the entire canvas right or left 90 degrees based on the boolean input
      Parameters:
      right - Rotates right if true else rotates left
    • clearAll

      public void clearAll()
      Clears the canvas panel
    • onScroll

      public void onScroll(javafx.scene.input.ScrollEvent event)
      Handles zooming/scaling the canvasPanel with the AnimatedZoomOperator class
      Parameters:
      event - Scroll event from Input class