bluegammon.gui
Class MenuCanvas

java.lang.Object
  extended byjavax.microedition.lcdui.Displayable
      extended byjavax.microedition.lcdui.Canvas
          extended bybluegammon.gui.PopupCanvas
              extended bybluegammon.gui.MenuCanvas
All Implemented Interfaces:
javax.microedition.lcdui.CommandListener, ItemAction, MenuListener

public class MenuCanvas
extends PopupCanvas
implements MenuListener, ItemAction, javax.microedition.lcdui.CommandListener

The MenuCanvas is the handler of the Bluegammon menu. There is only one menu per game, thus the singleton pattern.

Author:
Peter Andersson
See Also:
Menu

Field Summary
 
Fields inherited from class javax.microedition.lcdui.Canvas
DOWN, FIRE, GAME_A, GAME_B, GAME_C, GAME_D, KEY_NUM0, KEY_NUM1, KEY_NUM2, KEY_NUM3, KEY_NUM4, KEY_NUM5, KEY_NUM6, KEY_NUM7, KEY_NUM8, KEY_NUM9, KEY_POUND, KEY_STAR, LEFT, RIGHT, UP
 
Method Summary
 void actionCalled(MenuPage page, PageItem item, ItemAction action)
          Called when an ItemAction is invoked.
 void commandAction(javax.microedition.lcdui.Command c, javax.microedition.lcdui.Displayable d)
           
static MenuCanvas getInstance()
          Returns the singleton instance.
 void initShow()
          Initializes the states of items and starts the muzak, called on an already initialized menu when it is focused again.
 void itemAction(MenuPage page, PageItem item)
          ItemAction implementation, called from items in this menu.
 void itemSelected(MenuPage page, PageItem oldItem, PageItem newItem)
          Called when a item is selected in a page.
 void newPage(MenuPage fromPage, MenuPage toPage, boolean back)
          Called when a new page is shown.
 void transitionStarted(MenuPage fromPage, MenuPage toPage, long delay, int frames, boolean back)
          Called when a transition is started on a new page selection.
 void transitionStopped(MenuPage fromPage, MenuPage toPage)
          Called when a transition is finished.
 
Methods inherited from class bluegammon.gui.PopupCanvas
getPopup, setPopup
 
Methods inherited from class javax.microedition.lcdui.Canvas
getGameAction, getKeyCode, getKeyName, hasPointerEvents, hasPointerMotionEvents, hasRepeatEvents, isDoubleBuffered, repaint, repaint, serviceRepaints, setFullScreenMode
 
Methods inherited from class javax.microedition.lcdui.Displayable
addCommand, getHeight, getTicker, getTitle, getWidth, isShown, removeCommand, setCommandListener, setTicker, setTitle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static MenuCanvas getInstance()
Returns the singleton instance.

Returns:
The singleton instance.

initShow

public void initShow()
Initializes the states of items and starts the muzak, called on an already initialized menu when it is focused again.


commandAction

public void commandAction(javax.microedition.lcdui.Command c,
                          javax.microedition.lcdui.Displayable d)
Specified by:
commandAction in interface javax.microedition.lcdui.CommandListener

itemAction

public void itemAction(MenuPage page,
                       PageItem item)
ItemAction implementation, called from items in this menu. Instead of creating one class per action, we centralize the action behaviour here. Each action is identified by its id.

Specified by:
itemAction in interface ItemAction
Parameters:
page - The page from which the action was called
item - The item to which the action belongs

newPage

public void newPage(MenuPage fromPage,
                    MenuPage toPage,
                    boolean back)
Description copied from interface: MenuListener
Called when a new page is shown.

Specified by:
newPage in interface MenuListener
Parameters:
fromPage - Old page or null.
toPage - New page.
back - true if user steps back, false if active choice forwards.

itemSelected

public void itemSelected(MenuPage page,
                         PageItem oldItem,
                         PageItem newItem)
Description copied from interface: MenuListener
Called when a item is selected in a page.

Specified by:
itemSelected in interface MenuListener
Parameters:
page - The page in which the item is selected.
oldItem - The item that is deselected or null if no such item.
newItem - The item that is selected.

actionCalled

public void actionCalled(MenuPage page,
                         PageItem item,
                         ItemAction action)
Description copied from interface: MenuListener
Called when an ItemAction is invoked.

Specified by:
actionCalled in interface MenuListener
Parameters:
page - The page in which the action was invoked.
item - The item the action belongs to.
action - The action.

transitionStarted

public void transitionStarted(MenuPage fromPage,
                              MenuPage toPage,
                              long delay,
                              int frames,
                              boolean back)
Description copied from interface: MenuListener
Called when a transition is started on a new page selection.

Specified by:
transitionStarted in interface MenuListener
Parameters:
fromPage - Old page or null.
toPage - New page.
delay - Delay between each transition frame in milliseconds.
frames - Number of frames in this transition.
back - True if this is transition back to a previous page.

transitionStopped

public void transitionStopped(MenuPage fromPage,
                              MenuPage toPage)
Description copied from interface: MenuListener
Called when a transition is finished.

Specified by:
transitionStopped in interface MenuListener
Parameters:
fromPage - Old page or null.
toPage - New page.