com.hdcookbook.grin.io.builders
Class VisualRCHandlerCell

java.lang.Object
  extended by com.hdcookbook.grin.io.builders.VisualRCHandlerCell
Direct Known Subclasses:
VisualRCHandlerCell.ActivateCell, VisualRCHandlerCell.LocationRefCell, VisualRCHandlerCell.NullCell, VisualRCHandlerCell.StateCell, VisualRCHandlerCell.StateRefCell, VisualRCHandlerCell.WallCell

public abstract class VisualRCHandlerCell
extends java.lang.Object

A cell within a VisualRCHandler. This class is used only for VisualRCHandlerHelper. This class has no public constructor; instead, it has different factory methods for the different cell types.

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

Nested Class Summary
static class VisualRCHandlerCell.ActivateCell
           
static class VisualRCHandlerCell.LocationRefCell
           
static class VisualRCHandlerCell.NullCell
           
static class VisualRCHandlerCell.StateCell
           
static class VisualRCHandlerCell.StateRefCell
           
static class VisualRCHandlerCell.WallCell
           
 
Field Summary
protected  int alternate
           
protected  VisualRCHandlerHelper helper
           
 
Method Summary
abstract  java.lang.String addState(java.util.Map<java.lang.String,java.lang.Integer> stateMap, java.util.Set<java.lang.String> dupCheck, java.util.Map<java.lang.String,VisualRCHandlerCell> cellMap)
          Add the state referred to by this cell to the map of states.
abstract  java.lang.String check()
          Check that this cell is OK.
abstract  VisualRCHandlerCell getRefersTo()
          Get the cell that this cell refers to.
 int getRightLeft()
          Get the value for the rightLeft parameter of VisualRCHandler.
abstract  java.lang.String getState()
          Get the name of the state of this cell, or that this cell refers to.
abstract  int getStateNumber(java.util.Map<java.lang.String,java.lang.Integer> states, java.lang.String stateFrom)
          Get the integer number of this state within the states map when navigating to this cell from the numbered state.
 int getUpDown()
          Get the value for the upDown parameter of VisualRCHandler.
static VisualRCHandlerCell newActivate()
          Create a cell that causes an activate.
static VisualRCHandlerCell newLocationRef(int x, int y)
          Create a cell that refers to a state somewhere else in the grid, where that state is specified by an x,y position in the grid (countin from 0).
static VisualRCHandlerCell newNull()
          Create a null cell.
static VisualRCHandlerCell newState(java.lang.String state)
          Create a cell that represents a new state.
static VisualRCHandlerCell newStateRef(java.lang.String state)
          Create a cell that refers to a state that exists somewhere else in the grid.
static VisualRCHandlerCell newWall()
          Create a cell that acts as a "wall".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

helper

protected VisualRCHandlerHelper helper

alternate

protected int alternate
Method Detail

getRefersTo

public abstract VisualRCHandlerCell getRefersTo()
Get the cell that this cell refers to. Returns null if this cell doesn't refer to another cell, e.g. because it's a state or an .


addState

public abstract java.lang.String addState(java.util.Map<java.lang.String,java.lang.Integer> stateMap,
                                          java.util.Set<java.lang.String> dupCheck,
                                          java.util.Map<java.lang.String,VisualRCHandlerCell> cellMap)
Add the state referred to by this cell to the map of states. Calling this method multiple times on the same cell has no effect.

Returns:
null if OK, or an error message if not

getState

public abstract java.lang.String getState()
Get the name of the state of this cell, or that this cell refers to. Returns a synthetic value for activate, wall or null cells.


getStateNumber

public abstract int getStateNumber(java.util.Map<java.lang.String,java.lang.Integer> states,
                                   java.lang.String stateFrom)
                            throws java.io.IOException
Get the integer number of this state within the states map when navigating to this cell from the numbered state.

Throws:
java.io.IOException - if there's an error in the grid construction

check

public abstract java.lang.String check()
Check that this cell is OK. This is called after the cell is completely initialized.

Returns:
null if OK, or an error message if not

getUpDown

public int getUpDown()
              throws java.io.IOException
Get the value for the upDown parameter of VisualRCHandler. This has the state to go to on up encoded in the first 16 bits, and the state to go to on down encoded in the last 16 bits.

Throws:
java.io.IOException - if there's an inconsistency in the handler

getRightLeft

public int getRightLeft()
                 throws java.io.IOException
Get the value for the rightLeft parameter of VisualRCHandler. This has the state to go to on right encoded in the first 16 bits, and the state to go to on left encoded in the last 16 bits. This can only be called on cells that map to a state.

Throws:
java.io.IOException - if there's an inconsistency in the handler

newState

public static VisualRCHandlerCell newState(java.lang.String state)
Create a cell that represents a new state. Only one cell that defines a state can be present in the handler's grid.


newStateRef

public static VisualRCHandlerCell newStateRef(java.lang.String state)
Create a cell that refers to a state that exists somewhere else in the grid. When this cell is navigated to, the position in the grid will shift to wherever the referred-to state is.


newLocationRef

public static VisualRCHandlerCell newLocationRef(int x,
                                                 int y)
Create a cell that refers to a state somewhere else in the grid, where that state is specified by an x,y position in the grid (countin from 0). When this cell is navigated to, the position in the grid will shift to wherever the referred-to state is.

Returns:
a new cell, or null if there's a problem (like a range error)

newActivate

public static VisualRCHandlerCell newActivate()
Create a cell that causes an activate. When this cell is navigated to, the state of the grid remains the same (and stays on whatever cell was previously active), but an activate of that cell is triggered. Thus, navigating to such a cell is equivalent to pressing the ENTER/OK button.


newWall

public static VisualRCHandlerCell newWall()
Create a cell that acts as a "wall". When you navigate to a wall cell using the arrow keys, you "bounce off", that is, you stay in whatever state you were in before.


newNull

public static VisualRCHandlerCell newNull()
Create a null cell. If you can navigate to a null cell, then it's an error, and compilation fails.