net.nexttext
Class Book

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

public class Book
extends java.lang.Object

The container for the NextText for Processing data and window.

The PApplet which uses NextText uses this as its primary point of entry into the NextText data. Most importantly, it contains the TextObjects which hold the core text data, and the TextRenderer and window to actually draw the stuff.

The Book has its own step(), draw(), and stepAndDraw() methods which replace the Simulator loop found in regular NextText applications.

Any updates to the TextObject tree must be synchronized on the Book.


Field Summary
static KeyboardDefault keyboard
           
static MouseDefault mouse
           
static TextObjectBuilder toBuilder
           
 
Constructor Summary
Book(processing.core.PApplet p)
          Instantiates the Book with a default renderer.
Book(processing.core.PApplet p, processing.core.PGraphics g)
          Instatiates the Book with specific PGraphics object.
Book(processing.core.PApplet p, processing.core.PGraphics g, java.lang.String rendererType)
          Instantiates the Book.
Book(processing.core.PApplet p, java.lang.String rendererType)
          Instantiates the Book with a specific renderer.
 
Method Summary
 void addBehaviour(AbstractBehaviour b)
          Adds a Behaviour to the Book.
 Behaviour addGlyphBehaviour(AbstractAction action)
          Adds the given Action to the list of Behaviours applied to new TextObjectGlyphs.
 void addGlyphBehaviour(AbstractBehaviour b)
          Adds the given Behaviour to the list of Behaviours applied to new TextObjectGlyphs.
 Behaviour addGroupBehaviour(AbstractAction action)
          Adds the given Action to the list of Behaviours applied to new TextObjectGroups.
 void addGroupBehaviour(AbstractBehaviour b)
          Adds the given Behaviour to the list of Behaviours applied to new TextObjectGroups.
 TextPage addPage(java.lang.String pageName)
          Create and add a named TextPage to the Book
 TextPage addPage(java.lang.String name, TextPage p)
          Add a named page to the book
 TextPage addPage(TextPage p)
          Add a page to the book without specifying a name.
 TextObjectGroup addText(java.lang.String text, int x, int y)
          Builds a tree of TextObjects from the given string, at the specified location, using the stroke and fill colors set in the PApplet.
 TextObjectGroup addText(java.lang.String text, int x, int y, int lineLength)
          Builds a tree of TextObjects from the given string, at the specified location, using the stroke and fill colors set in the PApplet.
 TextObjectGroup addText(java.lang.String text, int x, int y, int lineLength, java.lang.String pageName)
          Builds a tree of TextObjects on the given Page from the given string, at the specified location, using the stroke and fill colors set in the PApplet.
 TextObjectGroup addText(java.lang.String text, int x, int y, java.lang.String pageName)
          Builds a tree of TextObjects on the given Page from the given string, at the specified location, using the stroke and fill colors set in the PApplet.
 Behaviour addWordBehaviour(AbstractAction action)
          Adds the given Action to the list of Behaviours applied to new words.
 void addWordBehaviour(AbstractBehaviour b)
          Adds the given Behaviour to the list of Behaviours applied to new words.
 void attachText(TextObject to)
           
 void attachText(TextObject to, java.lang.String pageName)
           
 void clear()
          Removes all the TextObjects from all the TextPages in the Book, except for all the TextObjectRoots.
 void clearPage(java.lang.String pageName)
          Removes all the TextObjects from the given TextPage, except for the TextObjectRoot.
 void draw()
          Renders a frame.
 void drawPage(java.lang.String pageName)
          Renders the given page for this frame.
 java.util.List<AbstractBehaviour> getBehaviourList()
          Returns the BehaviourList
 long getFrameCount()
          The frame number, incremented each frame by the Simulator.
 int getIndent()
          Get paragraph indentation.
 int getIndentStyle()
          Get the paragraph indentation style.
 InputManager getInputs()
          Returns the Input Manager
 float getLineHeight()
          Deprecated.  
 int getLineSpacing()
          Get the line spacing of the text.
 TextPage getPage(java.lang.String name)
          Get a named page from the book
 java.util.Collection<TextPage> getPages()
          Returns the page set
 TextPageRenderer getRenderer()
          Returns the page renderer
 int getSpaceOffset()
          Get the space offset.
 SpatialList getSpatialList()
          Returns the Spatial List
 TextObjectRoot getTextRoot()
          Get the root of the TextObject hierarchy.
 int getTracking()
          Get the tracking of the text.
 float getTrackingOffset()
          Deprecated.  
 void incrementFrameCount()
          The frame number, incremented each frame by the Simulator.
static java.awt.Font loadFontFromPFont(processing.core.PFont pf)
           
 void log(java.lang.String message)
          Log a message.
 void log(java.lang.String message, java.lang.Throwable t)
           
 void removeAllGlyphBehaviours()
          Removes all Behaviours from the list of Behaviours applied to new TextObjectGlyphs.
 void removeAllGroupBehaviours()
          Removes all Behaviours from the list of Behaviours applied to new TextObjectGroups.
 void removeAllWordBehaviours()
          Removes all Behaviours from the list of Behaviours applied to new word.
 void removeBehaviour(AbstractBehaviour b)
          Removes a Behaviour from the Book.
 void removeChildren(TextObjectGroup to)
          Removes the children of this textObject from the book
 void removeGlyphBehaviour(AbstractBehaviour b)
          Removes the given Behaviour from the list of Behaviours applied to new TextObjectGlyphs.
 void removeGroupBehaviour(AbstractBehaviour b)
          Removes the given Behaviour from the list of Behaviours applied to new TextObjectGroups.
 void removeObject(TextObject to)
          Remove a text object and any children from the tree.
 void removeQueuedObjects()
          Removes all objects that have been marked for deletion.
 void removeWordBehaviour(AbstractBehaviour b)
          Removes the given Behaviour from the list of Behaviours applied to new words.
 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 setLogger(java.io.PrintWriter pw)
          Specify a PrintWriter to which all log messages will be written.
 void setSpaceOffset(int space)
          Set the space offset.
 void setTracking(int d)
          Set the tracking of the text.
 void setTrackingOffset(float d)
          Deprecated.  
 void step()
          Applies all active behaviours.
 void stepAndDraw()
          Goes through a full iteration of the Book loop, i.e.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

toBuilder

public static TextObjectBuilder toBuilder

mouse

public static MouseDefault mouse

keyboard

public static KeyboardDefault keyboard
Constructor Detail

Book

public Book(processing.core.PApplet p)
Instantiates the Book with a default renderer.

Parameters:
p - the parent PApplet

Book

public Book(processing.core.PApplet p,
            java.lang.String rendererType)
Instantiates the Book with a specific renderer.

Parameters:
p - the parent PApplet
rendererType - the type of renderer to use, can be JAVA2D or OPENGL

Book

public Book(processing.core.PApplet p,
            processing.core.PGraphics g)
Instatiates the Book with specific PGraphics object.

Parameters:
p - the parent PApplet
g - the PGraphics object to render to

Book

public Book(processing.core.PApplet p,
            processing.core.PGraphics g,
            java.lang.String rendererType)
Instantiates the Book.

Parameters:
p - the parent PApplet
rendererType - the type of renderer to use, can be JAVA2D or OPENGL
Method Detail

getFrameCount

public long getFrameCount()
The frame number, incremented each frame by the Simulator.


incrementFrameCount

public void incrementFrameCount()
The frame number, incremented each frame by the Simulator.


removeObject

public void removeObject(TextObject to)
Remove a text object and any children from the tree.

This method will:

The object is not removed immediately, it is removed prior to starting the next simulator run. This means that behaviours can safely call this method without worrying that the object will disappear and mess up other behaviours in the chain.


removeQueuedObjects

public void removeQueuedObjects()
Removes all objects that have been marked for deletion.

Do not call this method while iterating over the TextObjectRoot for synchronization reasons.


step

public void step()
Applies all active behaviours.

This code is adapted from Simulator.run().


draw

public void draw()
Renders a frame.


drawPage

public void drawPage(java.lang.String pageName)
Renders the given page for this frame.

Parameters:
pageName - the name of the Page to render

stepAndDraw

public void stepAndDraw()
Goes through a full iteration of the Book loop, i.e. applies all behaviours and then renders a frame.


loadFontFromPFont

public static java.awt.Font loadFontFromPFont(processing.core.PFont pf)

addText

public TextObjectGroup addText(java.lang.String text,
                               int x,
                               int y)
Builds a tree of TextObjects from the given string, at the specified location, using the stroke and fill colors set in the PApplet.

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:
TextObjectGroup the built TextObjectGroup

addText

public TextObjectGroup addText(java.lang.String text,
                               int x,
                               int y,
                               java.lang.String pageName)
Builds a tree of TextObjects on the given Page from the given string, at the specified location, using the stroke and fill colors set in the PApplet.

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
pageName - the name of the Page to build on
Returns:
TextObjectGroup the built TextObjectGroup

addText

public TextObjectGroup addText(java.lang.String text,
                               int x,
                               int y,
                               int lineLength)
Builds a tree of TextObjects from the given string, at the specified location, using the stroke and fill colors set in the PApplet.

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:
TextObjectGroup the built TextObjectGroup

addText

public TextObjectGroup addText(java.lang.String text,
                               int x,
                               int y,
                               int lineLength,
                               java.lang.String pageName)
Builds a tree of TextObjects on the given Page from the given string, at the specified location, using the stroke and fill colors set in the PApplet.

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
pageName - the name of the Page to build on
Returns:
TextObjectGroup the built TextObjectGroup

attachText

public void attachText(TextObject to)

attachText

public void attachText(TextObject to,
                       java.lang.String pageName)

addGlyphBehaviour

public void addGlyphBehaviour(AbstractBehaviour b)
Adds the given Behaviour to the list of Behaviours applied to new TextObjectGlyphs.

The Behaviour will only be added to TextObjects created after this method is called.

The Behaviour is automatically added to the NTPBook.

Parameters:
b - the Behaviour to add

addGlyphBehaviour

public Behaviour addGlyphBehaviour(AbstractAction action)
Adds the given Action to the list of Behaviours applied to new TextObjectGlyphs.

The Action is converted into a Behaviour automatically.

The Behaviour will only be added to TextObjects created after this method is called.

The Behaviour is automatically added to the NTPBook.

The Behaviour is returned to allow calling removeGlyphBehaviour with the correct object.

Parameters:
action - the AbstractAction to convert and add as a behaviour
Returns:
the behaviour created from the action

removeGlyphBehaviour

public void removeGlyphBehaviour(AbstractBehaviour b)
Removes the given Behaviour from the list of Behaviours applied to new TextObjectGlyphs.

The Behaviour will not be added to TextObjects created after this method is called.

Parameters:
b - the Behaviour to remove

removeAllGlyphBehaviours

public void removeAllGlyphBehaviours()
Removes all Behaviours from the list of Behaviours applied to new TextObjectGlyphs.


addWordBehaviour

public void addWordBehaviour(AbstractBehaviour b)
Adds the given Behaviour to the list of Behaviours applied to new words.

The Behaviour will only be added to TextObjects created after this method is called.

The Behaviour is automatically added to the NTPBook.

Parameters:
b - the Behaviour to add

addWordBehaviour

public Behaviour addWordBehaviour(AbstractAction action)
Adds the given Action to the list of Behaviours applied to new words.

The Action is converted into a Behaviour automatically.

The Behaviour will only be added to TextObjects created after this method is called.

The Behaviour is automatically added to the NTPBook.

The Behaviour is returned to allow calling removeWordBehaviour with the correct object.

Parameters:
action - the AbstractAction to convert and add as a behaviour
Returns:
the behaviour created from the action

removeWordBehaviour

public void removeWordBehaviour(AbstractBehaviour b)
Removes the given Behaviour from the list of Behaviours applied to new words.

The Behaviour will not be added to TextObjects created after this method is called.

Parameters:
b - the Behaviour to remove

removeAllWordBehaviours

public void removeAllWordBehaviours()
Removes all Behaviours from the list of Behaviours applied to new word.


addGroupBehaviour

public void addGroupBehaviour(AbstractBehaviour b)
Adds the given Behaviour to the list of Behaviours applied to new TextObjectGroups.

The Behaviour will only be added to TextObjects created after this method is called.

The Behaviour is automatically added to the NTPBook.

Parameters:
b - the Behaviour to add

addGroupBehaviour

public Behaviour addGroupBehaviour(AbstractAction action)
Adds the given Action to the list of Behaviours applied to new TextObjectGroups.

The Action is converted into a Behaviour automatically.

The Behaviour will only be added to TextObjects created after this method is called.

The Behaviour is automatically added to the NTPBook.

The Behaviour is returned to allow calling removeGlyphBehaviour with the correct object.

Parameters:
action - the AbstractAction to convert and add as a behaviour
Returns:
the behaviour created from the action

removeGroupBehaviour

public void removeGroupBehaviour(AbstractBehaviour b)
Removes the given Behaviour from the list of Behaviours applied to new TextObjectGroups.

The Behaviour will not be added to TextObjects created after this method is called.

Parameters:
b - the Behaviour to remove

removeAllGroupBehaviours

public void removeAllGroupBehaviours()
Removes all Behaviours from the list of Behaviours applied to new TextObjectGroups.


getRenderer

public TextPageRenderer getRenderer()
Returns the page renderer


getPages

public java.util.Collection<TextPage> getPages()
Returns the page set


getBehaviourList

public java.util.List<AbstractBehaviour> getBehaviourList()
Returns the BehaviourList


getTextRoot

public TextObjectRoot getTextRoot()
Get the root of the TextObject hierarchy. Any changes to this tree must be synchronized on the book. Do not add textObjects as children of the textRoot directly because they will not be rendered, add them to a TextPage instead.


getInputs

public InputManager getInputs()
Returns the Input Manager


getSpatialList

public SpatialList getSpatialList()
Returns the Spatial List


addPage

public TextPage addPage(TextPage p)
Add a page to the book without specifying a name.

The page will be named "layerN" where N = 0,1,2,3...

Returns:
the new page

addPage

public TextPage addPage(java.lang.String name,
                        TextPage p)
Add a named page to the book

Returns:
the new page

addPage

public TextPage addPage(java.lang.String pageName)
Create and add a named TextPage to the Book

Parameters:
pageName - the name of the TextPage to add
Returns:
the new page

getPage

public TextPage getPage(java.lang.String name)
Get a named page from the book

Returns:
the page

addBehaviour

public void addBehaviour(AbstractBehaviour b)
Adds a Behaviour to the Book.


removeBehaviour

public void removeBehaviour(AbstractBehaviour b)
Removes a Behaviour from the Book.


removeChildren

public void removeChildren(TextObjectGroup to)
Removes the children of this textObject from the book

Parameters:
to -

clear

public void clear()
Removes all the TextObjects from all the TextPages in the Book, except for all the TextObjectRoots.


clearPage

public void clearPage(java.lang.String pageName)
Removes all the TextObjects from the given TextPage, except for the TextObjectRoot.

Parameters:
pageName - the name of the TextPage to clear

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

setLogger

public void setLogger(java.io.PrintWriter pw)
Specify a PrintWriter to which all log messages will be written.

NextText generated messages are written to this PrintWriter.


log

public void log(java.lang.String message)
Log a message.

The message will go to standard output, as well as a log file if one has been specified with setLogFile(). A newline will be appended to the message.


log

public void log(java.lang.String message,
                java.lang.Throwable t)