com.davisor.graphics.data
Class ShapeParameters

java.lang.Object
  extended bycom.davisor.graphics.data.ShapeParameters
All Implemented Interfaces:
ParameterConstants, java.io.Serializable

public class ShapeParameters
extends java.lang.Object
implements ParameterConstants, java.io.Serializable

ShapeParameters define shapes with a generic set of shape parameters. Each parameter defines one aspect of a desired shape. Together, the parameters form a shape specification from which a concrete shape object can be created.

Available shape parameters are:

The parameter values can be set explicitly, or they can be parsed from a parameter string as defined by the parse(String,ParsePosition) method. Any of the shape parameters can also be left unset, in which case the parameter default value, if any, will be used.

Since:
JDK1.1
See Also:
ShapeParameters(String,ParsePosition), parse(String,ParsePosition), toData(com.davisor.graphics.data.ShapeType), toShape(), BetterPath, PaintParameters, ShapeType, ShapeType.createShape(java.lang.String), Serialized Form

Field Summary
static int ANGLE
          Code for a 'angle' keyword.
static int ANGLEFROM
          Code for a 'angleFrom' keyword.
static int ANGLEKEY
          Code for a 'angleKey' keyword.
static int ANGLEMAX
          Code for a 'angleMax' keyword.
static int ANGLEMIN
          Code for a 'angleMin' keyword.
static int ANGLETO
          Code for a 'angleTo' keyword.
static int NAME
          Code for an 'name' keyword.
static int PATH
          Code for a 'path' keyword.
static int SCALE
          Code for a 'scale' keyword.
static int SCALEFROM
          Code for a 'scaleFrom' keyword.
static int SCALEKEY
          Code for a 'scaleKey' keyword.
static int SCALEMAX
          Code for a 'scaleMax' keyword.
static int SCALEMIN
          Code for a 'scaleMin' keyword.
static int SCALETO
          Code for a 'scaleTo' keyword.
static int SVG
          Code for a 'svg' keyword.
 
Fields inherited from interface com.davisor.graphics.ParameterConstants
ANNOTATIONADDRESS, ANNOTATIONCOORDS, ANNOTATIONDESCRIPTION, ANNOTATIONDESCRIPTION_MOZILLA, ANNOTATIONONMOUSEOUT, ANNOTATIONONMOUSEOVER, ANNOTATIONSEPARATOR, ANNOTATIONSHAPE, ANNOTATIONTARGET, CENTER, DOWN, FIELDSEPARATOR, LEFT, RIGHT, TAILSEPARATOR, TERMINAL, UNSET, UP, VALUESEPARATOR
 
Constructor Summary
ShapeParameters()
          Default constructor.
ShapeParameters(java.awt.Shape shape)
          Creates a new shape matching given example shape.
ShapeParameters(java.lang.String name, java.lang.Float angle, java.lang.Float scale, BetterPath path)
          Creates a new set of shape parameters.
ShapeParameters(java.lang.String parameters, java.text.ParsePosition status)
          Creates a new set of shape parameters from a shape parameter string.
ShapeParameters(java.lang.String shapePath, java.lang.String shapeName)
          Creates a new shape according to the given SVG path specifications.
 
Method Summary
 java.lang.Float getAngle()
          Gets the shape rotation angle (may be null).
 java.lang.String getName()
          Gets the shape name (may be null).
 BetterPath getPath()
          Gets the shape coordinate path (may be null).
 java.lang.Float getScale()
          Gets the shapes scale multiplier (may be null).
 void parse(java.lang.String parameters, java.text.ParsePosition status)
          Interpretes shape parameters from a shape parameter specification string.
 void parsePath(java.lang.String shapePath, java.lang.String shapeName)
          Interpretes a shape path.
protected  java.lang.Object readResolve()
          Resolves this object back to a shape during deserialization.
 void setParameters(java.awt.Shape shape)
          Sets shape parameters to match given shape.
 java.awt.Shape toData(ShapeType type)
          Creates a shape value of the given type and the current shape parameters.
static java.awt.Shape toData(ShapeType type, java.lang.Object value)
          Creates a shape value of the given type from the given data object.
 java.awt.Shape toShape()
          Creates a new shape based on the current shape parameters.
 java.lang.String toString()
          Gets the shape parameter string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ANGLE

public static final int ANGLE
Code for a 'angle' keyword.

See Also:
Constant Field Values

ANGLEFROM

public static final int ANGLEFROM
Code for a 'angleFrom' keyword.

See Also:
Constant Field Values

ANGLEKEY

public static final int ANGLEKEY
Code for a 'angleKey' keyword.

See Also:
Constant Field Values

ANGLEMAX

public static final int ANGLEMAX
Code for a 'angleMax' keyword.

See Also:
Constant Field Values

ANGLEMIN

public static final int ANGLEMIN
Code for a 'angleMin' keyword.

See Also:
Constant Field Values

ANGLETO

public static final int ANGLETO
Code for a 'angleTo' keyword.

See Also:
Constant Field Values

NAME

public static final int NAME
Code for an 'name' keyword.

See Also:
Constant Field Values

PATH

public static final int PATH
Code for a 'path' keyword.

See Also:
Constant Field Values

SCALE

public static final int SCALE
Code for a 'scale' keyword.

See Also:
Constant Field Values

SCALEFROM

public static final int SCALEFROM
Code for a 'scaleFrom' keyword.

See Also:
Constant Field Values

SCALEKEY

public static final int SCALEKEY
Code for a 'scaleKey' keyword.

See Also:
Constant Field Values

SCALEMAX

public static final int SCALEMAX
Code for a 'scaleMax' keyword.

See Also:
Constant Field Values

SCALEMIN

public static final int SCALEMIN
Code for a 'scaleMin' keyword.

See Also:
Constant Field Values

SCALETO

public static final int SCALETO
Code for a 'scaleTo' keyword.

See Also:
Constant Field Values

SVG

public static final int SVG
Code for a 'svg' keyword.

See Also:
Constant Field Values
Constructor Detail

ShapeParameters

public ShapeParameters()
Default constructor. Leaves all shape parameters to their default values.

See Also:
parse(java.lang.String, java.text.ParsePosition), toData(ShapeType), toData(ShapeType,Object)

ShapeParameters

public ShapeParameters(java.awt.Shape shape)
Creates a new shape matching given example shape. Shape parameters are extracted from the given shape as described by the setParameters(java.awt.Shape) method.

Parameters:
shape - shape to extract shape parameters from
See Also:
setParameters(java.awt.Shape)

ShapeParameters

public ShapeParameters(java.lang.String shapePath,
                       java.lang.String shapeName)
                throws InvalidDataException
Creates a new shape according to the given SVG path specifications.

Parameters:
shapePath - SVG shape path
shapeName - name of the shape
Throws:
InvalidDataException - if shapePath string can't be parsed
See Also:
parsePath(java.lang.String, java.lang.String)

ShapeParameters

public ShapeParameters(java.lang.String parameters,
                       java.text.ParsePosition status)
                throws InvalidDataException
Creates a new set of shape parameters from a shape parameter string. Shape parameter string is expected to be a white-space ( ) terminated string of dash (-) separated shape keywords and values. For keyword and value parsing details, please see the parse(java.lang.String, java.text.ParsePosition) method documentation.

Parameters:
parameters - shape parameters (may be null)
status - parse status (may be null)
Throws:
InvalidDataException - if parameter string can't be parsed
See Also:
parse(java.lang.String, java.text.ParsePosition), toData(ShapeType), toData(ShapeType,Object)

ShapeParameters

public ShapeParameters(java.lang.String name,
                       java.lang.Float angle,
                       java.lang.Float scale,
                       BetterPath path)
Creates a new set of shape parameters.

Parameters:
name - shape face name (may be null)
angle - shape rotation angle (may be null)
scale - shape scale multiplier (may be null)
path - shape coordinate path (may be null)
See Also:
parse(java.lang.String, java.text.ParsePosition), toData(ShapeType), toData(ShapeType,Object)
Method Detail

toString

public java.lang.String toString()
Gets the shape parameter string. The string will be in a form that later can be used to construct similar shapes with this class.


getAngle

public java.lang.Float getAngle()
Gets the shape rotation angle (may be null).


getName

public java.lang.String getName()
Gets the shape name (may be null).


getPath

public BetterPath getPath()
Gets the shape coordinate path (may be null).


getScale

public java.lang.Float getScale()
Gets the shapes scale multiplier (may be null).


parse

public void parse(java.lang.String parameters,
                  java.text.ParsePosition status)
           throws InvalidDataException
Interpretes shape parameters from a shape parameter specification string. The parameter string is expected to be a by dash (-) separated and by white space ( ) terminated string of the following shape parameter fields, specified in any order:

A size factor defines a shape scaling multiplier. Values above one make the shape bigger, values below one make it smaller. The scale is selected with a non-negative floating point value. In case of ambiguity, a scale keyword may be used to emphaseis that the next field is a scale value.

Orientation defines the amount of how much the shape coordinate path is to be rotated around its' origo. The angle is selected with a angle keyword, followed by positive floating point value field which defines the desired counter-clockwise rotation angle, expressed in degrees.

Any other field will be interpreted as XML escaped shape name, which is expected to refer to one of the system stock shapes. If the shape name matches with one of the stock strokes, the attributes of that stroke are taken as default values for otherwise undefined stroke parameters. If the shape name conflict with a shape specification keywords, a name keyword may be used to emphasis that the next field is a shape name.

Examples:

Parameters:
parameters - shape specification string
status - parse status
Throws:
InvalidDataException - if the string cannot be parsed as a shape
See Also:
toShape(), XMLUnicodeDecoder.decode(String)

parsePath

public void parsePath(java.lang.String shapePath,
                      java.lang.String shapeName)
               throws InvalidDataException
Interpretes a shape path. Shape path defines the shape form as understood by the BetterPath class. The path is defined with an SVG path specification string.

Throws:
InvalidDataException

setParameters

public void setParameters(java.awt.Shape shape)
Sets shape parameters to match given shape. The new parameters are merged incrementally with old ones, so that new values replace but missing values do not erase corresponding old values. The following shape types are supported.

Parameters:
shape - shape to extract shape parameters from (may be null)
See Also:
BetterPath, ShapeData, ShapeType

toData

public java.awt.Shape toData(ShapeType type)
Creates a shape value of the given type and the current shape parameters. Unspecified shape parameters will default to the class' specified default values. Missing or invalid path and/or name information will result a null shape.

If a shape type has been given, the shape, if any, will be wrapped inside a ShapeData object. Otherwise the shape is returned as received from toShape().

Parameters:
type - shape type (may be null)
Returns:
a shape that corresponds to current parameters (may be null)
See Also:
toShape()

toData

public static java.awt.Shape toData(ShapeType type,
                                    java.lang.Object value)
                             throws InvalidDataException
Creates a shape value of the given type from the given data object. The following value classes are directly supported, others are first converted to strings, and then interpreted as shapes.

If a shape type has been given, the shape, if any, will be wrapped inside a ShapeData object.

Throws:
InvalidDataException
See Also:
toData(ShapeType), ShapeData

toShape

public java.awt.Shape toShape()
Creates a new shape based on the current shape parameters. Unspecified shape parameters will default to the class' specified default values.

Returns:
a shape that corresponds to current parameters (may be null)
See Also:
toData(ShapeType), BetterPath

readResolve

protected java.lang.Object readResolve()
                                throws java.io.ObjectStreamException
Resolves this object back to a shape during deserialization.

Throws:
java.io.ObjectStreamException
See Also:
toData(ShapeType), ShapeData.writeReplace()


Copyright © 2001-2004 Davisor Oy. All Rights Reserved.