com.hdcookbook.grin.features
Class Translator

java.lang.Object
  extended by com.hdcookbook.grin.Feature
      extended by com.hdcookbook.grin.features.Modifier
          extended by com.hdcookbook.grin.features.Translator
All Implemented Interfaces:
Node
Direct Known Subclasses:
SETranslator

public class Translator
extends Modifier
implements Node

A Translator wraps other features, and adds movement taken from a translator model (represented at runtime by an InterpolatedModel) to it. The subfeature is translated by the given amount. For backwards compatibility reasons, there's also an "absolute" mode that attempts to use the coordinates of the upper-left hand corner of the child, but this mode is deprecated.

Author:
Bill Foote (http://jovial.com)
See Also:
InterpolatedModel

Field Summary
protected  int fx
           
protected  int fy
           
protected  InterpolatedModel model
           
protected  boolean modelIsRelative
           
static int OFFSCREEN
          A special value to use to translate something offscreen.
static int X_FIELD
          The field number in our model for the X coordinate
static int Y_FIELD
          The field number in our model for the Y coordinate
 
Fields inherited from class com.hdcookbook.grin.features.Modifier
activated, part
 
Fields inherited from class com.hdcookbook.grin.Feature
name, show
 
Constructor Summary
Translator(Show show)
           
 
Method Summary
 void addDisplayAreas(RenderContext context)
          Add all of the areas that are displayed for this feature with the current frame.
protected  Feature createClone(java.util.HashMap clones)
          This is an implementation method that should not be called direction by applications; applications should call cloneSubgraph().
 void destroy()
          Free any resources held by this feature.
 InterpolatedModel getModel()
          Get the translation that moves us
 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.
protected  void initializeClone(Feature original, java.util.HashMap clones)
          This is an implementation method that should not be called direction by applications; it is called from cloneSubgraph().
 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.
 
Methods inherited from class com.hdcookbook.grin.features.Modifier
addSubgraph, getPart, markDisplayAreasChanged, needsMoreSetup, setActivateMode, setChildChanged, setSetupMode, setup
 
Methods inherited from class com.hdcookbook.grin.Feature
activate, cloneCommands, clonedReference, cloneSubgraph, deactivate, destroyClonedSubgraph, getName, 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

X_FIELD

public static final int X_FIELD
The field number in our model for the X coordinate

See Also:
InterpolatedModel, Constant Field Values

Y_FIELD

public static final int Y_FIELD
The field number in our model for the Y coordinate

See Also:
InterpolatedModel, Constant Field Values

OFFSCREEN

public static final int OFFSCREEN
A special value to use to translate something offscreen. Set the x or the y coordinate to this value if you want it hidden. Numerically, it's Integer.MIN_VALUE.

See Also:
Constant Field Values

model

protected InterpolatedModel model

fx

protected int fx

fy

protected int fy

modelIsRelative

protected boolean modelIsRelative
Constructor Detail

Translator

public Translator(Show show)
Method Detail

createClone

protected Feature createClone(java.util.HashMap clones)
This is an implementation method that should not be called direction by applications; applications should call cloneSubgraph(). New subclasses of Feature that wish to support cloning must override this method.

Create a new clone of this feature. This method creates a new instance of this feature, and creates new instances of any sub-features, but it does not initialize the feature. This method is called from Feature.makeNewClone().

See the documentation of cloneSubgraph() for a list of runtime exceptions this method can throw. Subclasses that wish to support cloning must override this method.

Overrides:
createClone in class Feature
Parameters:
clones - A map from original feature to cloned feature. Entries are added by Feature.makeNewClone().
See Also:
Feature.makeNewClone(java.util.HashMap), Feature.cloneSubgraph(java.util.HashMap)

initializeClone

protected void initializeClone(Feature original,
                               java.util.HashMap clones)
This is an implementation method that should not be called direction by applications; it is called from cloneSubgraph(). New subclasses of Feature may override this method.

Initialize this cloned feature from its original. This is called after the entire subgraph has been cloned, so the HashMap containing the set of clones will be complete. See the documentation of cloneSubgraph() for a list of runtime exceptions this method can throw. Subclasses that wish to support cloning must override this method.

If this feature doesn't need initialization it's OK for a feature to not implement it; the default version of this method does nothing. Typically, you only need to implement this for features that have references to other features that aren't sub-features, or that have commands that might have references to other features.

Overrides:
initializeClone in class Feature
See Also:
Feature.cloneSubgraph(java.util.HashMap)

getModel

public InterpolatedModel getModel()
Get the translation that moves us


initialize

public void initialize()
Initialize this feature. This is called on show initialization. A show will initialize all of its features after it initializes the segments.

Overrides:
initialize in class Modifier

destroy

public void destroy()
Free any resources held by this feature. It is the opposite of setup; each call to setup() shall be balanced by a call to unsetup(), and they shall *not* be nested.

It's possible an active segment may be destroyed. For example, the last segment a show is in when the show is destroyed will probably be active (and it will probably be an empty segment too!).

Overrides:
destroy in class Modifier

nextFrame

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

Overrides:
nextFrame in class Modifier

addDisplayAreas

public void addDisplayAreas(RenderContext context)
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.

Subclasses will probably want to override this to account for changes in the drawing environment they make. The version in this class simply calls this method on the modified part.

Overrides:
addDisplayAreas in class Modifier
Parameters:
context - The context for tracking rendering state
See Also:
DrawRecord

getX

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

Overrides:
getX in class Modifier
Returns:
the x coordinate

getY

public 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.

Overrides:
getY in class Modifier
Returns:
the y coordinate

paintFrame

public void paintFrame(java.awt.Graphics2D gr)
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.

Overrides:
paintFrame in class Modifier
Parameters:
gr - The place to paint to.

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)