net.nexttext
Class TextObjectBuilder

java.lang.Object
  extended by net.nexttext.TextObjectBuilder

public class TextObjectBuilder
extends java.lang.Object

Factory class used for creating TextObjects and adding them to NextText.

A TextObjectBuilder provides methods which take Strings and build hierarchies of TextObjects from them. It can be configured in the following ways:

Future facilities which would be useful if included:


Field Summary
static int INDENT_HANGING
           
static int INDENT_NORMAL
           
 
Constructor Summary
TextObjectBuilder(Book book)
          Instantiates the TextObjectBuilder.
TextObjectBuilder(Book book, TextPage page)
          Instantiates the TextObjectBuilder.
 
Method Summary
 void addGlyphBehaviour(AbstractBehaviour b)
          Created glyphs will get this behaviour.
 void addGlyphProperty(java.lang.String name, Property p)
          Created glyphs will get this property.
 void addGroupBehaviour(AbstractBehaviour b)
          Created groups will get this behaviour.
 void addGroupProperty(java.lang.String name, Property p)
          Created groups will get this property.
 void addWordBehaviour(AbstractBehaviour b)
          Created words will get this behaviour.
 TextObjectGroup build(java.lang.String text)
          Deprecated.  
 TextObjectGroup build(java.lang.String text, int x, int y)
          Deprecated.  
 TextObjectGroup build(java.lang.String text, processing.core.PVector pos)
          Deprecated.  
 TextObjectGroup buildSentence(java.lang.String text)
          Build a tree of TextObjects from the given string.
 TextObjectGroup buildSentence(java.lang.String text, int x, int y)
          Build a tree of TextObjects from the given sentence, at the specified location.
 TextObjectGroup buildSentence(java.lang.String text, int x, int y, int lineLength)
          Builds a tree of TextObjects from the given sentence, at the specified location.
 TextObjectGroup buildSentence(java.lang.String text, processing.core.PVector pos, int lineLength)
          Build a tree of TextObjects from the given string.
 processing.core.PFont getFont()
           
 java.util.Set<AbstractBehaviour> getGlyphBehaviours()
          Behaviours to be added to each glyph.
 java.util.Set<AbstractBehaviour> getGroupBehaviours()
          Behaviours to be added to each group.
 int getIndent()
          Get paragraph indentation.
 int getIndentStyle()
          Get the paragraph indentation style.
 float getLineHeight()
          Deprecated.  
 int getLineSpacing()
          Get the line spacing of the text.
 TextObjectGroup getParent()
          null if there's none.
 processing.core.PVector getPosition()
           
 int getSpaceOffset()
          Get the space offset.
 int getTracking()
          Get the tracking of the text.
 float getTrackingOffset()
          Deprecated.  
 java.util.Set<AbstractBehaviour> getWordBehaviours()
          Behaviours to be added to each glyph.
 void removeAllGlyphBehaviours()
          Created glyphs will no longer get any behaviours.
 void removeAllGlyphProperties()
          Created glyphs will no longer get any properties.
 void removeAllGroupBehaviours()
          Created groups will no longer get any behaviours.
 void removeAllGroupProperties()
          Created groups will no longer get any properties.
 void removeAllWordBehaviours()
          Created glyphs will no longer get any behaviours.
 void removeGlyphBehaviour(AbstractBehaviour b)
          Created glyphs will no longer get this behaviour.
 void removeGlyphProperty(java.lang.String name)
          Created glyphs will no longer get this property.
 void removeGroupBehaviour(AbstractBehaviour b)
          Created groups will no longer get this behaviour.
 void removeGroupProperty(java.lang.String name)
          Created groups will no longer get this property.
 void removeWordBehaviour(AbstractBehaviour b)
          Created words will no longer get this behaviour.
 void setAddToSpatialList(boolean addToSpatialList)
          If created objects should be added to the spatial list.
 void setFont(processing.core.PFont pf, float size)
           
 void setFont(processing.core.PFont pf, java.awt.Font f, float size)
           
 void setIndent(int indent)
          Set the paragraph indentation using normal style.
 void setIndent(int indent, int style)
          Set the paragraph indentation.
 void setLineHeight(float d)
          Deprecated.  
 void setLineSpacing(int spacing)
          Set the line spacing of the text.
 void setParent(TextObjectGroup parent)
          May be null to unset.
 void setPosition(processing.core.PVector pos)
           
 void setSpaceOffset(int space)
          Set the space offset.
 void setTextAlign(int align)
          Set the horizontal alignment type of the group around the position.
 void setTextAlignY(int alignY)
          Set the vertical alignment type of the group around the position.
 void setTracking(int d)
          Set the tracking of the text.
 void setTrackingOffset(float d)
          Deprecated.  
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INDENT_NORMAL

public static final int INDENT_NORMAL
See Also:
Constant Field Values

INDENT_HANGING

public static final int INDENT_HANGING
See Also:
Constant Field Values
Constructor Detail

TextObjectBuilder

public TextObjectBuilder(Book book)
Instantiates the TextObjectBuilder.

Parameters:
book - the Book to build TextObjects into

TextObjectBuilder

public TextObjectBuilder(Book book,
                         TextPage page)
Instantiates the TextObjectBuilder.

Parameters:
book - the Book
page - the Page to build TextObjects into
Method Detail

setFont

public void setFont(processing.core.PFont pf,
                    float size)

setFont

public void setFont(processing.core.PFont pf,
                    java.awt.Font f,
                    float size)

getFont

public processing.core.PFont getFont()

setPosition

public void setPosition(processing.core.PVector pos)

getPosition

public processing.core.PVector getPosition()

setAddToSpatialList

public void setAddToSpatialList(boolean addToSpatialList)
If created objects should be added to the spatial list.


setTextAlign

public void setTextAlign(int align)
Set the horizontal alignment type of the group around the position.


setTextAlignY

public void setTextAlignY(int alignY)
Set the vertical alignment type of the group around the position.


setParent

public void setParent(TextObjectGroup parent)
May be null to unset.


getParent

public TextObjectGroup getParent()
null if there's none.


addGlyphBehaviour

public void addGlyphBehaviour(AbstractBehaviour b)
Created glyphs will get this behaviour.


removeGlyphBehaviour

public void removeGlyphBehaviour(AbstractBehaviour b)
Created glyphs will no longer get this behaviour.


removeAllGlyphBehaviours

public void removeAllGlyphBehaviours()
Created glyphs will no longer get any behaviours.


getGlyphBehaviours

public java.util.Set<AbstractBehaviour> getGlyphBehaviours()
Behaviours to be added to each glyph.


addWordBehaviour

public void addWordBehaviour(AbstractBehaviour b)
Created words will get this behaviour.


removeWordBehaviour

public void removeWordBehaviour(AbstractBehaviour b)
Created words will no longer get this behaviour.


removeAllWordBehaviours

public void removeAllWordBehaviours()
Created glyphs will no longer get any behaviours.


getWordBehaviours

public java.util.Set<AbstractBehaviour> getWordBehaviours()
Behaviours to be added to each glyph.


addGroupBehaviour

public void addGroupBehaviour(AbstractBehaviour b)
Created groups will get this behaviour.


removeGroupBehaviour

public void removeGroupBehaviour(AbstractBehaviour b)
Created groups will no longer get this behaviour.


removeAllGroupBehaviours

public void removeAllGroupBehaviours()
Created groups will no longer get any behaviours.


getGroupBehaviours

public java.util.Set<AbstractBehaviour> getGroupBehaviours()
Behaviours to be added to each group.


addGlyphProperty

public void addGlyphProperty(java.lang.String name,
                             Property p)
Created glyphs will get this property.


removeGlyphProperty

public void removeGlyphProperty(java.lang.String name)
Created glyphs will no longer get this property.


removeAllGlyphProperties

public void removeAllGlyphProperties()
Created glyphs will no longer get any properties.


addGroupProperty

public void addGroupProperty(java.lang.String name,
                             Property p)
Created groups will get this property.


removeGroupProperty

public void removeGroupProperty(java.lang.String name)
Created groups will no longer get this property.


removeAllGroupProperties

public void removeAllGroupProperties()
Created groups will no longer get any properties.


build

public TextObjectGroup build(java.lang.String text,
                             int x,
                             int y)
Deprecated. 

Builds a tree of TextObjects from the given string, at the specified location.

By default, this creates and returns a new TextObjectGroup, with a child TextObjectGlyph for each character in the string.

Parameters:
text - the String to create the TextObjectGroup from
x - the x-coordinate of the created TextObjectGroup
y - the y-coordinate of the created TextObjectGroup
Returns:
the built TextObjectGroup

build

public TextObjectGroup build(java.lang.String text)
Deprecated. 

Build a tree of TextObjects from the given string.

This is the core method of this class. Its behaviour is modified by all of the available TextObjectBuilder configuration. By default, it creates and returns a new TextObjectGroup, with a child TextObjectGlyph for each character in the string.


build

public TextObjectGroup build(java.lang.String text,
                             processing.core.PVector pos)
Deprecated. 

Build a tree of TextObjects at the specified location.


buildSentence

public TextObjectGroup buildSentence(java.lang.String text)
Build a tree of TextObjects from the given string.

The string is parsed as a sentence, where whitespace characters are treated as word delimiters. The returned TextObjectGroup has a child TextObjectGroup for each word in the string, and TextObjectGlyph grandchildren. Spaces between words are included as TextObjectGroups containing a single TextObjectGlyph child.

Parameters:
text - the String to create the TextObjectGroup from
Returns:
a group containing a sub-group for each identified tokens. Spaces are represented as groups containing one Space character.

buildSentence

public TextObjectGroup buildSentence(java.lang.String text,
                                     int x,
                                     int y)
Build a tree of TextObjects from the given sentence, at the specified location.

The string is parsed as a sentence, where whitespace characters are treated as word delimiters. The returned TextObjectGroup has a child TextObjectGroup for each word in the string, and TextObjectGlyph grandchildren. Spaces between words are included as TextObjectGroups containing a single TextObjectGlyph child.

Parameters:
text - the String to create the TextObjectGroup from
x - the x-coordinate of the created TextObjectGroup
y - the y-coordinate of the created TextObjectGroup
Returns:
a group containing a sub-group for each identified tokens. Spaces are represented as groups containing one Space character.

buildSentence

public TextObjectGroup buildSentence(java.lang.String text,
                                     int x,
                                     int y,
                                     int lineLength)
Builds a tree of TextObjects from the given sentence, at the specified location.

The returned TextObject tree will be laid out so that no more than lineLength characters appear on a single line.

Parameters:
text - the String to create the TextObjectGroup from
x - the x-coordinate of the created TextObjectGroup
y - the y-coordinate of the created TextObjectGroup
lineLength - the max number of characters per line
Returns:
the built TextObjectGroup

buildSentence

public TextObjectGroup buildSentence(java.lang.String text,
                                     processing.core.PVector pos,
                                     int lineLength)
Build a tree of TextObjects from the given string.

The returned TextObject tree will be laid out so that no more than lineLength characters appear on a single line.


setLineHeight

public void setLineHeight(float d)
Deprecated. 

Set the line height of the text.

Parameters:
d - height of a line in pixel using the current font

getLineHeight

public float getLineHeight()
Deprecated. 

Get the line height of the text.

Returns:
height of a line of text using the current font

setTrackingOffset

public void setTrackingOffset(float d)
Deprecated. 

Set the tracking of the text.

Parameters:
d - tracking in pixel

getTrackingOffset

public float getTrackingOffset()
Deprecated. 

Get the tracking of the text.

Returns:
tracking in pixel of the current font

setTracking

public void setTracking(int d)
Set the tracking of the text.

Parameters:
d - tracking in pixel

getTracking

public int getTracking()
Get the tracking of the text.

Returns:
tracking in pixel of the current font

setSpaceOffset

public void setSpaceOffset(int space)
Set the space offset.

Parameters:
space - space offset in pixel

getSpaceOffset

public int getSpaceOffset()
Get the space offset.

Returns:
space offset in pixel

setLineSpacing

public void setLineSpacing(int spacing)
Set the line spacing of the text.

Parameters:
spacing - line spacing in pixel

getLineSpacing

public int getLineSpacing()
Get the line spacing of the text.

Returns:
line spacing in pixel

setIndent

public void setIndent(int indent)
Set the paragraph indentation using normal style.

Parameters:
indent - indent in pixel

setIndent

public void setIndent(int indent,
                      int style)
Set the paragraph indentation.

Parameters:
indent - indent in pixel
style - indent style (INDENT_NORMAL or INDENT_HANGING)

getIndent

public int getIndent()
Get paragraph indentation.

Returns:
indent in pixel

getIndentStyle

public int getIndentStyle()
Get the paragraph indentation style.

Returns:
indent style