Technical Documentation (API — Backend) - Software-Engineering-Spring-2020/PollyPaint GitHub Wiki

Backend

Main backend files

The only class accessible from the frontend is Window. All needed DrawSpace functionality is in this class. Other classes are protected and only accessible within the backend package. (The API for Window is in a separate page, so that it can be easily accessed).

Note that the x and y positions in the backend are different from the frontend. The backend uses relational fractions, and the frontend uses coordinates. See "translateCoordinates()" in the DrawSpace class for information on how positions are translated from the frontend to backend.

xo, yo, and basically any letter +o is represents translation or distance of change.

ColorfulObject

protected abstract class ColorfulObject extends PollyObject implements Serializable

An PollyObject that has border and/or fill color

ColorfulObject()

Description: A constructor that creates a new ColorfulObject
Parameters: sketch, float x (x position), float y (y position), int[] fillColor, int[] boarderColor | Sets the sketch, x position, and y position in Superclass
Returns: A ColorfulObject

init()

Description: Initiates the Processing Sketch
Parameters: PApplet sketch
Returns: void

setBoarderColor()

Description: Sets the color of the object's border
Parameters: int r (red value), int g (green value), int b (blue value)
Returns: void

setFillColor()

Description: Sets the inner color of the object, not including the border
Parameters: int r (red value), int g (green value), int b (blue value)
Returns: void

int[] getBorderColor()

Description: Returns an int array with values that make up the border color. Position 0 is the red value, position 1 is the green value, and position 3 is the blue value.
Parameters: None
Returns: int[]

getFillColor()

Description: Returns an int array with values that make up the fill color. Position 0 is the red value, position 1 is the green value, and position 3 is the blue value.
Parameters: None
Returns: int[]

display()

Description: Displays ColorfulObjects. | Calls display in the superclass, then calls methods for the fill, stroke, and strokeweight

DrawSpace

protected class DrawSpace extends ColorfulObject

The DrawSpace represents the section of the canvas that the user draws on. It also includes all the objects the user draws.

DrawSpace()

Description: A constructor that creates a new DrawSpace object
Parameters: sketch, float x, float y, float w, float h
Returns: A DrawSpace object

init()

Description: Initiates the Processing Sketch
Parameters: PApplet sketch
Returns: void

getAllObjects()

Description: Gets a list of all objects in the DrawSpace.
Parameters: None
Returns: ArrayList

getObjectAt()

Description: Returns the object at the same location as the mouse.
Parameters: float mouseX, float mouseY, float zoom
Returns: Void

withinScope()

Description: Determines if an x and y position is within the DrawSpace
Parameters: float x, float y Returns: Boolean

getNumObjects()

Description: Returns number of objects in the drawSpace.
Parameters: None
Returns: int

translateCoordinates()

Description: Translates from relational fractions (used on the backend) to coordinates (used on the frontend)
Parameters: float x, float y, float zoom
Returns: float[] | The first float is the x position, the second the y position

relativePan()

Description: Pans taking in account zoom factor
Parameters: float xo, float yo, float zoom
Returns: float[]

pan()

Description: Pans working off window coordinates
Parameters: float x, float y Returns: void

setPosition()

Description: Sets position of the DrawSpace
Parameters: float x, float y
Returns: void

display()

Description: Displays the DrawSpace and all the objects present on it. It calls the individual display function of each object in the DrawSpace.
Parameters: float zoom, boolean showGrid, float gridSpacing
Returns: Void

addObject()

Description: Add an object to the DrawSpace. Returns boolean of if action was successful.
Parameters: PollyObject shape
Returns: boolean

removeObject()

Description: Removes an object from the DrawSpace. Returns boolean of if action was successful.
Parameters: PollyObject shape
Returns: boolean

indexOf()

Description: Returns the index of a PollyObject from the list of objects in the DrawSpace
Parameters: PollyObject shape
Returns: int

getShape()

Description: Returns a shape of a certain index from the list of objects in the DrawSpace
Parameters: int i
Returns: PollyObject

addComment()

Description: Adds a comment to list of objects in the DrawSpace. Returns boolean of if action was successful.
Parameters: PollyObject Shape
Returns: boolean

removeComment()

Description: Removes a comment to list of objects in the DrawSpace. Returns boolean of if action was successful.
Parameters: PollyObject Shape
Returns: boolean

getComment

Description: Returns a comment of a certain index from the list of comments in the DrawSpace
Parameters: int i
Returns: PollyObject

displayGrid()

Description: Displays grid over the DrawSpace
Parameters: float spacing
Returns: void

Group

protected class group extends PollyObject implements Serializable

Group()

Description: A constructor that creates a new Group object.
Parameters: sketch, float x (x position), float y (y position) | Sets the x and y positions in Superclass Returns: A Group object

showBoundingBox()

Description: Shows bounding box for objects in the group.
Parameters: none
Returns: void

withinScope

Description: Determines if objects in the group are within the scope of the DrawSpace
Parameters: float x, float y
Returns: void

pan()

Description: Pans all the objects in the group
Parameters: float xo, float yo
Returns: void

resize()

Description: Resizes all the objects in the group
Parameters: float factor
Returns: void

setRelativeRotate()

Description: Sets relative rotate for objects in the group
Parameters: None
Returns: void

NonShape

public abstract class NonShape extends ColorfulObject

NonShape()

Description: A constructor that creates a new NonShape object
Parameters: sketch, float x, float y, float strokeWeight, int[] fillColor, int[] boarderColor | All set in superclass
Returns: NonShape

setSettings()

Description: Sets the settings of NonShape
Parameters: None
Returns: void

setStrokeWeight()

Description: Sets the stroke weight of the NonShape
Parameters: float wgt
Returns: void

setBoarderColor()

Description: Sets border color of NonShape
Parameters: int r, int g, int b
Returns: void

setFillColor()

Description: Sets fill color of NonShape
Parameters: int r, int g, int b
Returns: void

display()

Description: Displays NonShape
Parameters: None
Returns: void

pan()

Description: Pans NonShape
Parameters: float xo, float yo
Returns: void

setRelativeRotate()

Description: Rotates NonShape
Parameters: float ro
Returns: void

PollyObject

protected abstract class PollyObject implements Serializable

A PollyObject applies to most objects in PollyPaint that can be displayed, such as shapes, lines, and the DrawSpace

PollyObject()

Description: A constructor that creates a new PollyObject object
Parameters: sketch, float x (x position), float y (y position)
Returns: A PollyObject object

init()

Description: Initiates the Processing Sketch
Parameters: PApplet sketch
Returns: void

getPosition

Description: Returns x and y coordinates of the PollyObject, in that order
Parameters: None
Returns: float[]

setPosition()

Description: Sets the PollyObject's x and y coordinates
Parameters: float x (x position), float y (y position)
Returns: void

setRotate()

Description: Sets how many degrees to increase or decrease PollyObject's rotate | You might enter 90 in this function. Then rotate will increase by 90 % 360
Parameters: float r
Returns: void

setRelativeRotate()

Description: Increases/decreases PollyObject's rotate. Subtract r from previous rotate, and use this value to increase or decrease the rotation of the shape.
Parameters: float r
Returns: void

getDimensions()

Description: Returns x position, y position, pixelWidth, and pixelHeight of PollyObject
Parameters: none
*Returns: float[]

withinScope()

Description: Checks to see if coordinates are within bounding box of PollyObject
Parameters: float x, float y
Returns: boolean

showBoundingBox()

Description: Shows the bounding box of PollyObject
Parameters: none
Returns: void

getBoundingBoxPoints()

Description: Generates four bounding box points around PollyObject. It uses the PollyObject's width and height, as well as the centerpoint, which has to be passed in. Points are not rotated if the PollyObject is rotated.
Parameters: float xcenter, float ycenter Returns: PVector[] | Array is four points long

getRotatedBoundingBoxPoints()

Description: Generates four bounding box points around PollyObject. It uses the PollyObject's width and height, as well as the centerpoint, which has to be passed in. Corresponds with a rotated PollyObject.
Parameters: float xcenter, float ycenter
Returns: PVector[] | Array is four points long

rotateAbout()

Description: Rotates PollyObject around a point
Parameters: PVector rotatePoint, PVector anchor, float degree
Returns: Pvector

display()

Description: displays PollyObject, adjusting for location, rotation, and scaling
Parameters: None
Returns: void

pan()

Description: Changes PollyObject's position by an x and y value
Parameters: float xo, float yo
Returns: void

resize()

Description: Resizes PollyObject by a certain factor Parameters: float factor
Returns: void

Shape

public abstract class Shape extends ColorfulObject implements Serializable

Shape()

Description: A constructor to create a new Shape object
Parameters: sketch, float x, float y, float strokeWeight, int[] fillColor, int[] boardercolor
Returns: Shape

init()

Description: Initiates the Processing Sketch
Parameters: PApplet sketch
Returns: void

setSettings()

Description: Sets the settings of Shape
Parameters: None
Returns: void

setStrokeWeight()

Description: Sets the stroke weight of Shape
Parameters: float wgt
Returns: void

setBoarderColor()

Description: Sets border color of Shape
Parameters: int r, int g, int b
Returns: void

setFillColor()

Description: Sets fill color of Shape
Parameters: int r, int g, int b, int a
Returns: void

setRelativeRotate()

Description: Sets relative rotate | calls superclass
Parameters: float ro
Returns: void

SerialManager

public class SerialManager

deepClonePollyObject()

Description: Returns a deep clone of the provided PollyObject | throws IOException, ClassNotFoundException
Parameters: PApplet sketch, PollyObject obj Returns: PollyObject

saveDrawSpace()

Description: Saves the draw space to a file that can be opened and restored later | throws IOException
Parameters: DrawSpace ds, String filename Returns: void

openDrawSpace

Description: Returns a draw space opened from file that can be made the current draw space | throws IOException, ClassNotFoundException
Parameters: PApplet sketch, String filename
Returns: DrawSpace

Objects

Comment

class *Comment extends TextBox implements Serializable

Comment()

Description: A constructor that creates a new Comment
Parameters: sketch, float x, float y, int[] fillColor, int[] boarderColor, String str, String font, float textSize | Sets values in superclass Returns: Comment

setSource()

Description: Sets source for Comment
Parameters: PollyObject source Returns: void

display()

Description: Displays Comment | calls method in superclass
Parameters: None
Returns: void

Curve

class Curve extends ColorfulObject implements Serializable

Curve()

Description: A constructor that creates a new Curve object
Parameters: PApplet sketch, float x, float y, ArrayList<float[]> points, float strokeWeight, int[] fillColor, int[] boarderColor | Sketch, x, y, strokeWeight, fillColor, and borderColor are set in Superclass
Returns: Curve

init()

Description: Initiates the Processing Sketch
Parameters: PApplet sketch
Returns: void

setSettings()

Description: Set the points of the curve
Parameters: ArrayList<float[]> points Returns: void

display()

Description: Displays Curve
Parameters: none
Returns: void

Ellipse

class Ellipse extends ColorfulObject implements Serializable

Ellipse()

Description: A constructor that creates a new Ellipse object
Parameters: sketch, float x, float y, float w, float h, int[] fillColor, int[] borderColor | Sketch, x, y, fillColor, and borderColor are set in Superclass
Returns: Ellipse

Ellipse()

Description: A constructor that creates a new Ellipse object
Parameters: sketch, float x, float y, float d, int[] fillColor, int[] borderColor
Returns: Ellipse

Ellipse()

Description: A constructor that creates a new Ellipse object
Parameters: sketch, float x, float y, int[] fillColor, int[] borderColor
Returns: Ellipse

init()

Description: Initiates the Processing Sketch
Parameters: PApplet sketch
Returns: void

display()

Description: Displays Ellipse
Parameters: None
Returns: void

FreeForm

class FreeForm extends Shape implements Serializable

FreeForm()

Description: A constructor that creates a new FreeForm object
Parameters: sketch, float x, float y, ArrayList<float[]> points, float strokeWeight, int[] fillColor, int[] boarderColor
Returns: FreeForm

init()

Description: Initiates the Processing Sketch
Parameters: PApplet sketch
Returns: void

createShape()

Description: Creates a FreeForm shape from an ArrayList of point arrays
Parameters: ArrayList<float[]> points
Returns: void

withinScope()

Description: Determines if a position is within scope of the FreeForm shape
Parameters: float x, float y
*Returns: boolean

display()

Description: Displays FreeForm shape | calls superclass
Parameters: None
Returns: void

Image

class Image extends PollyObject implements Serializable

Image()

Description: A constructor that creates a new Image object
Parameters: sketch, float x, float y, String filename, String extension | sets sketch, x, y in superclass
Returns: Image

init()

Description: Initiates the Processing Sketch
Parameters: PApplet sketch
Returns: void

display()

Description: Displays image
Parameters: None
Returns: Void

resize()

Description Resize image by a certain factor | calls superclass
Parameters: float factor
Returns: void

NonCurve

class NonCurve extends Shape

NonCurve()

Description: A constructor to create a new NoNCurve object
Parameters: PApplet sketch, float x, float y, ArrayList<float[]> points, float strokeWeight, int[] fillColor, int[] boarderColor | sketch, x, y, strokeWeight, fillColor, boarderColor are set in superclass
Returns: NonCurve

init()

Description: Initiates the Processing Sketch
Parameters: PApplet sketch
Returns: void

setSettings()

Description: Set fill color, border color, and stroke weight
Parameters: None
Returns: void

createShape()

Description: Creates a shape from an ArrayList of float[] points
Parameters: ArrayList<float[]> points
Returns: void

PollyGon

class PollyGon extends Shape implements Serializable

PollyGon()

Description: A constructor to create a new PollyGon object
Parameters: sketch, float x, float y, ArrayList<float[]> points, float strokeWeight, int[] fillColor, int[] boarderColor Returns: PollyGon

init()

Description: Initiates the Processing Sketch
Parameters: PApplet sketch
Returns: void

createShape()

Description: Creates a PollyGon from an ArrayList of float[] points passed to constructor
Parameters: None
Returns: void

display()

Description: Displays PollyGon | calls superclass and then translates
Parameters: None Returns: void

Rectangle

class Rectangle extends Shape implements Serializable

Rectangle()

Description: A constructor that creates a new Rectangle object
Parameters: sketch, float x, float y, float w, float h, int[] fillColor, int[] borderColor
Returns: Rectangle

Rectangle()

Description: A constructor that creates a new Rectangle object
Parameters: sketch, float x, float y, float d, int[] fillColor, int[] borderColor
Returns: Rectangle

Rectangle()

Description: A constructor that creates a new Rectangle object
Parameters: sketch, float x, float y, int[] fillColor, int[] borderColor
Returns: Rectangle

init()

Description: Initiates the Processing Sketch
Parameters: PApplet sketch
Returns: void

TextBox

protected class TextBox extends ColorfulObject implements Serializable

TextBox()

Description: A constructor that creates a new TextBox object
Parameters: sketch, float x, float y, int[] fillColor, int[] boarderColor, String str, String font, float textSize | sketch, x, y, fillcolor, boarderColor set in superclass
Returns: TextBox

init()

Description: Initiates the Processing Sketch
Parameters: PApplet sketch
Returns: void

display()

Description: Displays TextBox | calls superclass and then translates
Parameters: none
Returns: void

ObjectFactory

public class ObjectFactory

importImage

Description: Creates an image from a file
Parameters: float x, float y, String filename, String extension
Returns: Image

createTextBox

Description: Creates a TextBox
Parameters: float x, float y, int[] fillColor, int[] boarderColor, String str, String font, float textSize
Returns: TextBox

createComment

Description: Creates a Comment
Parameters: float x, float y, int[] fillColor, int[] boarderColor, String str, String font, float textSize
Returns: TextBox

createShape()

Description: Creates a shape based on the user-input char. 'e' corresponds to Circle, 'r' corresponds to Rectangle.
Parameters: float x, float y, char shape, int[] fillColor, int[] borderColor
Returns: null

createEllipse()

Description: Creates an Ellipse object
Parameters: float x, float y, float w, float h, float strokeWeight, int[] fillColor, int[] boarderColor
Returns: Ellipse

createEllipse()

Description: Creates an Ellipse object
Parameters: float x, float y, float d, float strokeWeight, int[] fillColor, int[] boarderColor
Returns: Ellipse

createEllipse()

Description: Creates an Ellipse object
Parameters: float x, float y, float strokeWeight, int[] fillColor, int[] boarderColor
Returns: Ellipse

createRect()

Description: Creates a Rectangle object
Parameters: (float x, float y, float w, float h, float strokeWeight, int[] fillColor, int[] boarderColor
Returns: Rectangle

createRect()

Description: Creates a Rectangle object
Parameters: float x, float y, float d, float strokeWeight, int[] fillColor, int[] boarderColor
Returns: Rectangle

createRect()

Description: Creates a Rectangle object
Parameters: float x, float y, float strokeWeight, int[] fillColor, int[] boarderColor
Returns: Rectangle

createFreeForm()

Description: Creates a FreeForm object
Parameters: float x, float y, ArrayList<float[]> points, float strokeWeight, int[] fillColor, int[] boarderColor
Returns: FreeForm

createLine()

Description: Creates a Line Parameters: float x, float y, ArrayList<float[]> points, float strokeWeight, int[] fillColor, int[] boarderColor
Returns: Line

createPollyGon()

Description: Creates a PollyGon
Parameters: float x, float y, ArrayList<float[] points points, float strokeWeight, int[] fillColor, int[] boarderColor
Returns: PollyGon

createCurve()

Description: Creates a Curve
Parameters: ArrayList<float[]> points, float strokeWeight, int[] fillColor, int[] boarderColor Returns: Curve

⚠️ **GitHub.com Fallback** ⚠️