com.hdcookbook.grin.fontstrip
Class FontStripText

java.lang.Object
  extended by com.hdcookbook.grin.Feature
      extended by com.hdcookbook.grin.fontstrip.FontStripText
All Implemented Interfaces:
Node, SetupClient

public class FontStripText
extends Feature
implements Node, SetupClient

A feature for drawing font strip text.

See the file READM.TXT in the font strip extension base directory for more details.


Field Summary
protected  int alignment
          The alignment to apply to x and y.
protected  java.awt.Color background
           
static int BASELINE
          Value for alignment indicating that y refers to the baseline of the text.
static int BOTTOM
          Value for alignment indicating that y refers to the baseline of the text.
protected  java.lang.String fontImageFileName
           
protected  int hspace
           
static java.lang.String INFOFILE
          The name of the fontstrip information file.
static int LEFT
          Value for alignment indicating that x refers to the left side of the text.
static int MIDDLE
          Value for alignment indicating that x refers to the middle of the text.
static int RIGHT
          Value for alignment indicating that x refers to the right side of the text.
protected  java.lang.String[] strings
           
static int TOP
          Value for alignment indicating that y refers to the top side of the text.
protected  int vspace
           
protected  int xArg
           
protected  int yArg
           
 
Fields inherited from class com.hdcookbook.grin.Feature
name, show
 
Constructor Summary
FontStripText(Show show)
           
 
Method Summary
 void addDisplayAreas(RenderContext context)
          Add all of the areas that are displayed for this feature with the current frame.
 void destroy()
          Free any resources held by this feature.
 void doSomeSetup()
          Do some (or all) of the setup work needed for this client.
 int getLineHeight()
          Get the height of a line, including any vertical padding to take it to the next line.
 java.lang.String[] getText()
          Get the text that's being displayed.
 int getX()
          Get the upper-left hand corner of this feature as presently displayed.
 int getY()
          Get the upper-left hand corner of this feature as presently displayed Return Integer.MAX_VALUE if this feature has no visible representation.
 void initialize()
          Initialize this feature.
 void markDisplayAreasChanged()
          Mark the display areas of this feature as modified for the next call to addDisplayAreas.
 boolean needsMoreSetup()
          This is where the feaure says whether or not it needs more setup.
 void nextFrame()
          Called from Segment with the Show lock held, to advance us to the state we should be in for the next frame.
 void paintFrame(java.awt.Graphics2D gr)
          Paint the current state of this feature to gr.
 void readInstanceData(GrinDataInputStream in, int length)
          Reads in this node information from the binary file format.
protected  void setActivateMode(boolean mode)
          Change the activated mode of this feature.
protected  int setSetupMode(boolean mode)
          Change the setup mode of this feature.
 void setText(java.lang.String[] newText)
          Change the text to display.
 
Methods inherited from class com.hdcookbook.grin.Feature
activate, addSubgraph, cloneCommands, clonedReference, cloneSubgraph, createClone, deactivate, destroyClonedSubgraph, getName, initializeClone, isSetup, makeNewClone, resetFeature, sendFeatureSetup, setName, setup, toString, unsetup
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LEFT

public static final int LEFT
Value for alignment indicating that x refers to the left side of the text.

See Also:
Constant Field Values

MIDDLE

public static final int MIDDLE
Value for alignment indicating that x refers to the middle of the text.

See Also:
Constant Field Values

RIGHT

public static final int RIGHT
Value for alignment indicating that x refers to the right side of the text.

See Also:
Constant Field Values

TOP

public static final int TOP
Value for alignment indicating that y refers to the top side of the text.

See Also:
Constant Field Values

BASELINE

public static final int BASELINE
Value for alignment indicating that y refers to the baseline of the text.

See Also:
Constant Field Values

BOTTOM

public static final int BOTTOM
Value for alignment indicating that y refers to the baseline of the text.

See Also:
Constant Field Values

alignment

protected int alignment
The alignment to apply to x and y. The value is obtained by or-ing (or by adding) a horizontal value (LEFT, MIDDLE or RIGHT) with a vertical value (TOP, BASELINE or BOTTOM).


INFOFILE

public static final java.lang.String INFOFILE
The name of the fontstrip information file.

See Also:
Constant Field Values

xArg

protected int xArg

yArg

protected int yArg

strings

protected java.lang.String[] strings

fontImageFileName

protected java.lang.String fontImageFileName

hspace

protected int hspace

vspace

protected int vspace

background

protected java.awt.Color background
Constructor Detail

FontStripText

public FontStripText(Show show)
Method Detail

getX

public int getX()
Description copied from class: Feature
Get the upper-left hand corner of this feature as presently displayed. Return Integer.MAX_VALUE if this feature has no visible representation.

Specified by:
getX in class Feature
Returns:
the x coordinate

getY

public int getY()
Description copied from class: Feature
Get the upper-left hand corner of this feature as presently displayed Return Integer.MAX_VALUE if this feature has no visible representation.

Specified by:
getY in class Feature
Returns:
the y coordinate

initialize

public void initialize()
Description copied from class: Feature
Initialize this feature. This is called on show initialization. A show will initialize all of its features after it initializes the segments. Clients of the GRIN framework should never call this method directly. Custom feature extensions must implement this method.

Specified by:
initialize in class Feature

destroy

public void destroy()
Description copied from class: Feature
Free any resources held by this feature. It is the opposite of initialize().

Features are deactivated before they are destroyed. For example, the last segment a show is in when the show is destroyed will probably be active, but it is deactivated and unsetup() is called in Show.destroy() before the features are destroyed.

Cloned features are handled a little differently. They have destroy() called from within Feature.destroyClonedSubgraph(). Since cloned fetures are exempt from the setup/unsetup lifecycle, the cloned feature will not be activated, but will be in a setup state when destroy() is called. Features that support cloning must therefore release any resources they acquired in createClone() or initializeClone() during the call to destroy().

Clients of the GRIN framework should never call this method directly. Custom feature extensions must implement this method.

Specified by:
destroy in class Feature

setSetupMode

protected int setSetupMode(boolean mode)
Change the setup mode of this feature. The new mode will always be different than the old. Clients of the GRIN framework should never call this method directly. Custom feature extensions must implement this method.

This method must return a guaranteed lower bound for the number of times it will send a feature setup command as a result of this call. That is, it must send at least as many feature setup commands to the segment as the number returned; sending an accurate number makes the setup process more efficient, since the time it takes to process a command scales with the number of features in a segment. When mode is false, 0 should be returned.

Specified by:
setSetupMode in class Feature

doSomeSetup

public void doSomeSetup()
Do some (or all) of the setup work needed for this client. This might be called when setup is no longer required; in this case, the client should just return.

Specified by:
doSomeSetup in interface SetupClient

needsMoreSetup

public boolean needsMoreSetup()
This is where the feaure says whether or not it needs more setup. Calls to this are synchronized within the init manager to avoid race conditions. The implementation of this method must not call outside code or call any animation manager methods. For a given setup cycle, this method is called only after setup(). Clients of the GRIN framework should never call this method directly. Custom feature extensions must implement this method.

Specified by:
needsMoreSetup in interface SetupClient
Specified by:
needsMoreSetup in class Feature
See Also:
SetupClient.needsMoreSetup()

setActivateMode

protected void setActivateMode(boolean mode)
Description copied from class: Feature
Change the activated mode of this feature. The new mode will always be different than the old. Clients of the GRIN framework should never call this method directly. Custom feature extensions must implement this method.

Specified by:
setActivateMode in class Feature

addDisplayAreas

public void addDisplayAreas(RenderContext context)
Description copied from class: Feature
Add all of the areas that are displayed for this feature with the current frame. This will be called exactly once per frame displayed on each activated feature.

A feature that displays something needs to maintain a record of it in a DrawRecord. The animation framework uses this to track what needs to be erased and drawn from frame to frame.

Clients of the GRIN framework should not call this method directly. Feature subclasses must implement this method.

Specified by:
addDisplayAreas in class Feature
Parameters:
context - The context for tracking rendering state
See Also:
DrawRecord

paintFrame

public void paintFrame(java.awt.Graphics2D gr)
Description copied from class: Feature
Paint the current state of this feature to gr. Clients of the GRIN framework should not call this method directly. Feature subclasses must implement this method.

Specified by:
paintFrame in class Feature
Parameters:
gr - The place to paint to.

nextFrame

public void nextFrame()
Description copied from class: Feature
Called from Segment with the Show lock held, to advance us to the state we should be in for the next frame.

Specified by:
nextFrame in class Feature

markDisplayAreasChanged

public void markDisplayAreasChanged()
Description copied from class: Feature
Mark the display areas of this feature as modified for the next call to addDisplayAreas. This can be called by a parent node on its children, e.g. when the parent is deactivated. This is necessary because a parent node might modify the drawing of its children (e.g. by setting an alpha value), and a parent might be taken out of a render tree when its children are not.

See also Issue 121

Specified by:
markDisplayAreasChanged in class Feature
See Also:
Feature.addDisplayAreas(com.hdcookbook.grin.animator.RenderContext)

readInstanceData

public void readInstanceData(GrinDataInputStream in,
                             int length)
                      throws java.io.IOException
Description copied from interface: Node
Reads in this node information from the binary file format.

An implementation of this method is recommended to call in.readSuperClassData(this) as the first line of the method to read in information that is defined in the base class of this Node type.

This should only be called while initializing this object.

Specified by:
readInstanceData in interface Node
Parameters:
in - InputStream to read data from.
length - the number of bytes that this node's information occupies in the InputStream. The implementation of this method is expected to read exactly this number of bytes from the stream. This can be used for a debugging purpose.
Throws:
java.io.IOException - if error occurs.
See Also:
GrinDataInputStream.readSuperClassData(Feature), GrinDataInputStream.readSuperClassData(RCHandler), GrinDataInputStream.readSuperClassData(Segment), GrinDataInputStream.readSuperClassData(Command)

getText

public java.lang.String[] getText()
Get the text that's being displayed.


getLineHeight

public int getLineHeight()
Get the height of a line, including any vertical padding to take it to the next line.


setText

public void setText(java.lang.String[] newText)
Change the text to display. This should only be called with the show lock held, at an appropriate time in the frame pump loop. A good time to call this is from within a command.

A good way to write this command that calls this is by using the java_command structure. There's an example of this in the cookbook menu.