Class PathBuilder


  • public class PathBuilder
    extends Object
    Builder class for paths. All methods for constructing path elements return a reference to the builder, so that it can be used like:
      PathBuilder builder = new PathBuilder();
      builder.moveTo(p1).lineTo(p1).close();
      GeneralPath path = builder.createPath();
     
    Author:
    Arvid
    Source code:
    main
    Belongs to CDK module:
    renderbasic
    • Constructor Detail

      • PathBuilder

        public PathBuilder()
        Make a new path builder with a default color of black.
      • PathBuilder

        public PathBuilder​(Color color)
        Make a path builder that will make a path with a particular color.
        Parameters:
        color - the color of the path
    • Method Detail

      • moveTo

        public PathBuilder moveTo​(javax.vecmath.Point2d point)
        Make a move in the path, without drawing anything. This is usually used to start a path.
        Parameters:
        point - the point to move to
        Returns:
        a reference to this builder
      • lineTo

        public PathBuilder lineTo​(javax.vecmath.Point2d point)
        Make a line in the path, from the last point to the given point.
        Parameters:
        point - the point to make a line to
        Returns:
        a reference to this builder
      • quadTo

        public PathBuilder quadTo​(javax.vecmath.Point2d cp,
                                  javax.vecmath.Point2d ep)
        Make a quadratic curve in the path, with one control point.
        Parameters:
        cp - the control point of the curve
        ep - the end point of the curve
        Returns:
        a reference to this builder
      • cubicTo

        public PathBuilder cubicTo​(javax.vecmath.Point2d cp1,
                                   javax.vecmath.Point2d cp2,
                                   javax.vecmath.Point2d ep)
        Make a cubic curve in the path, with two control points.
        Parameters:
        cp1 - the first control point
        cp2 - the second control point
        ep - the end point of the curve
        Returns:
        a reference to this builder
      • close

        public void close()
        Close the path.
      • color

        public PathBuilder color​(Color color)
        Sets the color if this path.
        Parameters:
        color - the new Color.
        Returns:
        returns itself.
      • createPath

        public GeneralPath createPath()
        Create and return the final path.
        Returns:
        the newly created path