com.hdcookbook.grinxlet
Class GrinXlet

java.lang.Object
  extended by com.hdcookbook.grinxlet.GrinXlet
All Implemented Interfaces:
AnimationContext, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener, javax.tv.xlet.Xlet, org.dvb.event.UserEventListener

public class GrinXlet
extends java.lang.Object
implements javax.tv.xlet.Xlet, AnimationContext, org.dvb.event.UserEventListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener

The xlet class for a grin-centric xlet project. This is the debug version of the xlet, with debug support turned on.

WARNING: There are actually three copies of this class: The debug version, the deploy version, and the GrinView version. The GrinView version can be found under AuthoringTools/grin/jdktools/grinviewer. It offers a subset of the public method of GrinXlet, e.g. to get and set the list of animation clients. This allows a GrinView simulation of a wider range of functionalities on a desktop.

If you add features to the xlet versions of this class (both debug and deploy), consider adding them to the GrinView version, too.


Field Summary
 Show show
           
static javax.tv.xlet.XletContext xletContext
          The XletContext of our game xlet.
 
Constructor Summary
GrinXlet()
           
 
Method Summary
 void animationFinishInitialization()
          Run the last part of initialization.
 void animationInitialize()
          Run the first part of initialization.
protected  AnimationEngine createAnimationEngine()
          Create the animation engine for this xlet, set up for the desired framerate.
 void destroyXlet(boolean unconditional)
           
protected  void doInitXlet(java.lang.String[] args)
          This method can be overridden by subclasses that want to look for xlet arguments in places other than the default XletContext.ARGS and "dvb.caller.parameters".
 AnimationClient[] getAnimationClients()
          Get the list of animation clients
 AnimationEngine getAnimationEngine()
          Get the animation engine
static GrinXlet getInstance()
          Get the instance of this singleton
protected  java.awt.Container getRootContainer()
          Return the root container for this xlet, with the size set to the desired size.
 void initXlet(javax.tv.xlet.XletContext context)
           
 void mouseClicked(java.awt.event.MouseEvent e)
          Mouse clicked callback
 void mouseDragged(java.awt.event.MouseEvent e)
          Mouse motion callback (when a button is down)
 void mouseEntered(java.awt.event.MouseEvent e)
          Mouse entered callback
 void mouseExited(java.awt.event.MouseEvent e)
          Mouse exited callback
 void mouseMoved(java.awt.event.MouseEvent e)
          Mouse motion callback
 void mousePressed(java.awt.event.MouseEvent e)
          Mouse pressed callback
 void mouseReleased(java.awt.event.MouseEvent e)
          Mouse released callback
 void pauseXlet()
           
 Show popKeyInterest()
          Removes the show at the top of the key interest stack.
 void pushKeyInterest(Show show)
          Inserts a new Show at the top of the key interest stack.
 void resetAnimationClients(AnimationClient[] clients)
          Reset the list of animation clients
 void startXlet()
           
 void userEventReceived(org.dvb.event.UserEvent e)
          A remote control event that is coming in via org.dvb.event.UserEventListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xletContext

public static javax.tv.xlet.XletContext xletContext
The XletContext of our game xlet. This is exposed as a public static variable so that client code can access the XletContext. It's set as soon as we discover our context, and nulled when the xlet is destroyed.

This is not available in the GrinView version of GrinXlet.


show

public Show show
Constructor Detail

GrinXlet

public GrinXlet()
Method Detail

getInstance

public static GrinXlet getInstance()
Get the instance of this singleton


getAnimationClients

public AnimationClient[] getAnimationClients()
Get the list of animation clients


resetAnimationClients

public void resetAnimationClients(AnimationClient[] clients)
Reset the list of animation clients


getAnimationEngine

public AnimationEngine getAnimationEngine()
Get the animation engine


initXlet

public void initXlet(javax.tv.xlet.XletContext context)
Specified by:
initXlet in interface javax.tv.xlet.Xlet

getRootContainer

protected java.awt.Container getRootContainer()
Return the root container for this xlet, with the size set to the desired size. The default implementation of this method returns a root container acquired from javax.tv.graphics.TVContainer.getRootContainer() (which in GEM systems is an HScene). It is sized to 1920x1080 by the default implementation of this method.

Subclasses may override this method to use a different container as the root container, or to set a different size. The implementation of the subclass method might also change the resolution of the player, e.g. from full HD (1920x1080) to QHD (960x540).


doInitXlet

protected void doInitXlet(java.lang.String[] args)
This method can be overridden by subclasses that want to look for xlet arguments in places other than the default XletContext.ARGS and "dvb.caller.parameters". Subclasses that override this should call super.doInitXlet(args) once they've colleded their arguments.


createAnimationEngine

protected AnimationEngine createAnimationEngine()
Create the animation engine for this xlet, set up for the desired framerate.


startXlet

public void startXlet()
Specified by:
startXlet in interface javax.tv.xlet.Xlet

pauseXlet

public void pauseXlet()
Specified by:
pauseXlet in interface javax.tv.xlet.Xlet

destroyXlet

public void destroyXlet(boolean unconditional)
Specified by:
destroyXlet in interface javax.tv.xlet.Xlet

animationInitialize

public void animationInitialize()
                         throws java.lang.InterruptedException
Description copied from interface: AnimationContext
Run the first part of initialization. By the time this is done, all of the initXXX methods of the animation framework that need to be called should be. Notably, the animation framework should be provided with a component. This method is called as the first step in the animation thread.

If this initialization is time-consuming, it should poll AnimationEngine.destroyRequested() from time to time, and bail out if needed. A good way to do this is by calling checkDestroy().

Specified by:
animationInitialize in interface AnimationContext
Throws:
java.lang.InterruptedException
See Also:
AnimationEngine.destroyRequested(), AnimationEngine.checkDestroy()

animationFinishInitialization

public void animationFinishInitialization()
Description copied from interface: AnimationContext
Run the last part of initialization. This is called by the animation thread after all of the animation clients are initialized. This is the last initialization step before running the actual animation loop. It's a good place to set the state of the UI, e.g. by calling a GRIN Show object's activateSegment() command. It might also be a reasonable place to call System.gc(), since initialization normally creates a lot of garbage, and the normal running of an xlet hopefully doesn't.

If this initialization is time-consuming, it should poll AnimationEngine.destroyRequested() from time to time, and bail out if needed. A good way to do this is by calling checkDestroy().

Specified by:
animationFinishInitialization in interface AnimationContext
See Also:
AnimationEngine.destroyRequested(), Show.activateSegment(com.hdcookbook.grin.Segment)

userEventReceived

public void userEventReceived(org.dvb.event.UserEvent e)
A remote control event that is coming in via org.dvb.event.UserEventListener

Specified by:
userEventReceived in interface org.dvb.event.UserEventListener

pushKeyInterest

public void pushKeyInterest(Show show)
Inserts a new Show at the top of the key interest stack. KeyEvents are delivered to the shows starting from the top of the key interest stack. If the show's currently active segment do not have any rc_handler that uses the key, then the the event is sent to the next show on the stack. MouseEvents are sent to all the shows in the key interest list.


popKeyInterest

public Show popKeyInterest()
Removes the show at the top of the key interest stack. KeyEvents are delivered to a show in the order starting from the top of the key interest stack. If the show's currently active segment do not have any rc_handler that uses the key, then the the event is sent to the next show on the stack. MouseEvents are sent to all the shows in the key interest list.


mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Mouse motion callback

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Mouse motion callback (when a button is down)

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Mouse clicked callback

Specified by:
mouseClicked in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Mouse pressed callback

Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Mouse released callback

Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Mouse entered callback

Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Mouse exited callback

Specified by:
mouseExited in interface java.awt.event.MouseListener