Class CubicPath

  • All Implemented Interfaces:
    Shape


    public final class CubicPath
    extends AbstractShape
    This is an editable path based on cubic bezier segments. Each node has "previous" and "next" control point.

    The scale factor is used to limit the magnitude of the the control points.

    Several methods have two sets of arguments:

    • One only accepting the nodeIndex. This looks at all nodes in the entire shape.
    • One accepting a nodeIndex and pathIndex. This breaks the shape up into separate paths, and looks at all the nodes in a given path.
    See Also:
    com.bric.plaf.CubicPathCreationUI
    • Constructor Summary

      Constructors

      Constructor and Description
      CubicPath()
      Creates an empty CubicPath.
      CubicPath(int windingRule)
      Creates an empty CubicPath.
    • Method Summary

      Modifier and Type Method and Description
      void append(Shape s)
      This will append the argument to this shape.
      void clear()
      Empties this shape.
      Object clone()
      Clones this CubicPath.
      void curveTo(float cx1, float cy1, float cx2, float cy2, float x2, float y2)
      This is analogous to GeneralPath.curveTo().
      void curveTo(int pathIndex, float cx1, float cy1, float cx2, float cy2, float x2, float y2)
      This is analogous to GeneralPath.curveTo().
      Point2D getNextControlForNode(int pathIndex, int nodeIndex, Point2D dest)
      Returns the next control point.
      Point2D getNextControlForNode(int nodeIndex, Point2D dest)
      Returns the next control point.
      Point2D getNextNode(int pathIndex, int nodeIndex, Point2D dest)
      Gets the next node after the indicated node.
      Point2D getNextNode(int nodeIndex, Point2D dest)
      Gets the next node after the indicated node.
      Point2D getNode(int pathIndex, int nodeIndex, Point2D dest)
      Returns the coordinates of a node.
      Point2D getNode(int nodeIndex, Point2D dest)
      Returns the coordinates of a node.
      int getNodeCount()
      Return the number of nodes in all paths.
      int getNodeCount(int pathIndex)
      Return the number of nodes in a given path.
      int getPathCount()
      Return the number of paths in this shape.
      PathIterator getPathIterator(AffineTransform transform)
      Returns a PathIterator that iterates over this shape.
      Point2D getPrevControlForNode(int pathIndex, int nodeIndex, Point2D dest)
      Returns the previous control point.
      Point2D getPrevControlForNode(int nodeIndex, Point2D dest)
      Returns the previous control point.
      Point2D getPrevNode(int pathIndex, int nodeIndex, Point2D dest)
      Gets the previous node before the indicated node.
      Point2D getPrevNode(int nodeIndex, Point2D dest)
      Gets the previous node before the indicated node.
      double getScaleFactor()
      Returns the scale factor.
      int getWindingRule()
      Returns the winding rule.
      boolean hasNextControlForNode(int nodeIndex)
      Returns whether a node has a next control point.
      boolean hasNextControlForNode(int pathIndex, int nodeIndex)
      Returns whether a node has a next control point.
      boolean hasPrevControlForNode(int nodeIndex)
      Returns whether a node has a previous control point.
      boolean hasPrevControlForNode(int pathIndex, int nodeIndex)
      Returns whether a node has a previous control point.
      boolean isEmpty()
      Return true if this path is empty.
      boolean isNodeSharp(int nodeIndex)
      A "sharp" node is a node that doesn't have a control points.
      boolean isNodeSharp(int pathIndex, int nodeIndex)
      A "sharp" node is a node that doesn't have a control points.
      boolean isNodeSmooth(int nodeIndex, boolean equalDistance)
      A "smooth" node is a node where the two control points are collinear.
      boolean isNodeSmooth(int pathIndex, int nodeIndex, boolean equalDistance)
      A "smooth" node is a node where the two control points are collinear.
      void lineTo(float x, float y)
      This is analogous to GeneralPath.lineTo().
      void lineTo(int pathIndex, float x, float y)
      This is analogous to GeneralPath.lineTo().
      int moveTo(float x, float y)
      This starts a new path.
      void removeNode(int nodeIndex)
      Removes a node from the last path in this shape.
      void removeNode(int pathIndex, int nodeIndex)
      Removes a node from a specified path.
      boolean setNextControlForNode(int nodeIndex, double x, double y)
      Sets the next control point for a node.
      boolean setNextControlForNode(int pathIndex, int nodeIndex, double x, double y)
      Sets the next control point for a node.
      boolean setNextControlForNode(int pathIndex, int nodeIndex, Point2D p)
      Sets the next control point for a node.
      boolean setNextControlForNode(int nodeIndex, Point2D p)
      Sets the next control point for a node.
      boolean setNextControlForNodeFromPrev(int nodeIndex, boolean includeDistance)
      Sets the coordinates of the next control point for a node based on the previous control point.
      boolean setNextControlForNodeFromPrev(int pathIndex, int nodeIndex, boolean includeDistance)
      Sets the coordinates of the next control point for a node based on the previous control point.
      boolean setNode(int nodeIndex, double x, double y, boolean translateControlPoints)
      Sets a node's location.
      boolean setNode(int pathIndex, int nodeIndex, double x, double y, boolean translateControlPoints)
      Sets a node's location.
      boolean setNode(int pathIndex, int nodeIndex, Point2D p, boolean translateControlPoints)
      Sets a node's location.
      boolean setNode(int nodeIndex, Point2D p, boolean translateControlPoints)
      Sets a node's location.
      boolean setPrevControlForNode(int nodeIndex, double x, double y)
      Sets the previous control point for a node.
      boolean setPrevControlForNode(int pathIndex, int nodeIndex, double x, double y)
      Sets the previous control point for a node.
      boolean setPrevControlForNode(int pathIndex, int nodeIndex, Point2D p)
      Sets the previous control point for a node.
      boolean setPrevControlForNode(int nodeIndex, Point2D p)
      Sets the coordinates of the previous control point for a node.
      boolean setPrevControlForNodeFromNext(int nodeIndex, boolean includeDistance)
      Sets the coordinates of the previous control point for a node based on the next control point.
      boolean setPrevControlForNodeFromNext(int pathIndex, int nodeIndex, boolean includeDistance)
      Sets the coordinates of the previous control point for a node based on the next control point.
      boolean setScaleFactor(double sf)
      This sets the scale factor for this shape.
      void setWindingRule(int newRule)
      Sets the winding rule.
      String toString()
      Returns a String representation of this shape.
    • Constructor Detail

      • CubicPath

        public CubicPath()
        Creates an empty CubicPath.
      • CubicPath

        public CubicPath(int windingRule)
        Creates an empty CubicPath.
        Parameters:
        windingRule - the winding rule.
    • Method Detail

      • setScaleFactor

        public boolean setScaleFactor(double sf)
        This sets the scale factor for this shape. The default value is 1.0.
        Parameters:
        sf - new the scale factor. This must be greater than zero.
        Returns:
        true if this changed the scale factor.
      • getScaleFactor

        public double getScaleFactor()
        Returns the scale factor.
      • clone

        public Object clone()
        Clones this CubicPath.
      • isNodeSharp

        public boolean isNodeSharp(int nodeIndex)
        A "sharp" node is a node that doesn't have a control points.
        Parameters:
        nodeIndex - the node to examine.
        Returns:
        true if the node is sharp.
      • isEmpty

        public boolean isEmpty()
        Return true if this path is empty.
      • isNodeSharp

        public boolean isNodeSharp(int pathIndex,
                                   int nodeIndex)
        A "sharp" node is a node that doesn't have a control points.
        Parameters:
        pathIndex - the path to examine.
        nodeIndex - the node to examine.
        Returns:
        true if the node is sharp.
      • isNodeSmooth

        public boolean isNodeSmooth(int nodeIndex,
                                    boolean equalDistance)
        A "smooth" node is a node where the two control points are collinear.
        Parameters:
        nodeIndex - the node to examine.
        equalDistance - if this is true then the control points have to be collinear and equidistant to the node point.
        Returns:
        true if the node is smooth.
      • isNodeSmooth

        public boolean isNodeSmooth(int pathIndex,
                                    int nodeIndex,
                                    boolean equalDistance)
        A "smooth" node is a node where the two control points are collinear.
        Parameters:
        pathIndex - the path to examine.
        nodeIndex - the node to examine.
        equalDistance - if this is true then the control points have to be collinear and equidistant to the node point.
        Returns:
        true if the node is smooth.
      • setNode

        public boolean setNode(int nodeIndex,
                               Point2D p,
                               boolean translateControlPoints)
        Sets a node's location.
        Parameters:
        nodeIndex - the node to change.
        p - the new coordinates of the node.
        translateControlPoints - whether the control points should translate similarly.
        Returns:
        true if data was modified by this call.
      • setNode

        public boolean setNode(int nodeIndex,
                               double x,
                               double y,
                               boolean translateControlPoints)
        Sets a node's location.
        Parameters:
        nodeIndex - the node to change.
        x - the new x-coordinate of the node.
        y - the new y-coordinate of the node.
        translateControlPoints - whether the control points should translate similarly.
        Returns:
        true if data was modified by this call.
      • setNode

        public boolean setNode(int pathIndex,
                               int nodeIndex,
                               Point2D p,
                               boolean translateControlPoints)
        Sets a node's location.
        Parameters:
        pathIndex - the path to change.
        nodeIndex - the node to change.
        p - the new coordinates of the node.
        translateControlPoints - whether the control points should translate similarly.
        Returns:
        true if data was modified by this call.
      • setNode

        public boolean setNode(int pathIndex,
                               int nodeIndex,
                               double x,
                               double y,
                               boolean translateControlPoints)
        Sets a node's location.
        Parameters:
        pathIndex - the path to change.
        nodeIndex - the node to change.
        x - the new x-coordinate of the node.
        y - the new y-coordinate of the node.
        translateControlPoints - whether the control points should translate similarly.
        Returns:
        true if data was modified by this call.
      • getPathCount

        public int getPathCount()
        Return the number of paths in this shape.
      • getNodeCount

        public int getNodeCount(int pathIndex)
        Return the number of nodes in a given path.
        Parameters:
        pathIndex - the path to get the node count of.
        Returns:
        the number of nodes in a given path.
      • getNodeCount

        public int getNodeCount()
        Return the number of nodes in all paths.
        Returns:
        the number of nodes in all paths.
      • removeNode

        public void removeNode(int nodeIndex)
        Removes a node from the last path in this shape.
      • removeNode

        public void removeNode(int pathIndex,
                               int nodeIndex)
        Removes a node from a specified path.
      • getNode

        public Point2D getNode(int nodeIndex,
                               Point2D dest)
        Returns the coordinates of a node.
        Parameters:
        nodeIndex - the node index.
        dest - the object to store the coordinates in. May be null.
        Returns:
        this will return the dest argument if it wasn't null.
      • clear

        public void clear()
        Empties this shape.
      • getNode

        public Point2D getNode(int pathIndex,
                               int nodeIndex,
                               Point2D dest)
        Returns the coordinates of a node.
        Parameters:
        pathIndex - the path index.
        nodeIndex - the node index.
        dest - the object to store the coordinates in. May be null.
        Returns:
        this will return the dest argument if it wasn't null.
      • setPrevControlForNode

        public boolean setPrevControlForNode(int nodeIndex,
                                             Point2D p)
        Sets the coordinates of the previous control point for a node.
        Parameters:
        nodeIndex - the node index.
        p - the object to store the coordinates in. May be null.
        Returns:
        this will return null if there is no previous control point for this node. Or this will return p if it wasn't null.
      • setNextControlForNodeFromPrev

        public boolean setNextControlForNodeFromPrev(int pathIndex,
                                                     int nodeIndex,
                                                     boolean includeDistance)
        Sets the coordinates of the next control point for a node based on the previous control point.
        Parameters:
        pathIndex - the path index.
        nodeIndex - the node index.
        includeDistance - whether the distances between control points and the node should be equal.
        Returns:
        true if this changed the shape.
      • setNextControlForNodeFromPrev

        public boolean setNextControlForNodeFromPrev(int nodeIndex,
                                                     boolean includeDistance)
        Sets the coordinates of the next control point for a node based on the previous control point.
        Parameters:
        nodeIndex - the node index.
        includeDistance - whether the distances between control points and the node should be equal.
        Returns:
        true if this changed the shape.
      • setPrevControlForNodeFromNext

        public boolean setPrevControlForNodeFromNext(int pathIndex,
                                                     int nodeIndex,
                                                     boolean includeDistance)
        Sets the coordinates of the previous control point for a node based on the next control point.
        Parameters:
        pathIndex - the path index.
        nodeIndex - the node index.
        includeDistance - whether the distances between control points and the node should be equal.
        Returns:
        true if this changed the shape.
      • setPrevControlForNodeFromNext

        public boolean setPrevControlForNodeFromNext(int nodeIndex,
                                                     boolean includeDistance)
        Sets the coordinates of the previous control point for a node based on the next control point.
        Parameters:
        nodeIndex - the node index.
        includeDistance - whether the distances between control points and the node should be equal.
        Returns:
        true if this changed the shape.
      • setPrevControlForNode

        public boolean setPrevControlForNode(int nodeIndex,
                                             double x,
                                             double y)
        Sets the previous control point for a node.
        Parameters:
        nodeIndex - the node index.
        x - the new x-coordinate of the control point.
        y - the new y-coordinate of the control point.
        Returns:
        true if this changed this shape.
      • setNextControlForNode

        public boolean setNextControlForNode(int nodeIndex,
                                             Point2D p)
        Sets the next control point for a node.
        Parameters:
        nodeIndex - the node index.
        p - the new coordinates of the control point.
        Returns:
        true if this changed this shape.
      • setNextControlForNode

        public boolean setNextControlForNode(int nodeIndex,
                                             double x,
                                             double y)
        Sets the next control point for a node.
        Parameters:
        nodeIndex - the node index.
        x - the new x-coordinate of the control point.
        y - the new y-coordinate of the control point.
        Returns:
        true if this changed this shape.
      • getNextNode

        public Point2D getNextNode(int nodeIndex,
                                   Point2D dest)
        Gets the next node after the indicated node. This may be useful if nodeIndex is the last node of a path and the "next" node is the zeroth node in this path.
        Parameters:
        nodeIndex - the node index.
        dest - the optional destination for the coordinates.
        Returns:
        the coordinates of the next node.
      • getNextNode

        public Point2D getNextNode(int pathIndex,
                                   int nodeIndex,
                                   Point2D dest)
        Gets the next node after the indicated node. This may be useful if nodeIndex is the last node of a path and the "next" node is the zeroth node in this path.
        Parameters:
        pathIndex - the path index.
        nodeIndex - the node index.
        dest - the optional destination for the coordinates.
        Returns:
        the coordinates of the next node.
      • getPrevNode

        public Point2D getPrevNode(int nodeIndex,
                                   Point2D dest)
        Gets the previous node before the indicated node. This may be useful if nodeIndex is the zeroth node of a path and the "previous" node is the last node in this path.
        Parameters:
        nodeIndex - the node index.
        dest - the optional destination for the coordinates.
        Returns:
        the coordinates of the previous node.
      • getPrevNode

        public Point2D getPrevNode(int pathIndex,
                                   int nodeIndex,
                                   Point2D dest)
        Gets the previous node before the indicated node. This may be useful if nodeIndex is the zeroth node of a path and the "previous" node is the last node in this path.
        Parameters:
        pathIndex - the path index.
        nodeIndex - the node index.
        dest - the optional destination for the coordinates.
        Returns:
        the coordinates of the previous node.
      • setPrevControlForNode

        public boolean setPrevControlForNode(int pathIndex,
                                             int nodeIndex,
                                             Point2D p)
        Sets the previous control point for a node.
        Parameters:
        pathIndex - the path index.
        nodeIndex - the node index.
        p - the new coordinates of the control point.
        Returns:
        true if this changed this shape.
      • setPrevControlForNode

        public boolean setPrevControlForNode(int pathIndex,
                                             int nodeIndex,
                                             double x,
                                             double y)
        Sets the previous control point for a node.
        Parameters:
        pathIndex - the path index.
        nodeIndex - the node index.
        x - the new x-coordinate of the control point.
        y - the new y-coordinate of the control point.
        Returns:
        true if this changed this shape.
      • setNextControlForNode

        public boolean setNextControlForNode(int pathIndex,
                                             int nodeIndex,
                                             Point2D p)
        Sets the next control point for a node.
        Parameters:
        pathIndex - the path index.
        nodeIndex - the node index.
        p - the new coordinates of the control point.
        Returns:
        true if this changed this shape.
      • setNextControlForNode

        public boolean setNextControlForNode(int pathIndex,
                                             int nodeIndex,
                                             double x,
                                             double y)
        Sets the next control point for a node.
        Parameters:
        pathIndex - the path index.
        nodeIndex - the node index.
        x - the new x-coordinate of the control point.
        y - the new y-coordinate of the control point.
        Returns:
        true if this changed this shape.
      • getNextControlForNode

        public Point2D getNextControlForNode(int nodeIndex,
                                             Point2D dest)
        Returns the next control point.
        Parameters:
        nodeIndex - the node index.
        dest - the optional destination to store the control point in.
        Returns:
        may return null if there is no next control point for a node. Otherwise this will return dest if it is non-null.
      • hasNextControlForNode

        public boolean hasNextControlForNode(int nodeIndex)
        Returns whether a node has a next control point.
        Parameters:
        nodeIndex - the node index.
        Returns:
        whether a node has a next control point.
      • hasPrevControlForNode

        public boolean hasPrevControlForNode(int nodeIndex)
        Returns whether a node has a previous control point.
        Parameters:
        nodeIndex - the node index.
        Returns:
        whether a node has a next control point.
      • hasNextControlForNode

        public boolean hasNextControlForNode(int pathIndex,
                                             int nodeIndex)
        Returns whether a node has a next control point.
        Parameters:
        pathIndex - the path index.
        nodeIndex - the node index.
        Returns:
        whether a node has a next control point.
      • hasPrevControlForNode

        public boolean hasPrevControlForNode(int pathIndex,
                                             int nodeIndex)
        Returns whether a node has a previous control point.
        Parameters:
        pathIndex - the path index.
        nodeIndex - the node index.
        Returns:
        whether a node has a next control point.
      • getPrevControlForNode

        public Point2D getPrevControlForNode(int nodeIndex,
                                             Point2D dest)
        Returns the previous control point.
        Parameters:
        nodeIndex - the node index.
        dest - the optional destination to store the control point in.
        Returns:
        may return null if there is no next control point for a node. Otherwise this will return dest if it is non-null.
      • getPrevControlForNode

        public Point2D getPrevControlForNode(int pathIndex,
                                             int nodeIndex,
                                             Point2D dest)
        Returns the previous control point.
        Parameters:
        nodeIndex - the node index.
        dest - the optional destination to store the control point in.
        Returns:
        may return null if there is no next control point for a node. Otherwise this will return dest if it is non-null.
      • getNextControlForNode

        public Point2D getNextControlForNode(int pathIndex,
                                             int nodeIndex,
                                             Point2D dest)
        Returns the next control point.
        Parameters:
        pathIndex - the path index.
        nodeIndex - the node index.
        dest - the optional destination to store the control point in.
        Returns:
        may return null if there is no next control point for a node. Otherwise this will return dest if it is non-null.
      • moveTo

        public int moveTo(float x,
                          float y)
        This starts a new path.
        Parameters:
        x - the x-coordinate to move to.
        y - the y-coordinate to move to.
        Returns:
        the path index of this new path.
      • curveTo

        public void curveTo(float cx1,
                            float cy1,
                            float cx2,
                            float cy2,
                            float x2,
                            float y2)
        This is analogous to GeneralPath.curveTo().
        Parameters:
        cx1 - the x-coordinate of the first control point.
        cy1 - the y-coordinate of the first control point.
        cx2 - the x-coordinate of the second control point.
        cy2 - the y-coordinate of the second control point.
        x2 - the x-coordinate of the end point.
        y2 - the y-coordinate of the end point.
      • curveTo

        public void curveTo(int pathIndex,
                            float cx1,
                            float cy1,
                            float cx2,
                            float cy2,
                            float x2,
                            float y2)
        This is analogous to GeneralPath.curveTo().
        Parameters:
        pathIndex - the path to append this curve to.
        cx1 - the x-coordinate of the first control point.
        cy1 - the y-coordinate of the first control point.
        cx2 - the x-coordinate of the second control point.
        cy2 - the y-coordinate of the second control point.
        x2 - the x-coordinate of the end point.
        y2 - the y-coordinate of the end point.
      • lineTo

        public void lineTo(float x,
                           float y)
        This is analogous to GeneralPath.lineTo().
        Parameters:
        x - the x-coordinate of the end point.
        y - the y-coordinate of the end point.
      • lineTo

        public void lineTo(int pathIndex,
                           float x,
                           float y)
        This is analogous to GeneralPath.lineTo().
        Parameters:
        pathIndex - the path index.
        x - the x-coordinate of the end point.
        y - the y-coordinate of the end point.
      • append

        public final void append(Shape s)
        This will append the argument to this shape.
        Parameters:
        s - the shape to append.
      • toString

        public String toString()
        Returns a String representation of this shape.
      • getWindingRule

        public int getWindingRule()
        Returns the winding rule.
        Specified by:
        getWindingRule in class  AbstractShape
        Returns:
        this will be WIND_NON_ZERO or WIND_EVEN_ODD.
      • setWindingRule

        public void setWindingRule(int newRule)
        Sets the winding rule.
        Parameters:
        newRule - the new winding rule. This must be WIND_NON_ZERO or WIND_EVEN_ODD.
      • getPathIterator

        public PathIterator getPathIterator(AffineTransform transform)
        Returns a PathIterator that iterates over this shape.