net.nexttext
Class TextObject

java.lang.Object
  extended by net.nexttext.TextObject
All Implemented Interfaces:
Locatable
Direct Known Subclasses:
TextObjectGlyph, TextObjectGroup

public abstract class TextObject
extends java.lang.Object
implements Locatable

An object in the core text data.

The core data of a NextText application is a bunch of text, with properties to define its behaviour on the screen. The text and properties are stored in a tree data structure, whose nodes are TextObjects. The terminal and non-terminal nodes of this tree are instances of two different subclasses of TextObject.

TextObject contains the common facilities of these subclasses, most importantly a list of properties. There is intentionally no removeProperty() method, so that behaviours can call properties.init() for all the properties that they need when they are attached to an object, and then they do not need to handle the case where getProperty() returns null. To change the value of a property, modify the returned Property object.

The tree structure is maintained inside the TextObject. This allows tree traversal and modification to be easily done by several methods in this class.


Method Summary
 void attachToLeft(TextObject newLeftSibling)
          Attach the given TextObject to the left of this one.
 void attachToRight(TextObject newRightSibling)
          Attach the given TextObject to the right of this one.
 void detach()
          Detach this from the TextObjectTree.
 CoordinateSystem getAbsoluteCoordinateSystem()
          Get the coordinate system which maps between this object's and global coordinates.
 Book getBook()
          Get the book whose TextObject hierarchy this object is attached to.
 java.awt.Polygon getBoundingPolygon()
          Returns the object's bounding polygon in absolute (screen) coordinates.
 java.awt.Rectangle getBounds()
          Convenience wrapper around getBoundingPolygon().getBounds().
 processing.core.PVector getCenter()
          Returns the center coordinates of the globalBoundingPolygon
 ColorProperty getColor()
          A getter for the standard "Color" property.
 java.awt.Color getColorAbsolute()
          Returns the absolute color of an Object, inheriting from the parent if the ColorProperty has been configured as such.
abstract  int getHeight()
          Get the greatest number of layers between this TextObject and the leaves of the tree.
 TextObject getLeftSibling()
          Get the left Sibling, or null if there isn't one.
abstract  java.awt.Polygon getLocalBoundingPolygon()
          Returns the object's bounding box expressed in local untransformed coordinates.
 processing.core.PVector getLocation()
          Returns the object's location in absolute coordinates.
 TextObjectGroup getParent()
          Get the parent, or null if this is the root.
 PVectorProperty getPosition()
          A getter for the standard "Position" property.
 processing.core.PVector getPositionAbsolute()
          The absolute position, rather than the usual relative position.
 Property getProperty(java.lang.String name)
          Get a single of property.
 java.util.Set<java.lang.String> getPropertyNames()
          Get the names of all properties.
 java.awt.Polygon getRelativeBoundingPolygon()
          Returns a convex polygon which encloses all of the object's geometry.
 CoordinateSystem getRelativeCoordinateSystem()
          Get the coordinate system which maps between this object's and its parent's coordinates.
 TextObject getRightSibling()
          Get the right Sibling, or null if there isn't one.
 NumberProperty getRotation()
          A getter for the standard "Rotation" property.
 StrokeProperty getStroke()
          A getter for the standard "Stroke" property.
 java.awt.BasicStroke getStrokeAbsolute()
          Returns the absolute stroke of an Object, inheriting from the parent if the StrokeProperty has been configured as such.
 ColorProperty getStrokeColor()
          A getter for the standard "StrokeColor" property.
 java.awt.Color getStrokeColorAbsolute()
          Returns the absolute stroke color of an Object, inheriting from the parent if the ColorProperty has been configured as such.
 void init(java.lang.String name, Property property)
          Initialize a single of property.
 void initProperties(java.util.Map<java.lang.String,Property> propertyMap)
          Initialize a bunch of properties.
 void invalidateLocalBoundingPolygon()
           
 boolean isFilled()
          Get the flag telling if the fill colour is activated or not.
 boolean isStroked()
          Get the flag telling if the stroke is activated or not.
abstract  java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getLeftSibling

public TextObject getLeftSibling()
Get the left Sibling, or null if there isn't one.


getRightSibling

public TextObject getRightSibling()
Get the right Sibling, or null if there isn't one.


getParent

public TextObjectGroup getParent()
Get the parent, or null if this is the root.


isStroked

public boolean isStroked()
Get the flag telling if the stroke is activated or not.


isFilled

public boolean isFilled()
Get the flag telling if the fill colour is activated or not.


attachToRight

public void attachToRight(TextObject newRightSibling)
Attach the given TextObject to the right of this one.


attachToLeft

public void attachToLeft(TextObject newLeftSibling)
Attach the given TextObject to the left of this one.


detach

public void detach()
Detach this from the TextObjectTree. It can be reattached elsewhere.


getHeight

public abstract int getHeight()
Get the greatest number of layers between this TextObject and the leaves of the tree.

Returns:
0 if this node is a leaf of the tree, 1 + the greatest depth of its children otherwise.


invalidateLocalBoundingPolygon

public void invalidateLocalBoundingPolygon()

getBoundingPolygon

public java.awt.Polygon getBoundingPolygon()
Returns the object's bounding polygon in absolute (screen) coordinates.

Do not modify the returned Polygon, because it may be cached.

XXXBUG: This method always returns a box-shaped unless we write an algorithm to find the convex hull of a set of points.

See Also:
TextObjectGlyph.getLocalBoundingPolygon(), TextObjectGroup.getLocalBoundingPolygon()

getBounds

public java.awt.Rectangle getBounds()
Convenience wrapper around getBoundingPolygon().getBounds().


getCenter

public processing.core.PVector getCenter()
Returns the center coordinates of the globalBoundingPolygon

Returns:
Vector3 the center point of the globalBoundingPolygon

getRelativeBoundingPolygon

public java.awt.Polygon getRelativeBoundingPolygon()
Returns a convex polygon which encloses all of the object's geometry.

Do not modify the returned Polygon, because it may be cached.

The returned polygon is in the same coordinate system as the object's position, which is its parent's coordinate system.


getLocalBoundingPolygon

public abstract java.awt.Polygon getLocalBoundingPolygon()
Returns the object's bounding box expressed in local untransformed coordinates.

Do not modify the returned Polygon, because it may be cached.


getRelativeCoordinateSystem

public CoordinateSystem getRelativeCoordinateSystem()
Get the coordinate system which maps between this object's and its parent's coordinates.

A TextObjectGlyph's control points can be transformed out of this coordinate system into its parent's coordinates.


getAbsoluteCoordinateSystem

public CoordinateSystem getAbsoluteCoordinateSystem()
Get the coordinate system which maps between this object's and global coordinates.

A TextObjectGlyph's control points can be transformed out of this coordinate system into the global (or screen) coordinates.


initProperties

public void initProperties(java.util.Map<java.lang.String,Property> propertyMap)
Initialize a bunch of properties.


init

public void init(java.lang.String name,
                 Property property)
Initialize a single of property.


getProperty

public Property getProperty(java.lang.String name)
Get a single of property.


getPropertyNames

public java.util.Set<java.lang.String> getPropertyNames()
Get the names of all properties.


getPosition

public PVectorProperty getPosition()
A getter for the standard "Position" property.


getColor

public ColorProperty getColor()
A getter for the standard "Color" property.


getStrokeColor

public ColorProperty getStrokeColor()
A getter for the standard "StrokeColor" property.


getStroke

public StrokeProperty getStroke()
A getter for the standard "Stroke" property.


getRotation

public NumberProperty getRotation()
A getter for the standard "Rotation" property.


getBook

public Book getBook()
Get the book whose TextObject hierarchy this object is attached to.

Returns:
null if this TextObject is not connected to any book.

getPositionAbsolute

public processing.core.PVector getPositionAbsolute()
The absolute position, rather than the usual relative position.

The absolute position is expressed in terms of screen coordinates.


getColorAbsolute

public java.awt.Color getColorAbsolute()
Returns the absolute color of an Object, inheriting from the parent if the ColorProperty has been configured as such.


getStrokeColorAbsolute

public java.awt.Color getStrokeColorAbsolute()
Returns the absolute stroke color of an Object, inheriting from the parent if the ColorProperty has been configured as such.


getStrokeAbsolute

public java.awt.BasicStroke getStrokeAbsolute()
Returns the absolute stroke of an Object, inheriting from the parent if the StrokeProperty has been configured as such.


toString

public abstract java.lang.String toString()
Overrides:
toString in class java.lang.Object

getLocation

public processing.core.PVector getLocation()
Returns the object's location in absolute coordinates.

Specified by:
getLocation in interface Locatable
Returns:
The object's location in absolute coordinates.