com.mindfusion.diagramming
Class Shape

java.lang.Object
  extended by com.mindfusion.diagramming.Shape

public class Shape
extends java.lang.Object

A Shape object describes a shape consisting of a series of straight lines, arcs and Bezier curves. The main component of a shape definition is its outline, which describes the shape region that will be filled in color, and used for hit-testing and aligning arrows to the shape. A shape can also contain decorations - lines, arcs or Bezier curves that are drawn with the shape but do not influence the fill or hit testing.

A shape is used by applying it to a ShapeNode instance by calling the ShapeNode.setShape(com.mindfusion.diagramming.Shape) method.


Constructor Summary
Shape(ElementTemplate[] outline, ElementTemplate[] decorations, ElementTemplate[] textArea, int windingRule, java.lang.String id)
          Initializes a new Shape instance by setting its outline, decorations, text area, fill rule and shape identifier.
Shape(ElementTemplate[] elements, ElementTemplate[] decorations, ElementTemplate[] textArea, int windingRule, java.lang.String id, ShapeDecoration[] closedDecorations)
           
Shape(ElementTemplate[] outline, int windingRule, java.lang.String id)
          Initializes a new Shape instance by setting its outline, fill rule and shape identifier.
Shape(short[] outline, java.lang.String id)
          Initializes a new instance of the Shape class with the specified outline and id.
 
Method Summary
 void draw(java.awt.Graphics2D drawingContext, Brush brush, Pen pen, boolean shadow)
          Draws this shape on the specified DrawingContext surface.
static Shape fromId(java.lang.String id)
          Returns the shape that has the specified identifier.
static Shape fromXmlElement(org.w3c.dom.Element e)
          Creates a ShapeTemplate from xml shape element
static Shape[] fromXmlElements(org.w3c.dom.Element shapes)
           
 java.lang.String getDisplayName()
           
 java.lang.String getId()
          Return the shape identifier.
 java.awt.Image getImage()
          Gets an image that is displayed by default in all instances of this shape.
 java.lang.String getImageLocation()
          Get the image location.
 java.awt.geom.Rectangle2D.Float getImageRectangle()
          Gets the location of the shape image relatively to the bounding rectangles of boxes of this shape.
 boolean getIsArrowhead()
          Gets a value indicating if this shape is used as arrowhead.
 ElementTemplate[] getOutline()
           
static ShapeList getShapes()
          Returns a list of all shapes definitions.
 ElementTemplate[] getTextArea()
           
 void setDisplayName(java.lang.String displayName)
           
 void setId(java.lang.String value)
           
 void setImage(java.awt.Image image)
          Sets an image that should be displayed by default in all instances of this shape.
 void setImageLocation(java.lang.String url)
          Accepted are absolute URLs, and relative paths with both back and forward slashes .NET ShapeEditor may produce absolute filesystem image paths when the images are on different drive than the shape library xml, and they will not work on java.
 void setImageRectangle(java.awt.geom.Rectangle2D.Float imageRectangle)
          Sets the location of the shape image relatively to the bounding rectangles of boxes of this shape.
 org.w3c.dom.Element toDOM(org.w3c.dom.Document owner)
           
static org.w3c.dom.Element[] toDOM(Shape[] shapes, org.w3c.dom.Document owner)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Shape

public Shape(ElementTemplate[] outline,
             int windingRule,
             java.lang.String id)
Initializes a new Shape instance by setting its outline, fill rule and shape identifier.

Parameters:
outline - An array of ElementTemplate objects representing the shape outline, which specifies what region of a box is filled, used for hit-testing and for aligning arrow end point to the box.
windingRule - GeneralPath.WIND_EVEN_ODD or GeneralPath.WIND_NON_ZERO.
id - An unique String identifier of this shape.

Shape

public Shape(ElementTemplate[] outline,
             ElementTemplate[] decorations,
             ElementTemplate[] textArea,
             int windingRule,
             java.lang.String id)
Initializes a new Shape instance by setting its outline, decorations, text area, fill rule and shape identifier.

Parameters:
outline - An array of ElementTemplate objects representing the shape outline, which specifies what region of a box is filled, used for hit-testing and for aligning arrow end point to the box.
decorations - An array of ElementTemplate objects representing the shape decoration lines.
textArea - An array of ElementTemplate objects representing the region of the shape where box' text is laid out.
windingRule - GeneralPath.WIND_EVEN_ODD or GeneralPath.WIND_NON_ZERO.
id - An unique String identifier of this shape.

Shape

public Shape(ElementTemplate[] elements,
             ElementTemplate[] decorations,
             ElementTemplate[] textArea,
             int windingRule,
             java.lang.String id,
             ShapeDecoration[] closedDecorations)

Shape

public Shape(short[] outline,
             java.lang.String id)
Initializes a new instance of the Shape class with the specified outline and id. The specified array should contain even number of values. Each odd value represents the x-coordinate and each even value represents the y-coordinate of the corresponding point in the shape outline.

Parameters:
outline - An array containing even number of coordinate values, which define the points of the shape outline.
id - The string identifier of the new shape.
Method Detail

getId

public java.lang.String getId()
Return the shape identifier.

Returns:
A String object containing the shape identifier.

setId

public void setId(java.lang.String value)

getShapes

public static ShapeList getShapes()
Returns a list of all shapes definitions.

Returns:
A ShapeList that contains all shape definitions.

fromId

public static Shape fromId(java.lang.String id)
Returns the shape that has the specified identifier.

Parameters:
id - The identifier of the looked-for shape.
Returns:
The Shape identified by the specified string.

fromXmlElements

public static Shape[] fromXmlElements(org.w3c.dom.Element shapes)
                               throws javax.xml.transform.TransformerException,
                                      XmlException
Throws:
javax.xml.transform.TransformerException
XmlException

fromXmlElement

public static Shape fromXmlElement(org.w3c.dom.Element e)
                            throws javax.xml.transform.TransformerException,
                                   XmlException
Creates a ShapeTemplate from xml shape element

Throws:
javax.xml.transform.TransformerException
XmlException

getImageLocation

public java.lang.String getImageLocation()
Get the image location. Will be null if the image was set with setImage, which does not provide location, or if there is no image.


setImageLocation

public void setImageLocation(java.lang.String url)
Accepted are absolute URLs, and relative paths with both back and forward slashes .NET ShapeEditor may produce absolute filesystem image paths when the images are on different drive than the shape library xml, and they will not work on java. Workaround: copy images to the same drive

Parameters:
url -

toDOM

public static org.w3c.dom.Element[] toDOM(Shape[] shapes,
                                          org.w3c.dom.Document owner)

toDOM

public org.w3c.dom.Element toDOM(org.w3c.dom.Document owner)

getImage

public java.awt.Image getImage()
Gets an image that is displayed by default in all instances of this shape.

Returns:
An Image displayed inside boxes of this shape.

setImage

public void setImage(java.awt.Image image)
Sets an image that should be displayed by default in all instances of this shape.

Parameters:
image - An Image that should be displayed inside boxes of this shape.

getImageRectangle

public java.awt.geom.Rectangle2D.Float getImageRectangle()
Gets the location of the shape image relatively to the bounding rectangles of boxes of this shape.

Returns:
A Rectangle2D object specifying the image coordinates as percents of the box bounds.

setImageRectangle

public void setImageRectangle(java.awt.geom.Rectangle2D.Float imageRectangle)
Sets the location of the shape image relatively to the bounding rectangles of boxes of this shape.

Parameters:
imageRectangle - A Rectangle2D object specifying the image coordinates as percents of the box bounds.

setDisplayName

public void setDisplayName(java.lang.String displayName)
Parameters:
displayName - The name that should be displayed for this shape in user interface, e.g. in the ShapeListBox.

getDisplayName

public java.lang.String getDisplayName()
Returns:
The name displayed for this shape in user interface.

getIsArrowhead

public boolean getIsArrowhead()
Gets a value indicating if this shape is used as arrowhead.


getOutline

public ElementTemplate[] getOutline()

getTextArea

public ElementTemplate[] getTextArea()

draw

public void draw(java.awt.Graphics2D drawingContext,
                 Brush brush,
                 Pen pen,
                 boolean shadow)
Draws this shape on the specified DrawingContext surface.

Parameters:
drawingContext - The DrawingContext surface to draw the shape on.
brush - A Brush used to fill the shape.
pen - A Pen used to draw the shape outline.
shadow - When shadow is true the brush and pen parameters have higher priority over shape's brush and pen.