t3.hrd.state
Class StateManager

java.lang.Object
  extended by t3.hrd.state.StateManager

public class StateManager
extends java.lang.Object

A StateManager allows you to create, destroy and reorder Links, Tiles and Cursors.

Each Link, Tile and Cursor has an id. You can create them with specific ids, or allow the system to auto-generate ids for you. This class has methods to get a Link, Tile or Cursor object given its id, if it exists. You can reorder Links and Tiles by specifying the new ordering either by id or by the actual Link and Tile objects themselves.

Threading notes: this class is not thread-safe. You must use some kind of locking scheme if you use it in a multithreaded environment.

Author:
pjt40

Field Summary
 boolean backTiles
           
 java.util.Set<Cursor> cursorsReadOnly
           
static int MAX_CURSOR_ID
           
static int MAX_ORDEREDELEMENT_ID
           
 int maxDimensionForTileImages
           
 int splitDimensionForTileImages
           
protected  StateListener stateListener
           
 java.util.List<OrderedElement> tilesAndLinksInOrderReadOnly
           
 boolean usePowersOfTwoForTileImages
           
 
Constructor Summary
StateManager(StateListener stateListener, boolean usePowersOfTwo, boolean backTiles, int maxDimensionForTileImages, int splitDimensionForTileImages)
          Creates a StateManager.
 
Method Summary
protected  Cursor factoryreturnNewCursorObject(int id)
           
protected  Link factoryReturnNewLinkObject(StateListener tilesListener, int linkId, int displayType, java.awt.Color c, ScaRotTraTransformImmutable tStandardRectToDESKrectA, ScaRotTraTransformImmutable tStandardRectToDESKrectB)
           
protected  Tile factoryReturnNewTileObject(StateListener tilesListener, int tileId, int w, int h, int flags, boolean usePowersOfTwo)
           
 void fatalError(java.lang.Throwable e)
          Prints a stack trace and calls System.exit(1);
 Cursor getCursorByIdForOp(int id)
           
 Link getLinkByIdForOp(int id)
           
 Tile getTileByIdForOp(int id)
           
 OrderedElement getTileOrLinkByIdForOp(int id)
           
 Cursor opCreateCursor(int id)
          CURSORS
 Cursor opCreateCursorAutogenerateId()
           
 Link opCreateLink(int elId, int displayType, java.awt.Color c, ScaRotTraTransformImmutable tStandardRectToDESKrectA, ScaRotTraTransformImmutable tStandardRectToDESKrectB)
          Creates and returns a link with the specified parameters.
 Link opCreateLinkAutogenerateId(int displayType, java.awt.Color c, ScaRotTraTransformImmutable tStandardRectToDESKrectA, ScaRotTraTransformImmutable tStandardRectToDESKrectB)
           
 Tile opCreateTile(int elId, int w, int h, int flags)
          Creates a new Tile.
 Tile opCreateTileAutogenerateId(int w, int h, int flags)
           
 void opDestroyCursor(Cursor c)
           
 void opDestroyLink(Link l)
           
 void opDestroyTile(Tile t)
           
 void opLogMessage(java.lang.String message)
           
 void opReorderTilesAndLinks(java.util.List<OrderedElement> order)
          Reorder the tiles and links by specifying an array of OrderedElements.
 void opReorderTilesAndLinksById(int[] orderById)
          Reorder the tiles and links by specifying an array of elementIds.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_ORDEREDELEMENT_ID

public static final int MAX_ORDEREDELEMENT_ID
See Also:
Constant Field Values

MAX_CURSOR_ID

public static final int MAX_CURSOR_ID
See Also:
Constant Field Values

tilesAndLinksInOrderReadOnly

public java.util.List<OrderedElement> tilesAndLinksInOrderReadOnly

usePowersOfTwoForTileImages

public final boolean usePowersOfTwoForTileImages

backTiles

public final boolean backTiles

maxDimensionForTileImages

public final int maxDimensionForTileImages

splitDimensionForTileImages

public final int splitDimensionForTileImages

stateListener

protected final StateListener stateListener

cursorsReadOnly

public final java.util.Set<Cursor> cursorsReadOnly
Constructor Detail

StateManager

public StateManager(StateListener stateListener,
                    boolean usePowersOfTwo,
                    boolean backTiles,
                    int maxDimensionForTileImages,
                    int splitDimensionForTileImages)
Creates a StateManager.

Parameters:
stateListener - Callbacks that allow customisation/
usePowersOfTwo - Iff this is true then tile image dimensions will be changed to be powers of two.
backTiles - Iff this is true then tiles will be backed.
maxDimensionForTileImages - Maximum width or height of a tile before it will be split, or 0 for no splitting.
splitDimensionForTileImages - Width or height of component tiles into which tiles are split, or 0 for no splitting.
Method Detail

getTileOrLinkByIdForOp

public OrderedElement getTileOrLinkByIdForOp(int id)

getTileByIdForOp

public Tile getTileByIdForOp(int id)

getLinkByIdForOp

public Link getLinkByIdForOp(int id)

opLogMessage

public void opLogMessage(java.lang.String message)

opCreateTile

public Tile opCreateTile(int elId,
                         int w,
                         int h,
                         int flags)
Creates a new Tile. New Tiles are not visible.

Parameters:
elId -
w -
h -
flags -
Returns:

opCreateTileAutogenerateId

public Tile opCreateTileAutogenerateId(int w,
                                       int h,
                                       int flags)

opCreateLink

public Link opCreateLink(int elId,
                         int displayType,
                         java.awt.Color c,
                         ScaRotTraTransformImmutable tStandardRectToDESKrectA,
                         ScaRotTraTransformImmutable tStandardRectToDESKrectB)
Creates and returns a link with the specified parameters.

Parameters:
elId -
displayType -
c -
tStandardRectToDESKrectA -
tStandardRectToDESKrectB -
Returns:

opCreateLinkAutogenerateId

public Link opCreateLinkAutogenerateId(int displayType,
                                       java.awt.Color c,
                                       ScaRotTraTransformImmutable tStandardRectToDESKrectA,
                                       ScaRotTraTransformImmutable tStandardRectToDESKrectB)

opDestroyTile

public void opDestroyTile(Tile t)

opDestroyLink

public void opDestroyLink(Link l)

opReorderTilesAndLinksById

public void opReorderTilesAndLinksById(int[] orderById)
Reorder the tiles and links by specifying an array of elementIds. The first element of the array is the backmost element. You must not specify the elementIds of any tiles that were created as a result of the splitting process. Any that you do not specify will be added at the front.

Parameters:
orderById -

opReorderTilesAndLinks

public void opReorderTilesAndLinks(java.util.List<OrderedElement> order)
Reorder the tiles and links by specifying an array of OrderedElements. The first element of the array is the backmost element. You must not specify the elementIds of any tiles that were created as a result of the splitting process. Any that you do not specify will be added at the front.

Parameters:
order -

fatalError

public void fatalError(java.lang.Throwable e)
Prints a stack trace and calls System.exit(1);

Parameters:
e -

factoryReturnNewTileObject

protected Tile factoryReturnNewTileObject(StateListener tilesListener,
                                          int tileId,
                                          int w,
                                          int h,
                                          int flags,
                                          boolean usePowersOfTwo)

factoryReturnNewLinkObject

protected Link factoryReturnNewLinkObject(StateListener tilesListener,
                                          int linkId,
                                          int displayType,
                                          java.awt.Color c,
                                          ScaRotTraTransformImmutable tStandardRectToDESKrectA,
                                          ScaRotTraTransformImmutable tStandardRectToDESKrectB)

opCreateCursor

public Cursor opCreateCursor(int id)
CURSORS


opCreateCursorAutogenerateId

public Cursor opCreateCursorAutogenerateId()

opDestroyCursor

public void opDestroyCursor(Cursor c)

getCursorByIdForOp

public Cursor getCursorByIdForOp(int id)

factoryreturnNewCursorObject

protected Cursor factoryreturnNewCursorObject(int id)