ch.aplu.jgamegrid
Class ToolBar

java.lang.Object
  extended by ch.aplu.jgamegrid.ToolBar

public class ToolBar
extends java.lang.Object

Class to represent a linear bar of item. The items are standard JGameGrid actors. A tool bar is used to show or modify the state of a game (e.g. to select/show the trump suit). Mouse touch events are reported by a registered tool bar listener. The actors may have several sprite image that may be changed by calling Actor.show(spriteId). Because in JGameGrid the paint order is determined per class (when the first actor of a class is s added to the game grid), the tool bar items are shown on top of card actors if the tool bar is shown first. The paint order may be changed by calling setOnTop() or setOnBottom resp.


Constructor Summary
ToolBar(GameGrid gameGrid)
           
 
Method Summary
 void addItem(ToolBarItem... item)
          Add the next item(s) into the tool bar in the order they are passed.
 void addToolBarListener(ToolBarListener listener)
          Registers a tool bar listener to get event notifications when an item is touched.
 ToolBarItem getItem(int itemIndex)
          Returns the tool bar item actor at the specified index of the item list.
 void removeAllItems()
          Removes all currently displayed items from the card game window and empties the item list.
 void setAllSpriteIds(int spriteId)
          Sets the sprite id of all items to given value.
 void setLocation(Location barLocation)
          Moves the current tool bar at the specified location.
 void setOnBottom(java.lang.Class clazz)
          Puts the given class prior to the ToolBarItem class in the paint order, so that actors from the given class are painted on top of tool bar item images.
 void setOnTop(java.lang.Class clazz)
          Puts the ToolBarItem class prior to the given class in the paint order, so that the tool bar item images are painted on top of actors from the given class.
 void setSpriteId(int itemIndex, int spriteId)
          Sets the sprite id of the item at given index to given value.
 void show(Location barLocation)
          Adds the tool bar item actors to the card game window at the given location (upper left corner of first item).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ToolBar

public ToolBar(GameGrid gameGrid)
Method Detail

show

public void show(Location barLocation)
Adds the tool bar item actors to the card game window at the given location (upper left corner of first item). The item actors are drawn on top of all other cardActors already visible in the card game window. If the tool bar has already been displayed before, just sets the tool bar with current attributes to new location. If the tool bar is empty, nothing happens.

To hide a toolbar instead of hiding all tool bar items, just move it outside the visible game grid.

Parameters:
barLocation - the location of the upper left corner of the first item

removeAllItems

public void removeAllItems()
Removes all currently displayed items from the card game window and empties the item list.


addItem

public void addItem(ToolBarItem... item)
Add the next item(s) into the tool bar in the order they are passed. The items will be displayed in the order the are added. All items should have the same height. To actualize a currently displayed tool bar, show() must be called.

Parameters:
item - the item(s) or array of items to be added

setSpriteId

public void setSpriteId(int itemIndex,
                        int spriteId)
Sets the sprite id of the item at given index to given value. For spriteId = -1, the sprite image is hidden.

Parameters:
itemIndex - the index of the item in the item list (in the range 0..nbItems-1, nothing happens if outside)
spriteId - the new sprite id of the item actor

setAllSpriteIds

public void setAllSpriteIds(int spriteId)
Sets the sprite id of all items to given value. For spriteId = -1, the sprite image is hidden.

Parameters:
spriteId - the new sprite id of all item actors

getItem

public ToolBarItem getItem(int itemIndex)
Returns the tool bar item actor at the specified index of the item list.

Parameters:
itemIndex - the index of the item in the item list (in the range 0..nbItems-1)
Returns:
the item at the specified itemIndex; null, if index outside range

setOnTop

public void setOnTop(java.lang.Class clazz)
Puts the ToolBarItem class prior to the given class in the paint order, so that the tool bar item images are painted on top of actors from the given class. Only valid, if the tool bar has been drawn.


setOnBottom

public void setOnBottom(java.lang.Class clazz)
Puts the given class prior to the ToolBarItem class in the paint order, so that actors from the given class are painted on top of tool bar item images.


setLocation

public void setLocation(Location barLocation)
Moves the current tool bar at the specified location. All current attributes are maintained. If the tool bar is empty, nothing happens.

Parameters:
barLocation - the new location of the tool bar

addToolBarListener

public void addToolBarListener(ToolBarListener listener)
Registers a tool bar listener to get event notifications when an item is touched.

Parameters:
listener - the ToolBarListener to register