A Primitive in the Tensegrity Graph Framework is an atomic graphical shape and forms the building
block for a Composite container. Lines, rectangles, ellipses and polygons are all
distinct Primitive implementations. The concrete Primitive classes are:
Ellipse2D
Label2D
Line2D
Polygon2D
Polyline2D
Rect2D
Every Primitive handles it's own set of attributes by
extending the AttributableOnSet interface. Moreover, you can select, move and resize
Primitive objects via the next extended interface BaseInteractable. Every
Primitive also provides it's own Illustrator which is used by the Renderer
[3]
to draw (render) the Primitive shape. Later, we will have
a better look at the Primitive implementation classes. But first, let's have a
closer examination of the interface itself.
This interface defines an atomic graphical shape.
A Primitive can be implemented as a line, rectangle, polygon,
ellipse or text. While the name of this interface might cause some initial
confusion, please remember that within the visual graph domain, a basic,
atomic drawing unit for a complex visual Node and Edge
is simply called a Primitive.
A Primitive must support a StrokeFormat and a PaintFormat
for regions. Additionally, a Primitive representing text will also support
a FontFormat. A StrokeFormat may be provided by default if the
application programmer does not specify one.
The following class diagram illustrates the general dependencies between
the classes and interfaces in package
primitive:
To get a better understanding of the formatting classes and options available, please read section Formats.
Please note that the MarkerFormat, which is used to describe arrows, is only
supported by line-oriented classes, such as Line2D and Polyline2D.
The most important methods of the Primitive interface are:
Boundary getBoundingBox()
Returns a Boundary that describes the bounding box for a
graphical object implementing this interface.
Illustrator getIllustrator(Transform2D)
Returns the Primitives illustrator object. To get more
informations about the illustrator object see the class above or the
documentation of the Illustrator class.
Transform2D getTransform()
Returns a Transform2D currently used to transform
the coordinates of the graphical Primitive.
The AbstractPrimitive class contains the shared, reusable
code needed by all of our Primitive implementations. By
deriving from this abstract base class, concrete Primitive
classes are much easier to write and maintain.
It is not possible for the AbstractPrimitive class to
implement all methods defined in the Primitive interface
for the obvious reason that some methods require specialized behavior.
Every concrete Primitive class must provide implementations for the
methods defined in interface AttributableOnSet:
AttributeSet getAttributes()
Returns an AttributeSet consisting of all attributes of this
AttributableOnSet.
void setAttributes(AttributeSet)
Searches within the AttributeSet given by
attributes for attributes that have the same name as the
attributes of this AttributableOnSet holds. The value of
every attribute that has the same name is used as the new value for the
corresponding attribute of this AttributableOnSet.
An Attribute within the given AttributeSet that
is not an attribute of the object that implements the
AttributableOnSet interface is not handled by nor added
to the specific implementor of the AttributableOnSet
interface.
For example, a Rect2D supports the following Primitive attributes:
PrimitiveAttributes.ATTRIBUTENAME_BORDER
PrimitiveAttributes.ATTRIBUTENAME_PAINT
PrimitiveAttributes.ATTRIBUTENAME_ROUND_EDGES
PrimitiveAttributes.ATTRIBUTENAME_ARC_WIDTH
PrimitiveAttributes.ATTRIBUTENAME_ARC_HEIGHT
As a general rule of thumb, Primitive classes provide attributes accessible
via getter and setter methods.
The following sections provide an overview of all currently implemented Primitive
classes located in package com.tensegrity.graphics.primitive2D.

An object of class Rect2D represents a 2-dimensional
rectangular shape. The main properties are its location and size.
The following methods deal with the important properties of a
Rect2D instance:
void set(int, int, int, int)
Sets the bounds of this Rect2D to the given left, top and
right, bottom coordinates.
void setArcHeight(int)
Sets the height of the arc of the rounded edges. Only visible, if rounded edges are enabled.
void setArcWidth(int)
Sets the width of the arc of the rounded edges. Only visible, if rounded edges are enabled.
void setEdgesRounded(boolean)
If the parameter is true, this rectangle will have rounded
edges.
void setHeight(int)
Sets the height of this Rect2D to the given height.
void setWidth(int)
Sets the width of this Rect2D to the given width.

An object of class Ellipse2D represents a 2-dimensional
elliptical shape specified by a rectangular boundary. If the boundary
is a square, the corresponding ellipse is a circle such that its
diameter equals the length of one of the squares sides.
The following methods deal with the important properties of an
Ellipse2D instance:
void setRadii(int, int)
Sets the radii in x and y direction of the ellipse to the values given
by radiusX and radiusY.
int getRadiusX()
Returns the radius in x direction of the ellipse.
int getRadiusY()
Returns the radius in y direction of the ellipse.

An object of class Label2D represents a 2-dimensional
multi-lined text area that may be edited in-place.
The location and size of a label can be modified with the same
methods listed for class Rect2D, hence they are not included
in this Label2D method list:
void enableAutomaticShortening(boolean)
If set to true lines of the label text that do not fit into
the label boundaries are not just clipped but get shortened and
“...” appended at the end.
void enableAutomaticWordWrap(boolean)
Sets the line-wrapping policy of the label. If set to true
the text will be wrapped if it is too long to fit within the allocated
width of the labels rectangular boundary.
void enableFirstWordCharacterWrap(boolean)
Set the style of wrapping used if automatic word-wrap is enabled.
If set to true, the lines will be wrapped at word boundaries
if they are too long to fit within the allocated width of the label. If
set to false, the lines will be wrapped at the text
character boundaries.
void setHorizontalAlignment(int)
Sets the horizontal alignment for the text that is associated to the
Label2D. The supported constants are defined by
ALIGN_LEFT
ALIGN_RIGHT
ALIGN_CENTER.
void setMargins(int, int, int, int)
Sets the margin of the label to the values given by
marginLeft, marginTop, marginRight and
marginBottom.
void setVerticalAlignment(int)
Sets the vertical alignment for the text that is associated to the
Label2D. The supported constants are defined by
ALIGN_TOP
ALIGN_BOTTOM
ALIGN_CENTER.
An object of class Line2D represents a 2-dimensional
line segment.
The following methods deal with the important properties of a
Line2D instance:
int getDegree()
Returns the bias of this line or, in other words, the degree of the
formula the LineModel of this line uses. For instance the
degree of a straight line is 1, for a quadric line it is 2 and the degree
for a cubic line is 3 and so forth.
void setMarkerBegin(MarkerFormat)
Sets the format of the beginning marker to the given one.
void setMarkerEnd(MarkerFormat)
Sets the format of the end marker to the given one.
void setStartEndCoordinate(Coordinate, Coordinate)
Sets the starting and the ending Coordinate of the line to
the values given by coordinateStart and
coordinateEnd
int getType()
Returns the type of this line. Potential values are LINEAR
and CUBIC as defined by this class.
void setWeight(int)
Sets the weight of this line.

An object of class Polyline2D represents a two-dimensional line
consisting of one or more line segments.
The following methods deal with the important properties of a
Polyline2D instance, which include most defined in Line2D
as well as methods which deal with polyline segments:
void addCoordinate(Coordinate)
Adds the given Coordinate to the list of coordinate pairs.
Each two coordinates defines a segment of this Polyline2D.
void setCoordinates(Coordinate[])
Sets the given Coordinates as the new vertex edges of this
Polyline2D. The old vertices of this line are deleted.
void setSegmentTypes(int[])
Sets the segment types for the Polygon2D to the values
given by segmentTypesNew. A value of null will
reset the all segments to linear, so reference coordinates are ignored.
The supported segment types are
LINEAR_SEGMENT
CUBIC_BEZIER_SEGMENT
CUBIC_CATMULL_ROM_SEGMENT
void removeCoordinate(int)
Removes the coordinate at the index specified by index from
the Polyline2D.

A Polygon2D is a closed two-dimensional region with three or
more sides. Internally, a polygon comprises of a list of (x, y) coordinate
pairs, where each pair defines a vertex of the polygon, and two successive
pairs are the endpoints of a line that is a side of the polygon. The methods
to manipulate the coordinates are the same as for class
Polyline2D.
The following methods are unique to the class Polygon2D:
void setSegmentTypes(int[])
Sets the segment types for the Polygon2D to the values
given by segmentTypesNew. The supported segment types are
defined by
LINEAR_SEGMENT
CUBIC_BEZIER_SEGMENT
CUBIC_CATMULL_ROM_SEGMENT.
© 2004, 2005 Tensegrity Software GmbH