|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.hdcookbook.grin.commands.Command com.hdcookbook.grin.GrinXHelper
public class GrinXHelper
This class has three distinct functions. It's mostly a helper class that acts as a superclass for code that gets generated in a GRIN show file, for the java_command structures and for instantiating GRIN extensions. This class is also used directly for some built-in GRIN commands. Doing this kind of functional overloading in one class definition is admittedly not very OO, but experimental data shows that classloading is a moderately expensive operation, so we do this overloading to optimize xlet start-up time.
To illustrate the different functions of this class, assume a show that defines a class called MenuShowCommands as the helper classname in the show file. The functions of GrinXHelper are:
For the built-in GRIN commands, the direct instances of GrinXHelper get instantiated "automatically" by the GRIN binary reader. The class GrinXHelper is registered as a built-in class, so that part "just works" -- it's represented by the integer constant GRINXHELPER_CMD_IDENTIFIER. For the MenuShowCommands instances, they're represented by the (interned) string that hold the fully-qualified classname of MenuShowCommands, which the binary reader feeds (once) into Class.forName() so that it can call newInstance().
To see how the java_command commands get compiled into the show's
subclass of GrinXHelper, see
com.hdcookbook.grin.SEShowCommands
XLET_ONLY [[ private final static org.bluray.system.RegisterAccess registers = org.bluray.system.RegisterAccess.getInstance(); ]] GRINVIEW_ONLY [[ private final static com.hdcookbook.grin.test.bigjdk.BDRegisterEmulator registers = com.hdcookbook.grin.test.bigjdk.BDRegisterEmulator.getInstance(); ]]With that, your commands can have statements like "int angleNumber = registers.getPSR(3)" or "registers.setGPR(10, 42)".
A better pattern might be to divide your director into an abstract superclass, with two implementations of the subclass, one for GrinView and one for a real xlet. That way, the common director can have an abstract method like "getPSR(int)" that you implement for GrinView in terms of an array, or maybe in terms of BDRegisterEmulator. This same abstract director pattern can be used for other player functionality, too. This is a more powerful and general technique than GRINVIEW_ONLY and XLET_ONLY.
Field Summary | |
---|---|
protected static int |
COMMAND_LIST
The commandNumber for the GRIN internal list-of-commands command |
protected int |
commandNumber
|
static int |
MOUSE_CLICK
The commandNumber for handling MOUSE_CLICK event |
static int |
MOUSE_MOVE
The commandNumber for handling MOUSE_MOVE event |
protected static int |
SEGMENT_DONE
The commandNumber for a segment_done command |
protected Command[] |
subCommands
|
protected static int |
SYNC_DISPLAY
The commandNumber for a sync_display command |
Fields inherited from class com.hdcookbook.grin.commands.Command |
---|
show |
Constructor Summary | |
---|---|
GrinXHelper(Show show)
|
Method Summary | |
---|---|
void |
execute()
Execute the command. |
void |
execute(Show caller)
Execute the command. |
Node |
getInstanceOf(Show show,
int id)
Instantiate an extension class. |
void |
readInstanceData(GrinDataInputStream in,
int length)
Reads in this node information from the binary file format. |
protected void |
runSubCommand(int num,
Show caller)
Run a sub-command. |
void |
setCommandNumber(int commandNumber)
Sets the command number for this class when used as a command. |
void |
setCommandObject(java.lang.Object object)
Sets the additional data for this class when used as a command. |
void |
setSubCommands(Command[] subCommands)
Sets the sub-commands array for this class when used as a java_command. |
java.lang.String |
toString()
Return a user-friendly string for this command for debugging purposes. |
Methods inherited from class com.hdcookbook.grin.commands.Command |
---|
cloneIfNeeded, deferNextCommands |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected int commandNumber
protected Command[] subCommands
protected static final int SYNC_DISPLAY
protected static final int SEGMENT_DONE
protected static final int COMMAND_LIST
public static final int MOUSE_MOVE
public static final int MOUSE_CLICK
Constructor Detail |
---|
public GrinXHelper(Show show)
Method Detail |
---|
public void setCommandNumber(int commandNumber)
public void setCommandObject(java.lang.Object object)
public void setSubCommands(Command[] subCommands)
protected void runSubCommand(int num, Show caller)
num
- The numeric ID of the command to execute. This is
automatically generated by the compiler.public void readInstanceData(GrinDataInputStream in, int length) throws java.io.IOException
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.
readInstanceData
in interface Node
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.
java.io.IOException
- if error occurs.GrinDataInputStream.readSuperClassData(Feature)
,
GrinDataInputStream.readSuperClassData(RCHandler)
,
GrinDataInputStream.readSuperClassData(Segment)
,
GrinDataInputStream.readSuperClassData(Command)
public void execute(Show caller)
execute
in class Command
caller
- The show that is executing this command. This might
not be the same as the show this command was created
under.public void execute()
execute
in class Command
public Node getInstanceOf(Show show, int id) throws java.io.IOException
java.io.IOException
public java.lang.String toString()
toString
in class Command
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |