Class ShapeStringUtils



  • public class ShapeStringUtils
    extends Object
    This is a small set of static methods that translate shape data into java.lang.Strings and vice versa.
    • Constructor Detail

      • ShapeStringUtils

        public ShapeStringUtils()
    • Method Detail

      • toString

        public static String toString(Shape s)
        This describes a shape in a String. The model is used is based on how SVG encodes shape data.

        The call:
        ShapeUtils.createPathIterator(ShapeUtils.toString(shape));
        should result in an identical shape.

        The shape data is formatted as a single letter (m, l, q, c, z) followed by the appropriate number of points (2, 2, 4, 6, 0 respectively). This uses floats, not doubles, so it will not contain strings with an exponent (i.e. "1.3e-4").

        Parameters:
        s - the shape to describe
        Returns:
        textual representation of that shape.
      • createPathIterator

        public static PathIterator createPathIterator(String s)
        This creates a PathIterator that iterates over the text in s.

        The shape returned uses winding rule WIND_EVEN_ODD.

        Parameters:
        s - textual representation of a path.

        This should be the output of ShapeUtils.toString(), resembling: "m 1 2 l 3 4 q 5 6 7 8 c 9 10 11 12 13 14 z"

        Returns:
        a PathIterator that will iterate over the data in s.
      • createGeneralPath

        public static GeneralPath createGeneralPath(String s)
        This creates a GeneralPath of rule WIND_EVEN_ODD that represents this shape data.

        This method simply calls:
        GeneralPath p = new GeneralPath();
        p.append(createPathIterator(s),true);
        return p;

        Parameters:
        s - textual representation of a path.

        This should be the output of ShapeUtils.toString(), resembling: "m 1 2 l 3 4 q 5 6 7 8 c 9 10 11 12 13 14 z"

        Returns:
        a GeneralPath that represents this shape.
      • createPathIterator

        public static PathIterator createPathIterator(String s,
                                                      int windingRule)
        This creates a PathIterator that iterates over the text in s.
        Parameters:
        s - textual representation of a path.
        windingRule - the winding rule to use. (This should be PathIterator.WIND_NON_ZERO or PathIterator.WIND_EVEN_ODD.)

        This should be the output of ShapeUtils.toString(), resembling: "m 1 2 l 3 4 q 5 6 7 8 c 9 10 11 12 13 14 z"

        Returns:
        a PathIterator that will iterate over the data in s.