Package doodlepad

Class Shape

java.lang.Object
doodlepad.Shape
Direct Known Subclasses:
Arc, Image, Line, Oval, Path, Polygon, Rectangle, RoundRect, Sprite, Text

public abstract class Shape extends Object
Abstract base class for all graphical shape objects
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Interface used by methods that assign mouse event handlers given a method reference as a parameter.
    static interface 
    Interface used by methods that assign selection event handlers given a method reference as a parameter.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
    Boolean indicating if this shape can be dragged.
    protected boolean
    Flag indicating if this Shape should receive events
    protected Color
    The fill color to be used to draw this Shape.
    protected boolean
    Flag to determine if Shape should be filled.
    protected Font
    The Font to use to render the text
    protected String
     
    protected int
     
    protected int
     
    protected double
    The height of the Shape's bounding box.
    protected Layer
    The Layer on which this Shape is to be drawn
    protected boolean
    Flag to indicate if this Shape can be selected.
    protected boolean
    Flag to indicate if this Shape is currently selected
    Inner class used to handle Shape mouse events.
    protected Color
    The stroke color to be used to draw this Shape.
    protected boolean
    Flag to determine if Shape should be stroked.
    protected double
    The width of the stroke used to draw this Shape.
    protected String
    The String to be displayed over a Shape
    protected Color
    Color to use to render the text
    protected AffineTransform
    The current affine transform to be used when drawing this Shape
    protected boolean
    Flag to determine if Shape should be drawn.
    protected double
    The width of the Shape's bounding box.
    protected double
    The x-coordinate of the upper left-hand coordinate of the Shape's bounding box.
    protected double
    The y-coordinate of the upper left-hand coordinate of the Shape's bounding box.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Shape(double x, double y, double width, double height, Layer layer)
    Constructor for Shape object.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    contains(double x, double y)
    Returns true if this shape contains the given point
    boolean
    Returns true if this shape contains the given point
    abstract void
    Draw the shape.
    protected void
    Draw the text over a Shape
    Get a rectangular Area object that surrounds the Shape
    Return the current center point of the shape as a Point object.
    boolean
    Determine if the Shape is set so that it can be dragged
    boolean
    Return setting that indicates if the Shape object will receive events that are implementable by overriding methods
    int
    Get the fill color alpha component
    int
    Get the fill color blue component
    Get fill color that currently used to fill the shape when drawn
    boolean
    Get flag indicating whether or not Shape should be filled.
    int
    Get the fill color green component
    int
    Get the fill color red component
    Return the Font family name for this Rectangle object.
    int
    Return the font size for this Text object.
    int
    Return the Font style code for this Rectangle object.
    double
    Get the Shape's height
    Return the Layer on which this Shape exists
    Return the current location of the shape as a Point object.
    A utility method that returns this Shape's Pad instance
    Get the coordinates of the Shape location in the Pad coordinate system
    boolean
    Determine if the Shape is set so that it can be selected
    boolean
    Return selected state of this Shape.
    Return the current Shape size as a Dimension object
    int
    Get the stroke color alpha component
    int
    Get the stroke color blue component
    Get the current Shape stroke color.
    boolean
    Get flag indicating whether or not Shape should be stroked.
    int
    Get the stroke color green component
    int
    Get the stroke color red component
    double
    Get the current stroke width for this Shape.
    Return the Rectangle object String
    Clone the Shape\'s current AffineTransform.
    boolean
    Get visible status of Shape
    double
    Get the Shape's width
    Get the coordinates of the Shape location in the window coordinate system
    double
    Get x-coordinate of Shape
    double
    Get y-coordinate of Shape
    boolean
    Determine if the current Shape intersects with the shp Shape parameter
    void
    move(double dx, double dy)
    Move the Shape by the amounts specified in the x and y-directions
    void
    onMouseClicked(double x, double y, int button)
    Handle mouse clicked Shape events.
    void
    onMouseDoubleClicked(double x, double y, int button)
    Handle mouse double-clicked Shape events.
    void
    onMouseDragged(double x, double y, int button)
    Handle mouse dragged Shape events.
    void
    onMouseEntered(double x, double y, int button)
    Handle mouse entered Shape events.
    void
    onMouseExited(double x, double y, int button)
    Handle mouse exited Shape events.
    void
    onMouseMoved(double x, double y, int button)
    Handle mouse moved Shape events.
    void
    onMousePressed(double x, double y, int button)
    Handle mouse pressed Shape events.
    void
    onMouseReleased(double x, double y, int button)
    Handle mouse released Shape events.
    void
    onSelectionChanged(boolean sel)
    React to change in selection state by overriding
    protected void
    Utility method to trigger a repaint of the entire Pad.
    void
    Resets the shape to have no transformation.
    void
    rotate(double angle)
    Add a rotation angle to Shape transform.
    void
    rotate(double angle, double cx, double cy)
    Add a rotation angle to Shape transform.
    void
    scale(double factor)
    Add a scale factor to Shape transform.
    void
    scale(double xFactor, double yFactor)
    Add a scale factor to Shape transform.
    void
    scale(double factor, double cx, double cy)
    Add a scale factor to Shape transform.
    void
    scale(double xFactor, double yFactor, double cx, double cy)
    Add a scale factor to Shape transform.
    void
    setCenter(double cx, double cy)
    Set the Shape position so that the center is at the given coordinates.
    void
    Set the Shape position so that the center is at the given Point.
    void
    setDraggable(boolean drag)
    Set the flag that indicates if the shape can be dragged.
    void
    setEventsEnabled(boolean enabled)
    Set the boolean indicating whether or not the Shape will receive events that can be handled by overriding event methods
    void
    setFillColor(double gray)
    Set the gray scale fill color with which to draw the shape.
    void
    setFillColor(double red, double green, double blue)
    Set the fill color with which to draw the shape
    void
    setFillColor(double red, double green, double blue, double alpha)
    Set the fill color with which to fill the shape
    void
    Set the fill color by passing a Color object
    void
    setFilled(boolean filled)
    Set flag indicating whether or not Shape should be filled.
    void
    setFontFamily(String fontFamily)
    Update the Font family for the text of this Rectangle object.
    void
    setFontSize(int fontSize)
    Update the Font size for this Rectangle object.
    void
    setFontStyle(int fontStyle)
    Update the Font style for this Rectangle object.
    void
    setHeight(double height)
    Set a new Shape height.
    void
    setLocation(double x, double y)
    Set the current location of the shape and redraw it.
    void
    Set the current location of the shape and redraw it.
    void
    Assign an onMouseClicked event handler using a method reference.
    void
    Assign an onMouseDoubleClicked event handler using a method reference.
    void
    Assign an onMouseDragged event handler using a method reference.
    void
    Assign an onMouseEntered event handler using a method reference.
    void
    Assign an onMouseExited event handler using a method reference.
    void
    Assign an onMouseMoved event handler using a method reference.
    void
    Assign an onMousePressed event handler using a method reference.
    void
    Assign an onMouseReleased event handler using a method reference.
    void
    Set the Pad location of the Shape
    void
    setSelectable(boolean select)
    Set the flag that indicates if the shape can be selected
    void
    setSelected(boolean sel)
    Set the selected state of the Shape
    void
    Assign a selectionChanged event handler using a method reference.
    void
    setSize(double width, double height)
    Reset the size of the Shape and trigger a repaint
    void
    Reset the size of the Shape and trigger a repaint
    void
    setStrokeColor(double gray)
    Set the gray scale stroke color with which to draw the shape.
    void
    setStrokeColor(double red, double green, double blue)
    Set the current Shape stroke color.
    void
    setStrokeColor(double red, double green, double blue, double alpha)
    Set the fill color with which to stroke the shape
    void
    Set the stroke color of the Shape
    void
    setStroked(boolean stroked)
    Set flag indicating whether or not Shape should be stroked.
    void
    setStrokeWidth(double width)
    Set the stroke width for this Shape.
    void
    Set the Rectangle text
    void
    setTextColor(double gray)
    Set the gray scale text color with which to draw the shape.
    void
    setTextColor(double red, double green, double blue)
    Set the text color
    void
    setTextColor(double red, double green, double blue, double alpha)
    Set the text color
    void
    Set the text color by passing a Color object
    void
    Set a new AffineTransform for the Shape.
    void
    setVisible(boolean visible)
    Set visible status of Shape
    void
    setWidth(double width)
    Set a new Shape width.
    void
    Set the window location of the Shape
    void
    setX(double x)
    Set x-coordinate of Shape
    void
    setY(double y)
    Set y-coordinate of Shape
    void
    Move this shape to the beginning of the draw list
    void
    Move this shape to the end of the draw list
    Generate a representation of the Shape object.
    double[]
    toWindowCoords(double x, double y)
    Convert transformed Shape coordinates to window coordinates returns as a new Point object.
    Convert transformed Shape coordinates in a Point object to window coordinates returned as a new Point object.
    void
    translate(double deltaX, double deltaY)
    Add a translate to Shape transform.

    Methods inherited from class java.lang.Object

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

    • layer

      protected Layer layer
      The Layer on which this Shape is to be drawn
    • x

      protected double x
      The x-coordinate of the upper left-hand coordinate of the Shape's bounding box.
    • y

      protected double y
      The y-coordinate of the upper left-hand coordinate of the Shape's bounding box.
    • width

      protected double width
      The width of the Shape's bounding box.
    • height

      protected double height
      The height of the Shape's bounding box.
    • transform

      protected AffineTransform transform
      The current affine transform to be used when drawing this Shape
    • fillColor

      protected Color fillColor
      The fill color to be used to draw this Shape.
    • strokeColor

      protected Color strokeColor
      The stroke color to be used to draw this Shape.
    • strokeWidth

      protected double strokeWidth
      The width of the stroke used to draw this Shape.
    • visible

      protected boolean visible
      Flag to determine if Shape should be drawn.
    • filled

      protected boolean filled
      Flag to determine if Shape should be filled.
    • stroked

      protected boolean stroked
      Flag to determine if Shape should be stroked.
    • text

      protected String text
      The String to be displayed over a Shape
    • fontSize

      protected int fontSize
    • fontStyle

      protected int fontStyle
    • fontFamily

      protected String fontFamily
    • font

      protected Font font
      The Font to use to render the text
    • textFillColor

      protected Color textFillColor
      Color to use to render the text
    • eventsEnabled

      protected boolean eventsEnabled
      Flag indicating if this Shape should receive events
    • selected

      protected boolean selected
      Flag to indicate if this Shape is currently selected
    • selectable

      protected boolean selectable
      Flag to indicate if this Shape can be selected.
    • draggable

      protected boolean draggable
      Boolean indicating if this shape can be dragged.
    • shapeListener

      protected ShapeMouseListener shapeListener
      Inner class used to handle Shape mouse events.
  • Constructor Details

    • Shape

      public Shape(double x, double y, double width, double height, Layer layer)
      Constructor for Shape object. Optional Pad object parameter.
      Parameters:
      x - Shape x-coordinate
      y - Shape y-coordinate
      width - Shape width
      height - Shape height
      layer - Layer object to add Shape to, or null if not to add Shape to a Layer
  • Method Details

    • getPad

      public Pad getPad()
      A utility method that returns this Shape's Pad instance
      Returns:
      The current Pad singleton object.
    • getFilled

      public boolean getFilled()
      Get flag indicating whether or not Shape should be filled.
      Returns:
      Boolean indicating whether or not Shape should be filled.
    • setFilled

      public void setFilled(boolean filled)
      Set flag indicating whether or not Shape should be filled.
      Parameters:
      filled - true if Shape to be filled when drawn.
    • getFillColor

      public Color getFillColor()
      Get fill color that currently used to fill the shape when drawn
      Returns:
      The current fill color object
    • getFillRed

      public int getFillRed()
      Get the fill color red component
      Returns:
      The current fill color red component
    • getFillBlue

      public int getFillBlue()
      Get the fill color blue component
      Returns:
      The current fill color blue component
    • getFillGreen

      public int getFillGreen()
      Get the fill color green component
      Returns:
      The current fill color green component
    • getFillAlpha

      public int getFillAlpha()
      Get the fill color alpha component
      Returns:
      The current fill color alpha component
    • setFillColor

      public void setFillColor(double gray)
      Set the gray scale fill color with which to draw the shape.
      Parameters:
      gray - the gray scale value in the range [0, 255]
    • setFillColor

      public void setFillColor(double red, double green, double blue)
      Set the fill color with which to draw the shape
      Parameters:
      red - the red component of the color [0, 255]
      green - the green component of the color [0, 255]
      blue - the blue component of the color [0, 255]
    • setFillColor

      public void setFillColor(double red, double green, double blue, double alpha)
      Set the fill color with which to fill the shape
      Parameters:
      red - the red component of the color [0, 255]
      green - the green component of the color [0, 255]
      blue - the blue component of the color [0, 255]
      alpha - the color transparency [0, 255]
    • setFillColor

      public void setFillColor(Color color)
      Set the fill color by passing a Color object
      Parameters:
      color - the Color to be used for fill
    • getStroked

      public boolean getStroked()
      Get flag indicating whether or not Shape should be stroked.
      Returns:
      boolean indicating whether Shape is stroked
    • setStroked

      public void setStroked(boolean stroked)
      Set flag indicating whether or not Shape should be stroked.
      Parameters:
      stroked - true if Shape to be stroked when drawn.
    • getStrokeColor

      public Color getStrokeColor()
      Get the current Shape stroke color.
      Returns:
      Current Shape stroke color.
    • getStrokeRed

      public int getStrokeRed()
      Get the stroke color red component
      Returns:
      The current stroke color red component
    • getStrokeBlue

      public int getStrokeBlue()
      Get the stroke color blue component
      Returns:
      The current stroke color blue component
    • getStrokeGreen

      public int getStrokeGreen()
      Get the stroke color green component
      Returns:
      The current stroke color green component
    • getStrokeAlpha

      public int getStrokeAlpha()
      Get the stroke color alpha component
      Returns:
      The current stroke color alpha component
    • setStrokeColor

      public void setStrokeColor(double gray)
      Set the gray scale stroke color with which to draw the shape.
      Parameters:
      gray - the gray scale value in the range [0, 255]
    • setStrokeColor

      public void setStrokeColor(double red, double green, double blue)
      Set the current Shape stroke color.
      Parameters:
      red - the red component of the stroke color [0, 255]
      green - the green component of the stroke color [0, 255]
      blue - the blue component of the stroke color [0, 255]
    • setStrokeColor

      public void setStrokeColor(double red, double green, double blue, double alpha)
      Set the fill color with which to stroke the shape
      Parameters:
      red - the red component of the color [0, 255]
      green - the green component of the color [0, 255]
      blue - the blue component of the color [0, 255]
      alpha - the color transparency [0, 255]
    • setStrokeColor

      public void setStrokeColor(Color clr)
      Set the stroke color of the Shape
      Parameters:
      clr - the Color object to be used as the stroke color
    • getStrokeWidth

      public double getStrokeWidth()
      Get the current stroke width for this Shape.
      Returns:
      A float value for the current stroke width.
    • setStrokeWidth

      public void setStrokeWidth(double width)
      Set the stroke width for this Shape.
      Parameters:
      width - The stroke width value to set.
    • setText

      public void setText(String text)
      Set the Rectangle text
      Parameters:
      text - The internal text as a String
    • getText

      public String getText()
      Return the Rectangle object String
      Returns:
      The text of the object as a String
    • setTextColor

      public void setTextColor(double gray)
      Set the gray scale text color with which to draw the shape.
      Parameters:
      gray - the gray scale value in the range [0, 255]
    • setTextColor

      public void setTextColor(double red, double green, double blue)
      Set the text color
      Parameters:
      red - the red component of the color [0, 255]
      green - the green component of the color [0, 255]
      blue - the blue component of the color [0, 255]
    • setTextColor

      public void setTextColor(double red, double green, double blue, double alpha)
      Set the text color
      Parameters:
      red - the red component of the color [0, 255]
      green - the green component of the color [0, 255]
      blue - the blue component of the color [0, 255]
      alpha - the color transparency [0, 255]
    • setTextColor

      public void setTextColor(Color color)
      Set the text color by passing a Color object
      Parameters:
      color - the Color to be used for fill
    • setFontFamily

      public void setFontFamily(String fontFamily)
      Update the Font family for the text of this Rectangle object.
      Parameters:
      fontFamily - The Font family name (ex. "Arial")
    • getFontFamily

      public String getFontFamily()
      Return the Font family name for this Rectangle object.
      Returns:
      The Font family name String
    • setFontStyle

      public void setFontStyle(int fontStyle)
      Update the Font style for this Rectangle object.
      Parameters:
      fontStyle - The font style code (ex. 0 (Font.PLAIN), 1 (Font.BOLD), 2 (Font.ITALIC))
    • getFontStyle

      public int getFontStyle()
      Return the Font style code for this Rectangle object.
      Returns:
      The Font style code
    • setFontSize

      public void setFontSize(int fontSize)
      Update the Font size for this Rectangle object.
      Parameters:
      fontSize - The font size (ex. 10)
    • getFontSize

      public int getFontSize()
      Return the font size for this Text object.
      Returns:
      the font size.
    • setLocation

      public void setLocation(double x, double y)
      Set the current location of the shape and redraw it.
      Parameters:
      x - the x-value of the position
      y - the y-value of the position
    • setLocation

      public void setLocation(Point p)
      Set the current location of the shape and redraw it.
      Parameters:
      p - a Point object containing the coordinates of the new location
    • setPadLocation

      public void setPadLocation(Point p)
      Set the Pad location of the Shape
      Parameters:
      p - The point indicating Pad coordinates
    • setWindowLocation

      public void setWindowLocation(Point p)
      Set the window location of the Shape
      Parameters:
      p - The point indicating window coordinates
    • getLocation

      public Point getLocation()
      Return the current location of the shape as a Point object.
      Returns:
      A Point object representing the current upper left corner of the Shape's bounding box.
    • getPadLocation

      public Point getPadLocation()
      Get the coordinates of the Shape location in the Pad coordinate system
      Returns:
      A Point object holding Pad coordinates of the current Shape location
    • getWindowLocation

      public Point getWindowLocation()
      Get the coordinates of the Shape location in the window coordinate system
      Returns:
      A Point object holding window coordinates of the current Shape location
    • setCenter

      public void setCenter(double cx, double cy)
      Set the Shape position so that the center is at the given coordinates.
      Parameters:
      cx - the x-value of the position
      cy - the y-value of the position
    • setCenter

      public void setCenter(Point c)
      Set the Shape position so that the center is at the given Point.
      Parameters:
      c - the Point object indicating the center coordinates
    • getCenter

      public Point getCenter()
      Return the current center point of the shape as a Point object.
      Returns:
      A Point object representing the current center point of the Shape's bounding box.
    • getX

      public double getX()
      Get x-coordinate of Shape
      Returns:
      The Shape's x-coordinate
    • getY

      public double getY()
      Get y-coordinate of Shape
      Returns:
      The Shape's y-coordinate
    • setX

      public void setX(double x)
      Set x-coordinate of Shape
      Parameters:
      x - x-coordinate value
    • setY

      public void setY(double y)
      Set y-coordinate of Shape
      Parameters:
      y - y-coordinate value
    • move

      public void move(double dx, double dy)
      Move the Shape by the amounts specified in the x and y-directions
      Parameters:
      dx - Amount to move in the x-direction (pixels)
      dy - Amount to move in the y-direction (pixels)
    • setSize

      public void setSize(double width, double height)
      Reset the size of the Shape and trigger a repaint
      Parameters:
      width - new width
      height - new height
    • setSize

      public void setSize(Dimension d)
      Reset the size of the Shape and trigger a repaint
      Parameters:
      d - Dimension containing Shape size
    • getSize

      public Dimension getSize()
      Return the current Shape size as a Dimension object
      Returns:
      A Dimension object holding the Shape width and height
    • getWidth

      public double getWidth()
      Get the Shape's width
      Returns:
      A double that is the Shape's current width
    • setWidth

      public void setWidth(double width)
      Set a new Shape width.
      Parameters:
      width - A double value that is the new Shape width.
    • getHeight

      public double getHeight()
      Get the Shape's height
      Returns:
      A double that is the Shape's current height
    • setHeight

      public void setHeight(double height)
      Set a new Shape height.
      Parameters:
      height - A double value that is the new Shape height.
    • setEventsEnabled

      public void setEventsEnabled(boolean enabled)
      Set the boolean indicating whether or not the Shape will receive events that can be handled by overriding event methods
      Parameters:
      enabled - Boolean indicating if this Shape should receive events.
    • getEventsEnabled

      public boolean getEventsEnabled()
      Return setting that indicates if the Shape object will receive events that are implementable by overriding methods
      Returns:
      boolean indicating whether Shape receives events
    • setVisible

      public void setVisible(boolean visible)
      Set visible status of Shape
      Parameters:
      visible - Boolean indicating whether or not the Shape should be drawn.
    • getVisible

      public boolean getVisible()
      Get visible status of Shape
      Returns:
      true if the Shape is currently marked to be visible.
    • setSelected

      public void setSelected(boolean sel)
      Set the selected state of the Shape
      Parameters:
      sel - Boolean indicating if the Shapes should be selected
    • getSelected

      public boolean getSelected()
      Return selected state of this Shape.
      Returns:
      Boolean indicating the selected state of the Shape.
    • setSelectable

      public void setSelectable(boolean select)
      Set the flag that indicates if the shape can be selected
      Parameters:
      select - a boolean value (true/false) to assign to the flag
    • getSelectable

      public boolean getSelectable()
      Determine if the Shape is set so that it can be selected
      Returns:
      true if the Shape can be selected
    • setDraggable

      public void setDraggable(boolean drag)
      Set the flag that indicates if the shape can be dragged. If true, then also set selectable to true. Shapes cannot be dragged unless they can be selected.
      Parameters:
      drag - a boolean value (true/false) to assign to the flag
    • getDraggable

      public boolean getDraggable()
      Determine if the Shape is set so that it can be dragged
      Returns:
      true if the Shape can be dragged
    • toFront

      public void toFront()
      Move this shape to the end of the draw list
    • toBack

      public void toBack()
      Move this shape to the beginning of the draw list
    • toString

      public String toString()
      Generate a representation of the Shape object.
      Overrides:
      toString in class Object
      Returns:
      String representation
    • contains

      public boolean contains(double x, double y)
      Returns true if this shape contains the given point
      Parameters:
      x - The x-coordinate of the point to test
      y - The y-coordinate of the point to test
      Returns:
      true if the Shape contains the given point.
    • contains

      public boolean contains(Point p)
      Returns true if this shape contains the given point
      Parameters:
      p - a Point object containing the coordinates to be tested
      Returns:
      true if the Shape contains the given point.
    • getArea

      public Area getArea()
      Get a rectangular Area object that surrounds the Shape
      Returns:
      Rectangular Area object
    • getLayer

      public Layer getLayer()
      Return the Layer on which this Shape exists
      Returns:
      Layer holding this Shape
    • intersects

      public boolean intersects(Shape shp)
      Determine if the current Shape intersects with the shp Shape parameter
      Parameters:
      shp - The Shape with which to test intersection
      Returns:
      true if the intersection is not empty
    • repaint

      protected void repaint()
      Utility method to trigger a repaint of the entire Pad.
    • setMouseClickedHandler

      public void setMouseClickedHandler(Shape.ShapeMouseEventHandler handler)
      Assign an onMouseClicked event handler using a method reference.
      Parameters:
      handler - Method reference to an event handler
    • setMouseDoubleClickedHandler

      public void setMouseDoubleClickedHandler(Shape.ShapeMouseEventHandler handler)
      Assign an onMouseDoubleClicked event handler using a method reference.
      Parameters:
      handler - Method reference to an event handler
    • setMouseDraggedHandler

      public void setMouseDraggedHandler(Shape.ShapeMouseEventHandler handler)
      Assign an onMouseDragged event handler using a method reference.
      Parameters:
      handler - Method reference to an event handler
    • setMouseEnteredHandler

      public void setMouseEnteredHandler(Shape.ShapeMouseEventHandler handler)
      Assign an onMouseEntered event handler using a method reference.
      Parameters:
      handler - Method reference to an event handler
    • setMouseExitedHandler

      public void setMouseExitedHandler(Shape.ShapeMouseEventHandler handler)
      Assign an onMouseExited event handler using a method reference.
      Parameters:
      handler - Method reference to an event handler
    • setMouseMovedHandler

      public void setMouseMovedHandler(Shape.ShapeMouseEventHandler handler)
      Assign an onMouseMoved event handler using a method reference.
      Parameters:
      handler - Method reference to an event handler
    • setMousePressedHandler

      public void setMousePressedHandler(Shape.ShapeMouseEventHandler handler)
      Assign an onMousePressed event handler using a method reference.
      Parameters:
      handler - Method reference to an event handler
    • setMouseReleasedHandler

      public void setMouseReleasedHandler(Shape.ShapeMouseEventHandler handler)
      Assign an onMouseReleased event handler using a method reference.
      Parameters:
      handler - Method reference to an event handler
    • setSelectionChangedHandler

      public void setSelectionChangedHandler(Shape.ShapeSelectionEventHandler handler)
      Assign a selectionChanged event handler using a method reference.
      Parameters:
      handler - Method reference to an event handler
    • onMousePressed

      public void onMousePressed(double x, double y, int button)
      Handle mouse pressed Shape events. Override in subclasses to implement.
      Parameters:
      x - x-position of the mouse when event occurred
      y - y-position of the mouse when event occurred
      button - Integer indicating button pressed during event.
    • onMouseReleased

      public void onMouseReleased(double x, double y, int button)
      Handle mouse released Shape events. Override in subclasses to implement.
      Parameters:
      x - x-position of the mouse when event occurred
      y - y-position of the mouse when event occurred
      button - Integer indicating button pressed during event.
    • onMouseClicked

      public void onMouseClicked(double x, double y, int button)
      Handle mouse clicked Shape events. Override in subclasses to implement.
      Parameters:
      x - x-position of the mouse when event occurred
      y - y-position of the mouse when event occurred
      button - Integer indicating button pressed during event.
    • onMouseDoubleClicked

      public void onMouseDoubleClicked(double x, double y, int button)
      Handle mouse double-clicked Shape events. Override in subclasses to implement.
      Parameters:
      x - x-position of the mouse when event occurred
      y - y-position of the mouse when event occurred
      button - Integer indicating button pressed during event.
    • onMouseMoved

      public void onMouseMoved(double x, double y, int button)
      Handle mouse moved Shape events. Override in subclasses to implement.
      Parameters:
      x - x-position of the mouse when event occurred
      y - y-position of the mouse when event occurred
      button - Integer indicating button pressed during event.
    • onMouseDragged

      public void onMouseDragged(double x, double y, int button)
      Handle mouse dragged Shape events. Override in subclasses to implement.
      Parameters:
      x - x-position of the mouse when event occurred
      y - y-position of the mouse when event occurred
      button - Integer indicating button pressed during event.
    • onMouseEntered

      public void onMouseEntered(double x, double y, int button)
      Handle mouse entered Shape events. Override in subclasses to implement.
      Parameters:
      x - x-position of the mouse when event occurred
      y - y-position of the mouse when event occurred
      button - Integer indicating button pressed during event.
    • onMouseExited

      public void onMouseExited(double x, double y, int button)
      Handle mouse exited Shape events. Override in subclasses to implement.
      Parameters:
      x - x-position of the mouse when event occurred
      y - y-position of the mouse when event occurred
      button - Integer indicating button pressed during event.
    • onSelectionChanged

      public void onSelectionChanged(boolean sel)
      React to change in selection state by overriding
      Parameters:
      sel - Boolean indicating new selection state of Shape.
    • rotate

      public void rotate(double angle)
      Add a rotation angle to Shape transform.
      Parameters:
      angle - Adds the rotation angle to the current transform (degrees)
    • rotate

      public void rotate(double angle, double cx, double cy)
      Add a rotation angle to Shape transform.
      Parameters:
      angle - Adds the rotation angle to the current transform (degrees)
      cx - x-coordinate of point about which rotation occurs
      cy - y-coordinate of point about which rotation occurs
    • translate

      public void translate(double deltaX, double deltaY)
      Add a translate to Shape transform.
      Parameters:
      deltaX - Translate shape in the x-direction by deltaX
      deltaY - Translate shape in the y-direction by deltaY
    • scale

      public void scale(double factor)
      Add a scale factor to Shape transform.
      Parameters:
      factor - Scale the shape by a scale factor
    • scale

      public void scale(double factor, double cx, double cy)
      Add a scale factor to Shape transform.
      Parameters:
      factor - Scale the shape by a scale factor
      cx - x-coordinate of point about which scaling occurs
      cy - y-coordinate of point about which scaling occurs
    • scale

      public void scale(double xFactor, double yFactor)
      Add a scale factor to Shape transform.
      Parameters:
      xFactor - Scale the shape in the x-direction by a xFactor
      yFactor - Scale the shape in the y-direction by a yFactor
    • scale

      public void scale(double xFactor, double yFactor, double cx, double cy)
      Add a scale factor to Shape transform.
      Parameters:
      xFactor - Scale the shape in the x-direction by a xFactor
      yFactor - Scale the shape in the y-direction by a yFactor
      cx - x-coordinate of point about which scaling occurs
      cy - y-coordinate of point about which scaling occurs
    • reset

      public void reset()
      Resets the shape to have no transformation.
    • getTransform

      public AffineTransform getTransform()
      Clone the Shape\'s current AffineTransform.
      Returns:
      The cloned AffineTransform.
    • setTransform

      public void setTransform(AffineTransform transform)
      Set a new AffineTransform for the Shape.
      Parameters:
      transform - The new transform.
    • toWindowCoords

      public double[] toWindowCoords(double x, double y)
      Convert transformed Shape coordinates to window coordinates returns as a new Point object. This method is useful for converting transformed coordinates received from a Shape mouse event method back to original window coordinates.
      Parameters:
      x - Transformed x-coordinate
      y - Transformed y-coordinate
      Returns:
      A Point object containing the transformed coordinates
    • toWindowCoords

      public Point toWindowCoords(Point pt)
      Convert transformed Shape coordinates in a Point object to window coordinates returned as a new Point object. This method is useful for converting transformed coordinates received from a Shape mouse event method back to original window coordinates.
      Parameters:
      pt - A Point object
      Returns:
      A new Point object containing the transformed coordinates
    • drawText

      protected void drawText(Graphics2D g)
      Draw the text over a Shape
      Parameters:
      g - The Graphics2D on which to draw the hit region
    • draw

      public abstract void draw(Graphics2D g)
      Draw the shape. Abstract method to be overridden in subclasses.
      Parameters:
      g - The Graphics2D object on which to draw.