com.tensegrity.graphics.primitive2D
Class Polygon2D

java.lang.Object
  extended bycom.tensegrity.graphics.AbstractPrimitive
      extended bycom.tensegrity.graphics.primitive2D.Polygon2D
All Implemented Interfaces:
Attributable, AttributableOnSet, BaseInteractable, Interactable, Primitive

public class Polygon2D
extends AbstractPrimitive
implements Interactable

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.

Version:
$Id: Polygon2D.java,v 1.88 2006/03/21 14:26:11 MichaelKegel Exp $
Author:
MichaelKegel

Field Summary
protected  int[] coordsX
          instance variable for the x components of the polygons coordinates
protected  int[] coordsXRef
          instance variable for the x components of the polygons reference coordinates (necessary when the polygon has segments that are not linear lines)
protected  int[] coordsY
          instance variable for the y components of the polygons coordinates
protected  int[] coordsYRef
          instance variable for the y components of the polygons reference coordinates (necessary when the polygon has segments that are not linear lines)
protected  int[] segmentTypes
          instance variable for the segment types of the polygon
 
Fields inherited from class com.tensegrity.graphics.AbstractPrimitive
attributableOnSetListener, doAttributableEvents, infovalueregistry, interactionDescriptor, selected
 
Fields inherited from interface com.tensegrity.generic.attribute.AttributableOnSet
TREE_SUBSET_POSTFIX
 
Constructor Summary
Polygon2D()
          Constructor that creates an empty Polygon2D.
Polygon2D(Coordinate[] coordinates)
          Constructor that creates a Polygon2D with the coordinates given by coordinates.
Polygon2D(int[] coordsX, int[] coordsY)
          Constructor that creates a Polygon2D with the coordinates given by coordsX and coordsY.
Polygon2D(int[] coordsX, int[] coordsY, int[] coordsXRef, int[] coordsYRef, int[] segmentTypes)
          Constructor that creates a Polygon2D with the coordinates given by coordsX and coordsY with the reference coordinates given by coordsXRef and coordsYRef and the segment types given by segmentTypes.
Polygon2D(Polygon2D polygon)
          Copy constructor for Polygon2D.
 
Method Summary
 void addCoordinate(Coordinate coordinate)
          Adds the Coordinate given by coordinate to the coordinates of the Polygon2D.
 void applyState(PrimitiveState state)
           
 BoundingBox calculateBoundingBox(InteractionInfo interactionInfo)
           
 Primitive deepCopy()
          An implementation of this method is responsible for returning a deep- copy of the Primitive instance
 Attribute getAttribute(java.lang.String name)
          Returns the attribute with the given name or null if there is no Attribute with the given name.
 AttributeSet getAttributes()
          Returns an AttributeSet consisting of all attributes of this AttributableOnSet.
 AttributeSet getAttributesTree()
          Returns an AttributeSet containing all Attributes of this AttributableOnSet in a treelike structure.
 Boundary getBoundingBox()
          Returns the bounding box of the BaseInteractable.
 Coordinate getCoordinateAt(int index)
          Returns the coordinate at the index specified by index.
 int getCoordinateCount()
          Returns the current count of coordinates the Polygon2D consists of.
 Coordinate[] getCoordinates()
          Returns an array of Coordinates the Polygon2D consists of.
 Illustrator getIllustrator(Transform2D xform_context)
          Returns the Primitives illustrator object.
 Coordinate[] getReferenceCoordinates()
          Returns an array of Coordinates that represents the reference coordinates the Polygon2D currently provides.
 int[] getSegmentTypes()
          Returns an int-array that represent the segment types the Polygon2D currently provides.
 PrimitiveState getState()
           
 void insertCoordinate(int index, Coordinate coordinate)
          Inserts the Coordinate given by coordinate at the index specified by index.
 void insertReferenceCoordinates(int indexSegment, Coordinate[] coordinatesRef)
          Inserts
protected  InteractionDescriptor internalCreateInteractionDescriptor()
          This method should return an InteractionDescriptor that defines the interaction capabilities of a certain Primitive.
 boolean isResizable()
          Returns a boolean that indicates whether the Interactable is resizable or not.
 void removeCoordinate(int index)
          Removes the coordinate at the index specified by index from the Polygon2D.
 void removeCoordinates(int index1, int index2)
          Removes the coordinates between the index specified by index1 and the index specified by index2 from the Polygon2D.
 void setAttributes(AttributeSet attributes)
          Searches within the AttributeSet given by attributes for attributes that have the same name as the attributes of this AttributableOnSet holds.
 void setAttributesTree(AttributeSet attributes)
          Performs the same operation as the setAttributes(com.tensegrity.generic.attribute.AttributeSet) method with the difference that the AttributeSet given to this method must provide the treelike structure mentioned in the documentation of the getAttributesTree().
 void setAttributeValue(java.lang.String name, java.lang.Object value)
          Sets the value of the attribute with the name to the given value.
 void setCoordinateAt(int index, Coordinate coordinate)
          Sets the Coordinate given by coordinate at the index specified by index.
 void setCoordinates(Coordinate[] coords)
          Sets the Coordinates given by coords as the new coordinates the Polygon2D should consists of.
 void setReferenceCoordinates(Coordinate[] coords)
          Sets the Coordinates given by coords as the new reference coordinates the Polygon2D should provide.
 void setResizable(boolean resizable)
          Sets the state of resizability for the Interactable to the value given by resizable.
 void setSegmentTypes(int[] segmentTypes)
          Sets the segment types for the Polygon2D to the values given by segmentTypesNew.
 void setStroke(StrokeFormat stroke)
          Sets a StrokeFormat for the Primitive.
 java.lang.String toString()
           
 
Methods inherited from class com.tensegrity.graphics.AbstractPrimitive
addAttributableOnSetListener, addInfoValue, addOrSetInfoValue, areAttributableEventsEnabled, disableAttributableEvents, enableAttributableEvents, fireAttributableOnSetChangedEvent, fireAttributableOnSetChangedEvent, getAttributeType, getAttributeValue, getFont, getInfoValue, getInteractionDescriptor, getMoveItem, getPaint, getRenderingData, getStroke, getTransform, hasInfoValue, hits, internalDeepCopyInfoValues, internalEnableSelection, internalSelect, internalSetFont, internalSetPaint, internalSetSelected, internalSetStroke, internalSetStroke, isMovable, isSelectable, isSelected, mouseClick, mouseDown, mouseEnter, mouseExit, mouseUp, postActing, preActing, raiseAttributableEvents, removeAttributableOnSetListener, removeInfoValue, select, setAttribute, setFontFormat, setInfoValue, setMovable, setPaint, setSelectable, setSelected, setTransform, startAction, stopAction
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.tensegrity.graphics.interaction.BaseInteractable
getInteractionDescriptor, getMoveItem, hits, internalEnableSelection, internalSelect, internalSetSelected, isMovable, isSelectable, isSelected, mouseClick, mouseDown, mouseEnter, mouseExit, mouseUp, postActing, preActing, select, setMovable, setSelectable, setSelected, startAction, stopAction
 

Field Detail

coordsX

protected int[] coordsX
instance variable for the x components of the polygons coordinates


coordsY

protected int[] coordsY
instance variable for the y components of the polygons coordinates


coordsXRef

protected int[] coordsXRef
instance variable for the x components of the polygons reference coordinates (necessary when the polygon has segments that are not linear lines)


coordsYRef

protected int[] coordsYRef
instance variable for the y components of the polygons reference coordinates (necessary when the polygon has segments that are not linear lines)


segmentTypes

protected int[] segmentTypes
instance variable for the segment types of the polygon

Constructor Detail

Polygon2D

public Polygon2D()
Constructor that creates an empty Polygon2D.
Even though a Polygon without coordinates isnt any useful, it can be necessary to create such an instance without knowing its coordinates yet.


Polygon2D

public Polygon2D(int[] coordsX,
                 int[] coordsY)
Constructor that creates a Polygon2D with the coordinates given by coordsX and coordsY.

Parameters:
coordsX - the x components of the coordinates
coordsY - the y components of the coordinates

Polygon2D

public Polygon2D(Coordinate[] coordinates)
Constructor that creates a Polygon2D with the coordinates given by coordinates.

Parameters:
coordinates - array of the coordinates

Polygon2D

public Polygon2D(int[] coordsX,
                 int[] coordsY,
                 int[] coordsXRef,
                 int[] coordsYRef,
                 int[] segmentTypes)
Constructor that creates a Polygon2D with the coordinates given by coordsX and coordsY with the reference coordinates given by coordsXRef and coordsYRef and the segment types given by segmentTypes.

Parameters:
coordsX - the x components of the coordinates
coordsY - the y components of the coordinates
coordsXRef - the x components of the reference coordinates
coordsYRef - the y components of the reference coordinates
segmentTypes - the different segment types

Polygon2D

public Polygon2D(Polygon2D polygon)
Copy constructor for Polygon2D.

Parameters:
polygon - the Polygon2D to copy
Method Detail

getCoordinateCount

public int getCoordinateCount()
Returns the current count of coordinates the Polygon2D consists of.

Returns:
int the current count of coordinates

getCoordinateAt

public Coordinate getCoordinateAt(int index)
Returns the coordinate at the index specified by index.

Parameters:
index - the index to return the coordinate for
Returns:
Coordinate the coordinate at the specified index

setCoordinateAt

public void setCoordinateAt(int index,
                            Coordinate coordinate)
Sets the Coordinate given by coordinate at the index specified by index.

Parameters:
index - the index to set the coordinate at
coordinate - the new Coordinate

addCoordinate

public void addCoordinate(Coordinate coordinate)
Adds the Coordinate given by coordinate to the coordinates of the Polygon2D.

Parameters:
coordinate - the Coordinate to add

insertCoordinate

public void insertCoordinate(int index,
                             Coordinate coordinate)
Inserts the Coordinate given by coordinate at the index specified by index.

Parameters:
index - the index where to insert the new Coordinate
coordinate - the Coordinate to insert

insertReferenceCoordinates

public void insertReferenceCoordinates(int indexSegment,
                                       Coordinate[] coordinatesRef)
Inserts

Parameters:
indexSegment -
coordinatesRef -

removeCoordinate

public void removeCoordinate(int index)
Removes the coordinate at the index specified by index from the Polygon2D.

Parameters:
index - the index where to remove the coordinate

removeCoordinates

public void removeCoordinates(int index1,
                              int index2)
Removes the coordinates between the index specified by index1 and the index specified by index2 from the Polygon2D.

Parameters:
index1 - the start index of the coordinates to remove
index2 - the stop index of the coordinates to remove

getCoordinates

public Coordinate[] getCoordinates()
Returns an array of Coordinates the Polygon2D consists of.
NOTICE:Changes to the returned array do not change the Polygon2D

Returns:
Coordinate[] array of the coordinates the Polygon2D consists of

setCoordinates

public void setCoordinates(Coordinate[] coords)
Sets the Coordinates given by coords as the new coordinates the Polygon2D should consists of.

Parameters:
coords - the new Coordinates for the Polygon2D

getReferenceCoordinates

public Coordinate[] getReferenceCoordinates()
Returns an array of Coordinates that represents the reference coordinates the Polygon2D currently provides.
NOTICE:Changes to the returned array do not change the Polygon2D

Returns:
Coordinate[] array of the reference coordinates the Polygon2D currently provides

setReferenceCoordinates

public void setReferenceCoordinates(Coordinate[] coords)
Sets the Coordinates given by coords as the new reference coordinates the Polygon2D should provide.

Parameters:
coords - the new reference Coordinates for the Polygon2D

getSegmentTypes

public int[] getSegmentTypes()
Returns an int-array that represent the segment types the Polygon2D currently provides. The different segment types that are supported by the Polygon2D are defined by the constants UtilitiesLine.LINEAR_SEGMENT, UtilitiesLine.CUBIC_BEZIER_SEGMENT or UtilitiesLine.CUBIC_CATMULL_ROM_SEGMENT.

Returns:
int[] the current segment types of the Polygon2D

setSegmentTypes

public void setSegmentTypes(int[] segmentTypes)
Sets the segment types for the Polygon2D to the values given by segmentTypesNew. The supported segment types are defined by

Find more information in the class documentation


setStroke

public void setStroke(StrokeFormat stroke)
Description copied from interface: Primitive
Sets a StrokeFormat for the Primitive.

Specified by:
setStroke in interface Primitive
Parameters:
stroke - the StrokeFormat to use

getBoundingBox

public Boundary getBoundingBox()
Description copied from interface: BaseInteractable
Returns the bounding box of the BaseInteractable.

Specified by:
getBoundingBox in interface BaseInteractable
Returns:
Boundary the bounding box of the BaseInteractable

getState

public PrimitiveState getState()
Specified by:
getState in interface Primitive

applyState

public void applyState(PrimitiveState state)
                throws PrimitiveStateNotApplicableException
Specified by:
applyState in interface Primitive
Throws:
PrimitiveStateNotApplicableException

getIllustrator

public Illustrator getIllustrator(Transform2D xform_context)
Description copied from interface: Primitive
Returns the Primitives illustrator object. To get more informations about the illustrator object see the class above or the documentation of the Illustrator class.

Specified by:
getIllustrator in interface Primitive
Parameters:
xform_context - the transformation of the context the Primitive lies within.
Returns:
Illustrator the illustrator for outputting the Primitive.

deepCopy

public Primitive deepCopy()
Description copied from interface: Primitive
An implementation of this method is responsible for returning a deep- copy of the Primitive instance

Specified by:
deepCopy in interface Primitive
Returns:
a deep copy of the Primitive.

isResizable

public boolean isResizable()
Description copied from interface: Interactable
Returns a boolean that indicates whether the Interactable is resizable or not.

Specified by:
isResizable in interface Interactable
Returns:
boolean that indicates the state of resizability of the Interactable

setResizable

public void setResizable(boolean resizable)
Description copied from interface: Interactable
Sets the state of resizability for the Interactable to the value given by resizable.

Specified by:
setResizable in interface Interactable
Parameters:
resizable - the new state of resizability for the Interactable

calculateBoundingBox

public BoundingBox calculateBoundingBox(InteractionInfo interactionInfo)
Specified by:
calculateBoundingBox in interface Interactable

setAttributeValue

public void setAttributeValue(java.lang.String name,
                              java.lang.Object value)
                       throws IllegalValueException,
                              ConstraintViolationException
Description copied from interface: Attributable
Sets the value of the attribute with the name to the given value.
Notice: If the specific implementor of the Attributable interface doesn't support an Attribute with the name given by name, the attribute given through name and value is not handled nor created by Attributable.

Specified by:
setAttributeValue in interface Attributable
Overrides:
setAttributeValue in class AbstractPrimitive
Throws:
IllegalValueException
ConstraintViolationException

getAttribute

public Attribute getAttribute(java.lang.String name)
Description copied from interface: Attributable
Returns the attribute with the given name or null if there is no Attribute with the given name.

Specified by:
getAttribute in interface Attributable
Overrides:
getAttribute in class AbstractPrimitive

getAttributes

public AttributeSet getAttributes()
Description copied from interface: AttributableOnSet
Returns an AttributeSet consisting of all attributes of this AttributableOnSet.

Specified by:
getAttributes in interface AttributableOnSet
Returns:
AttributeSet an AttributeSet with all attributes.

setAttributes

public void setAttributes(AttributeSet attributes)
Description copied from interface: AttributableOnSet
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.

Specified by:
setAttributes in interface AttributableOnSet
Parameters:
attributes - the AttributeSet consisting of the attributes whose values to set.

getAttributesTree

public AttributeSet getAttributesTree()
Description copied from interface: AttributableOnSet
Returns an AttributeSet containing all Attributes of this AttributableOnSet in a treelike structure.
Treelike means that each attribute can have a subset that contains subsequent Attributes for an Attribute of this AttributableOnSet.
Since an Attribute can only have one value (in this case an object or the Attributes for an object) the subsequent attributes are plugged into the returned AttributeSet as a new Attribute with the same name and the AttributableOnSet.TREE_SUBSET_POSTFIX.

Specified by:
getAttributesTree in interface AttributableOnSet
Returns:
AttributeSet an AttributeSet with the attributes in a treelike structure

setAttributesTree

public void setAttributesTree(AttributeSet attributes)
Description copied from interface: AttributableOnSet
Performs the same operation as the AttributableOnSet.setAttributes(com.tensegrity.generic.attribute.AttributeSet) method with the difference that the AttributeSet given to this method must provide the treelike structure mentioned in the documentation of the AttributableOnSet.getAttributesTree().

Specified by:
setAttributesTree in interface AttributableOnSet
Parameters:
attributes - the AttributeSet containing the attributes whose values to set.

internalCreateInteractionDescriptor

protected InteractionDescriptor internalCreateInteractionDescriptor()
Description copied from class: AbstractPrimitive
This method should return an InteractionDescriptor that defines the interaction capabilities of a certain Primitive. Since the InteractionDescriptor varies for different kinds of primitives this method is declared as abstract and must be implemented for each Primitive that is based on the AbstractPrimitive class.
NOTICE: The return value must not be null.

Specified by:
internalCreateInteractionDescriptor in class AbstractPrimitive
Returns:
InteractionDescriptor the InteractionDescriptor for the certain Primitive instance

toString

public java.lang.String toString()


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.