Package org.jungrapht.visualization.util
Class ShapeFactory<T>
- java.lang.Object
-
- org.jungrapht.visualization.util.ShapeFactory<T>
-
public class ShapeFactory<T> extends Object
A utility class for generatingShape
s 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 aFunction<T, Integer>
) and aspect ratio function (specified by aFunction<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.
-
-
Field Summary
Fields Modifier and Type Field Description protected Function<T,Float>
aspectRatioFunction
protected Function<T,Integer>
sizeFunction
-
Constructor Summary
Constructors Constructor Description ShapeFactory()
Creates aShapeFactory
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 aEllipse2D
whose width and height are defined by this instance's size and aspect ratio functions.Shape
getRectangle(T t)
Returns aRectangle2D
whose width and height are defined by this instance's size and aspect ratio functions.Shape
getRectangle(T t, double rotation)
Returns aRectangle2D
whose width and height are defined by this instance's size and aspect ratio functions.Shape
getRegularPolygon(T t, int sides)
Returns a regularsides
-sidedPolygon
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 regularsides
-sidedPolygon
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 regularPolygon
ofpoints
points whose bounding box's width and height are defined by this instance's layoutSize and aspect ratio functions.RoundRectangle2D
getRoundRectangle(T t)
Returns aRoundRectangle2D
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 objectaspectRatioFunction
- provides a height/width ratio for each input object
-
ShapeFactory
public ShapeFactory()
Creates aShapeFactory
with a constant size of 10 and a constant aspect ratio of 1.
-
-
Method Detail
-
getRectangle
public Shape getRectangle(T t, double rotation)
Returns aRectangle2D
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 aRectangle2D
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 aEllipse2D
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 aRoundRectangle2D
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 regularsides
-sidedPolygon
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 drawnsides
- 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 regularsides
-sidedPolygon
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 drawnsides
- 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 regularPolygon
ofpoints
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 drawnpoints
- the number of points of the polygon; must be ≥ 5.- Returns:
- an star shape for this t
-
-