Class ShapeFactory<T>


  • public class ShapeFactory<T>
    extends Object
    A utility class for generating Shapes for drawing objects. The available shapes include rectangles, rounded rectangles, ellipses, regular polygons, and regular stars. The dimensions of the requested shapes are defined by the specified size function (specified by a Function<T, Integer>) and aspect ratio function (specified by a Function<T, Float>) implementations: the width of the bounding box of the shape is given by the size, and the height is given by the size multiplied by the aspect ratio.
    • Constructor Summary

      Constructors 
      Constructor Description
      ShapeFactory()
      Creates a ShapeFactory with a constant size of 10 and a constant aspect ratio of 1.
      ShapeFactory​(Function<T,​Integer> sizeFunction, Function<T,​Float> aspectRatioFunction)
      Creates an instance with the specified size and aspect ratio functions.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Shape getEllipse​(T t)
      Returns a Ellipse2D whose width and height are defined by this instance's size and aspect ratio functions.
      Shape getRectangle​(T t)
      Returns a Rectangle2D whose width and height are defined by this instance's size and aspect ratio functions.
      Shape getRectangle​(T t, double rotation)
      Returns a Rectangle2D whose width and height are defined by this instance's size and aspect ratio functions.
      Shape getRegularPolygon​(T t, int sides)
      Returns a regular sides-sided Polygon whose bounding box's width and height are defined by this instance's size and aspect ratio functions.
      Shape getRegularPolygon​(T t, int sides, double rotation)
      Returns a regular sides-sided Polygon whose bounding box's width and height are defined by this instance's size and aspect ratio functions.
      Shape getRegularStar​(T t, int points)
      Returns a regular Polygon of points points whose bounding box's width and height are defined by this instance's layoutSize and aspect ratio functions.
      RoundRectangle2D getRoundRectangle​(T t)
      Returns a RoundRectangle2D whose width and height are defined by this instance's size and aspect ratio functions.
    • Constructor Detail

      • ShapeFactory

        public ShapeFactory​(Function<T,​Integer> sizeFunction,
                            Function<T,​Float> aspectRatioFunction)
        Creates an instance with the specified size and aspect ratio functions.
        Parameters:
        sizeFunction - provides a size (width) for each input object
        aspectRatioFunction - provides a height/width ratio for each input object
      • ShapeFactory

        public ShapeFactory()
        Creates a ShapeFactory with a constant size of 10 and a constant aspect ratio of 1.
    • Method Detail

      • getRectangle

        public Shape getRectangle​(T t,
                                  double rotation)
        Returns a Rectangle2D whose width and height are defined by this instance's size and aspect ratio functions.
        Parameters:
        t - the object for which the shape will be drawn
        Returns:
        a rectangle for this input T
      • getRectangle

        public Shape getRectangle​(T t)
        Returns a Rectangle2D whose width and height are defined by this instance's size and aspect ratio functions.
        Parameters:
        t - the object for which the shape will be drawn
        Returns:
        a rectangle for this input T
      • getEllipse

        public Shape getEllipse​(T t)
        Returns a Ellipse2D whose width and height are defined by this instance's size and aspect ratio functions.
        Parameters:
        t - the object for which the shape will be drawn
        Returns:
        an ellipse for input T
      • getRoundRectangle

        public RoundRectangle2D getRoundRectangle​(T t)
        Returns a RoundRectangle2D whose width and height are defined by this instance's size and aspect ratio functions. The arc layoutSize is set to be half the minimum of the height and width of the frame.
        Parameters:
        t - the object for which the shape will be drawn
        Returns:
        an round rectangle for this input T
      • getRegularPolygon

        public Shape getRegularPolygon​(T t,
                                       int sides,
                                       double rotation)
        Returns a regular sides-sided Polygon whose bounding box's width and height are defined by this instance's size and aspect ratio functions.
        Parameters:
        t - the T for which the shape will be drawn
        sides - the number of sides of the polygon; must be ≥ 3.
        Returns:
        a regular polygon for this t
      • getRegularPolygon

        public Shape getRegularPolygon​(T t,
                                       int sides)
        Returns a regular sides-sided Polygon whose bounding box's width and height are defined by this instance's size and aspect ratio functions.
        Parameters:
        t - the T for which the shape will be drawn
        sides - the number of sides of the polygon; must be ≥ 3.
        Returns:
        a regular polygon for this t
      • getRegularStar

        public Shape getRegularStar​(T t,
                                    int points)
        Returns a regular Polygon of points points whose bounding box's width and height are defined by this instance's layoutSize and aspect ratio functions.
        Parameters:
        t - the input T for which the shape will be drawn
        points - the number of points of the polygon; must be ≥ 5.
        Returns:
        an star shape for this t