view
Class ShapeFactory

java.lang.Object
  extended by view.ShapeFactory

public class ShapeFactory
extends Object

A class that allows creation of Shapes from a single string. The string must be a double-tokenizable list, specified in StringTool.doubleTokenize(java.lang.String). If creating a new shape, the first entry in the string must be a float pair, which is then used for a move-to command, otherwise a move to 0,0 is prepended. Note that all float pairs are interpreted as line-to commands. The instance returned by the createShape(java.lang.String) method is a general path.


Nested Class Summary
static class ShapeFactory.Display
          Display the command line shape in a single window.
static class ShapeFactory.Drawings
          The possible drawing types understood.
static class ShapeFactory.Ellipse
          We test the ellipse shape in various ways.
static class ShapeFactory.Paths
          For generating general path from strings.
 
Constructor Summary
ShapeFactory()
           
 
Method Summary
private static Shape addStringPath(GeneralPath into, String points)
          Adds the points stored in the string to this general path, using line to's for each point pair encountered, quad to's for quadruple entries, and curve to for hexagesimal entries.
static PointDraw createPointDraw(String pd, boolean filled)
          Creates a new PointDraw object using a string.
static Shape createShape(String poly)
          Creates a new shape instance using the default general-path constructor
static Shape createShape(String poly, int rule)
          Creates a new shape instance using the general-path constructor with the specified winding rule.
static Shape createShape(String poly, Shape add)
          Creates a new shape instance using the exisitng shape and adding the string to it.
static ShapeDraw createShapeDraw(String poly, boolean filled)
          Creates a new shape instance using the default general-path constructor
static TextDraw createTextDraw(String td, boolean fill)
          Creates a new TextDraw object using a string definition.
static String toPointDrawString(PointDraw s)
          Converts a PointDraw into a string that can be used in constructing the shape.
static String toShapeString(Shape s)
          Converts a shape into a string that can be used in constructing the shape.
static String toString(ShapeFactory.Drawings type, Object what)
          Converts the object passed over as the specialised type.
static String toTextDrawString(TextDraw s)
          Converts a TextDraw into a string that can be used in constructing the shape.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShapeFactory

public ShapeFactory()
Method Detail

createShape

public static Shape createShape(String poly)
Creates a new shape instance using the default general-path constructor


createShape

public static Shape createShape(String poly,
                                int rule)
Creates a new shape instance using the general-path constructor with the specified winding rule.


createShape

public static Shape createShape(String poly,
                                Shape add)
Creates a new shape instance using the exisitng shape and adding the string to it. No connection is done.


createShapeDraw

public static ShapeDraw createShapeDraw(String poly,
                                        boolean filled)
Creates a new shape instance using the default general-path constructor


createPointDraw

public static PointDraw createPointDraw(String pd,
                                        boolean filled)
Creates a new PointDraw object using a string. The string starts with a pair of doubles separated by a StringTool.COMMA. Then a StringTool.OUTERLIST separates this from a shape definition.


createTextDraw

public static TextDraw createTextDraw(String td,
                                      boolean fill)
Creates a new TextDraw object using a string definition. The string must be formatted that each defining substring is separated with a StringTool.OUTERLIST. Empty substrings are interpreted as default values (null for Font, zero for rotation and justification, 0,0 for points). Note that the remaining text may not consist of StringTool.DOLLAR if used in a normalized canvas.


addStringPath

private static Shape addStringPath(GeneralPath into,
                                   String points)
Adds the points stored in the string to this general path, using line to's for each point pair encountered, quad to's for quadruple entries, and curve to for hexagesimal entries. If at any time a list is encountered that has not two, four, or six elements the path is closed and returned. If the first entry has two elements and the general path has no point, they are interpreted as a move-to. If the first entry is not two-elements and the path has not previous point, a move to 0,0 is inserted.

Parameters:
into - The general path into which the points should be added.
points - A double-tokenizable list of coordinate-pairs

toShapeString

public static String toShapeString(Shape s)
Converts a shape into a string that can be used in constructing the shape. If the shape is an Ellipse2D, we return a string like #ELLIPSE plus the two radii. In any other case, a path iterator is used to link the individual segments together.


toPointDrawString

public static String toPointDrawString(PointDraw s)
Converts a PointDraw into a string that can be used in constructing the shape.


toTextDrawString

public static String toTextDrawString(TextDraw s)
Converts a TextDraw into a string that can be used in constructing the shape.


toString

public static String toString(ShapeFactory.Drawings type,
                              Object what)
Converts the object passed over as the specialised type.